Skip to content

Commit

Permalink
Clean up APIv1
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlgo11 committed Nov 5, 2023
1 parent 5d94027 commit effaf48
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scripts/APIv1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def public_api
path = 'public/api/v1'

Dir.glob(@entries) { |file| all[File.basename(file, '.*')] = JSON.parse(File.read(file)).values[0] }
all.sort.to_h.each do |_, v|
v['additional-domains']&.each do |domain|
all[domain] = v.reject { |key| key == 'additional-domains' }
all.sort.to_h.each do |_, entry|
entry['additional-domains']&.each do |domain|
all[domain] = entry.reject { |key| key == 'additional-domains' }
end
v.delete('additional-domains')
v.delete('img')
entry.delete('additional-domains')
entry.delete('img')
end

all.to_h.each do |k, v|
Expand Down Expand Up @@ -48,15 +48,16 @@ def private_api

Dir.glob(@entries) { |file| all[JSON.parse(File.read(file)).keys[0]] = JSON.parse(File.read(file)).values[0] }

all.sort.to_h.each do |_, v|
v['regions']&.each do |region|
all.sort.to_h.each do |_, entry|
entry['regions']&.each do |region|
next if region[0] == '-'

regions[region] = {} unless regions.key? region
regions[region]['count'] = 1 + regions[region]['count'].to_i
end
v['passkeys'] = Array(v['passkeys']) if v.key?('passkeys')
v['categories'] = Array(v['categories']) if v.key?('categories')
entry['passkeys'] = Array(entry['passkeys']) if entry.key?('passkeys')
entry['categories'] = Array(entry['categories']) if entry.key?('categories')
entry.delete 'additional-domains'
end

regions['int'] = { 'count' => all.length, 'selection' => true }
Expand Down

0 comments on commit effaf48

Please sign in to comment.