mirror of
https://github.com/iv-org/instances-api.git
synced 2025-05-10 02:25:41 -04:00
Changed CORS from string to boolean
This commit is contained in:
parent
7e743abee0
commit
8e56425c3b
2 changed files with 7 additions and 4 deletions
|
@ -24,7 +24,7 @@ macro rendered(filename)
|
||||||
render "src/instances/views/#{{{filename}}}.ecr"
|
render "src/instances/views/#{{{filename}}}.ecr"
|
||||||
end
|
end
|
||||||
|
|
||||||
alias Instance = NamedTuple(flag: String?, region: String?, stats: JSON::Any?, cors: String?, api: Bool?, type: String, uri: String, monitor: JSON::Any?)
|
alias Instance = NamedTuple(flag: String?, region: String?, stats: JSON::Any?, cors: Bool?, api: Bool?, type: String, uri: String, monitor: JSON::Any?)
|
||||||
|
|
||||||
INSTANCES = {} of String => Instance
|
INSTANCES = {} of String => Instance
|
||||||
|
|
||||||
|
@ -77,14 +77,17 @@ spawn do
|
||||||
begin
|
begin
|
||||||
req = client.get("/api/v1/stats")
|
req = client.get("/api/v1/stats")
|
||||||
stats = JSON.parse(req.body)
|
stats = JSON.parse(req.body)
|
||||||
cors = req.headers["Access-Control-Allow-Origin"]
|
|
||||||
|
|
||||||
api = false
|
api = false
|
||||||
|
cors = false
|
||||||
req = client.get("/api/v1/trending")
|
req = client.get("/api/v1/trending")
|
||||||
if req.status_code == 200
|
if req.status_code == 200
|
||||||
begin
|
begin
|
||||||
JSON.parse(req.body)
|
JSON.parse(req.body)
|
||||||
api = true
|
api = true
|
||||||
|
if req.headers["Access-Control-Allow-Origin"] == "*"
|
||||||
|
cors = true
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
puts "Cant parse API json"
|
puts "Cant parse API json"
|
||||||
end
|
end
|
||||||
|
@ -153,7 +156,7 @@ SORT_PROCS = {
|
||||||
"name" => ->(name : String, instance : Instance) { name },
|
"name" => ->(name : String, instance : Instance) { name },
|
||||||
"signup" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
|
"signup" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
|
||||||
"type" => ->(name : String, instance : Instance) { instance[:type] },
|
"type" => ->(name : String, instance : Instance) { instance[:type] },
|
||||||
"cors" => ->(name : String, instance : Instance) { instance[:cors]? || "-" },
|
"cors" => ->(name : String, instance : Instance) { instance[:cors] == nil ? 2 : instance[:cors] ? 0 : 1 },
|
||||||
"api" => ->(name : String, instance : Instance) { instance[:api] == nil ? 2 : instance[:api] ? 0 : 1 },
|
"api" => ->(name : String, instance : Instance) { instance[:api] == nil ? 2 : instance[:api] ? 0 : 1 },
|
||||||
"users" => ->(name : String, instance : Instance) { -(instance[:stats]?.try &.["usage"]?.try &.["users"]["total"].as_i || 0) },
|
"users" => ->(name : String, instance : Instance) { -(instance[:stats]?.try &.["usage"]?.try &.["users"]["total"].as_i || 0) },
|
||||||
"version" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["software"]?.try &.["version"].as_s.try &.split("-", 2)[0].split(".").map { |a| -a.to_i } || [0, 0, 0] },
|
"version" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["software"]?.try &.["version"].as_s.try &.split("-", 2)[0].split(".").map { |a| -a.to_i } || [0, 0, 0] },
|
||||||
|
|
|
@ -119,7 +119,7 @@
|
||||||
<td><%= instance[:stats]?.try &.["software"]?.try &.["version"] || "-" %></td>
|
<td><%= instance[:stats]?.try &.["software"]?.try &.["version"] || "-" %></td>
|
||||||
<td><%= instance[:type] %></td>
|
<td><%= instance[:type] %></td>
|
||||||
<td><%= instance[:stats]?.try &.["usage"]?.try &.["users"]["total"] || "-" %></td>
|
<td><%= instance[:stats]?.try &.["usage"]?.try &.["users"]["total"] || "-" %></td>
|
||||||
<td><%= instance[:cors] || "-" %></td>
|
<td><%= instance[:cors] == nil ? "-" : instance[:cors] ? "✔" : "❌" %></td>
|
||||||
<td><%= instance[:api] == nil ? "-" : instance[:api] ? "✔" : "❌" %></td>
|
<td><%= instance[:api] == nil ? "-" : instance[:api] ? "✔" : "❌" %></td>
|
||||||
<td><%= instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? "✔" : "❌" } || "-" %></td>
|
<td><%= instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? "✔" : "❌" } || "-" %></td>
|
||||||
<td><%= instance[:flag]? ? "#{instance[:flag]} #{instance[:region]}" : "-" %></td>
|
<td><%= instance[:flag]? ? "#{instance[:flag]} #{instance[:region]}" : "-" %></td>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue