Skip to content

Commit

Permalink
Updown debut implementation - currently broken
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFrenchGhosty committed Apr 2, 2024
1 parent 5301e08 commit 338f07a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM docker.io/crystallang/crystal:1.0.0-alpine AS builder
FROM docker.io/crystallang/crystal:1.8.0-alpine AS builder
WORKDIR /app
COPY ./shard.yml ./shard.yml
RUN shards install
COPY ./src/ ./src/
RUN crystal build ./src/instances.cr --release

FROM alpine:latest
RUN apk add --no-cache gc pcre libgcc
RUN apk add --no-cache gc pcre libgcc pcre2
WORKDIR /app
RUN addgroup -g 1000 -S invidious && \
adduser -u 1000 -S invidious -G invidious
Expand Down
30 changes: 15 additions & 15 deletions src/instances.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ INSTANCES = {} of String => Instance
spawn do
loop do
monitors = [] of JSON::Any
page = 1
#page = 1
loop do
begin
client = HTTP::Client.new(URI.parse("https://stats.uptimerobot.com/89VnzSKAn"))
client = HTTP::Client.new(URI.parse("https://updown.io/p/wqufo"))
client.connect_timeout = 10.seconds
client.read_timeout = 10.seconds
response = JSON.parse(client.get("/api/getMonitorList/89VnzSKAn?page=#{page}").body)
response = JSON.parse(client.get("/api/checks?api-key=ro-52iHyp6LBqQq7rGp4N7p").body)

monitors += response["psp"]["monitors"].as_a
page += 1
# monitors += response["psp"]["monitors"].as_a
# page += 1

break if response["psp"]["perPage"].as_i * (page - 1) + 1 > response["psp"]["totalMonitors"].as_i
# break if response["psp"]["perPage"].as_i * (page - 1) + 1 > response["psp"]["totalMonitors"].as_i
rescue ex
error_message = response.try &.as?(String).try &.["errorStats"]?
error_message ||= ex.message
Expand Down Expand Up @@ -98,7 +98,7 @@ spawn do
end
end

monitor = monitors.try &.select { |monitor| monitor["name"].try &.as_s == host }[0]?
monitor = monitors.try &.select { |monitor| monitor["alias"].try &.as_s == host }[0]?
instances[host] = {flag: flag, region: region, stats: stats, cors: cors, api: api, type: type, uri: uri.to_s, monitor: monitor || instances[host]?.try &.[:monitor]?}
end

Expand Down Expand Up @@ -151,15 +151,15 @@ static_headers do |response, filepath, filestat|
end

SORT_PROCS = {
"health" => ->(name : String, instance : Instance) { -(instance[:monitor]?.try &.["30dRatio"]["ratio"].as_s.to_f || 0.0) },
"location" => ->(name : String, instance : Instance) { instance[:region]? || "ZZ" },
"health" => ->(alias : String, instance : Instance) { -(instance[:monitor]?.try &.["30dRatio"]["ratio"].as_s.to_f || 0.0) },
"location" => ->(alias : String, instance : Instance) { instance[:region]? || "ZZ" },
"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] == 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] },
"signup" => ->(alias : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
"type" => ->(alias : String, instance : Instance) { instance[:type] },
"cors" => ->(alias : String, instance : Instance) { instance[:cors] == nil ? 2 : instance[:cors] ? 0 : 1 },
"api" => ->(alias : String, instance : Instance) { instance[:api] == nil ? 2 : instance[:api] ? 0 : 1 },
"users" => ->(alias : String, instance : Instance) { -(instance[:stats]?.try &.["usage"]?.try &.["users"]["total"].as_i || 0) },
"version" => ->(alias : String, instance : Instance) { instance[:stats]?.try &.["software"]?.try &.["version"].as_s.try &.split("-", 2)[0].split(".").map { |a| -a.to_i } || [0, 0, 0] },
}

def sort_instances(instances, sort_by)
Expand Down

0 comments on commit 338f07a

Please sign in to comment.