Changed CORS from string to boolean

This commit is contained in:
xRealNeon 2022-01-11 14:00:46 +01:00
parent 7e743abee0
commit 8e56425c3b
2 changed files with 7 additions and 4 deletions

View File

@ -24,7 +24,7 @@ macro rendered(filename)
render "src/instances/views/#{{{filename}}}.ecr"
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
@ -77,14 +77,17 @@ spawn do
begin
req = client.get("/api/v1/stats")
stats = JSON.parse(req.body)
cors = req.headers["Access-Control-Allow-Origin"]
api = false
cors = false
req = client.get("/api/v1/trending")
if req.status_code == 200
begin
JSON.parse(req.body)
api = true
if req.headers["Access-Control-Allow-Origin"] == "*"
cors = true
end
rescue
puts "Cant parse API json"
end
@ -153,7 +156,7 @@ SORT_PROCS = {
"name" => ->(name : String, instance : Instance) { name },
"signup" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
"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 },
"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] },

View File

@ -119,7 +119,7 @@
<td><%= instance[:stats]?.try &.["software"]?.try &.["version"] || "-" %></td>
<td><%= instance[:type] %></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[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? "✔" : "❌" } || "-" %></td>
<td><%= instance[:flag]? ? "#{instance[:flag]} #{instance[:region]}" : "-" %></td>