mirror of
https://github.com/iv-org/instances-api.git
synced 2025-03-13 09:46:34 -04:00
Unnest country data from instance API
This commit is contained in:
parent
93425fe8a3
commit
ca8a99c9d1
10
src/fetch.cr
10
src/fetch.cr
@ -3,7 +3,7 @@ def fetch_country(md)
|
||||
flag = md["flag"]?
|
||||
country_name = md["country_name"]?
|
||||
|
||||
return {flag: flag, region: region, name: country_name}
|
||||
return flag, region, country_name
|
||||
end
|
||||
|
||||
def fetch_notes(md)
|
||||
@ -19,7 +19,7 @@ def prepare_http_instance(md, instances, monitors)
|
||||
uri = URI.parse(md["uri"])
|
||||
host = md["host"]
|
||||
|
||||
country = fetch_country(md)
|
||||
flag, region, country_name = fetch_country(md)
|
||||
|
||||
status_url = md["status_url"]?
|
||||
|
||||
@ -44,7 +44,7 @@ def prepare_http_instance(md, instances, monitors)
|
||||
end
|
||||
|
||||
monitor = monitors.try &.select { |monitor| monitor["name"].try &.as_s == host }[0]?
|
||||
return {country: country, stats: stats, type: "https", uri: uri.to_s, status_url: status_url,
|
||||
return {flag: flag, region: region, country_name: country_name, stats: stats, type: "https", uri: uri.to_s, status_url: status_url,
|
||||
privacy_policy: privacy_policy, ddos_protection: ddos_protection,
|
||||
owner: owner, notes: notes, monitor: monitor || instances[host]?.try &.[:monitor]?}
|
||||
end
|
||||
@ -54,7 +54,7 @@ def prepare_onion_instance(md, instances)
|
||||
host = md["host"]
|
||||
|
||||
clearnet_url = md["clearnet_url"]
|
||||
country = fetch_country(md)
|
||||
flag, region, country_name = fetch_country(md)
|
||||
privacy_policy = md["privacy_policy"]?
|
||||
owner = {name: md["owner"].strip("@"), url: md["owner_url"]}
|
||||
notes = fetch_notes(md)
|
||||
@ -76,7 +76,7 @@ def prepare_onion_instance(md, instances)
|
||||
stats = nil
|
||||
end
|
||||
|
||||
return {country: country, stats: stats, type: "onion", uri: uri.to_s, clearnet_url: clearnet_url,
|
||||
return {flag: flag, region: region, country_name: country_name, stats: stats, type: "onion", uri: uri.to_s, clearnet_url: clearnet_url,
|
||||
privacy_policy: privacy_policy, owner: owner, notes: notes,
|
||||
monitor: nil}
|
||||
end
|
||||
|
@ -30,9 +30,8 @@ macro rendered(filename)
|
||||
end
|
||||
|
||||
alias Owner = NamedTuple(name: String, url: String)
|
||||
alias Country = NamedTuple(flag: String?, region: String?, name: String?)
|
||||
alias ClearNetInstance = NamedTuple(country: Country, stats: JSON::Any?, type: String, uri: String, status_url: String?, privacy_policy: String?, ddos_protection: String?, owner: Owner, notes: String?, monitor: JSON::Any?)
|
||||
alias OnionInstance = NamedTuple(country: Country, stats: JSON::Any?, type: String, uri: String, clearnet_url: String?, privacy_policy: String?, owner: Owner, notes: String?, monitor: JSON::Any?)
|
||||
alias ClearNetInstance = NamedTuple(flag: String?, region: String?, country_name: String?, stats: JSON::Any?, type: String, uri: String, status_url: String?, privacy_policy: String?, ddos_protection: String?, owner: Owner, notes: String?, monitor: JSON::Any?)
|
||||
alias OnionInstance = NamedTuple(flag: String?, region: String?, country_name: String?, stats: JSON::Any?, type: String, uri: String, clearnet_url: String?, privacy_policy: String?, owner: Owner, notes: String?, monitor: JSON::Any?)
|
||||
|
||||
INSTANCES = {} of String => ClearNetInstance | OnionInstance
|
||||
|
||||
@ -119,7 +118,7 @@ end
|
||||
|
||||
SORT_PROCS = {
|
||||
"health" => ->(name : String, instance : ClearNetInstance | OnionInstance) { -(instance[:monitor]?.try &.["30dRatio"]["ratio"].as_s.to_f || 0.0) },
|
||||
"location" => ->(name : String, instance : ClearNetInstance | OnionInstance) { instance[:country][:region]? || "ZZ" },
|
||||
"location" => ->(name : String, instance : ClearNetInstance | OnionInstance) { instance[:region]? || "ZZ" },
|
||||
"name" => ->(name : String, instance : ClearNetInstance | OnionInstance) { name },
|
||||
"signup" => ->(name : String, instance : ClearNetInstance | OnionInstance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
|
||||
"type" => ->(name : String, instance : ClearNetInstance | OnionInstance) { instance[:type] },
|
||||
|
@ -118,7 +118,7 @@
|
||||
<td><%= instance[:type] %></td>
|
||||
<td><%= instance[:stats]?.try &.["usage"]?.try &.["users"]["total"] || "-" %></td>
|
||||
<td><%= instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? "✔" : "❌" } || "-" %></td>
|
||||
<td><%= instance[:country]? ? "#{instance[:country][:flag]} #{instance[:country][:name]}" : "-" %></td>
|
||||
<td><%= instance[:flag]? ? "#{instance[:flag]} #{instance[:region]}" : "-" %></td>
|
||||
<td><%= instance[:monitor]?.try &.["30dRatio"]["ratio"] || "-" %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user