mirror of
https://github.com/iv-org/instances-api.git
synced 2025-06-30 09:17:18 -04:00
Merge 67a99e2c3b
into 5301e08bd3
This commit is contained in:
commit
ad63a3e388
5 changed files with 46 additions and 2 deletions
|
@ -6,11 +6,12 @@ COPY ./src/ ./src/
|
||||||
RUN crystal build ./src/instances.cr --release
|
RUN crystal build ./src/instances.cr --release
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
RUN apk add --no-cache gc pcre libgcc
|
RUN apk add --no-cache gc pcre libgcc yaml
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN addgroup -g 1000 -S invidious && \
|
RUN addgroup -g 1000 -S invidious && \
|
||||||
adduser -u 1000 -S invidious -G invidious
|
adduser -u 1000 -S invidious -G invidious
|
||||||
COPY ./assets/ ./assets/
|
COPY ./assets/ ./assets/
|
||||||
|
COPY ./config.yml ./config.yml
|
||||||
COPY --from=builder /app/instances .
|
COPY --from=builder /app/instances .
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
9
config.yml
Normal file
9
config.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Uses the system's CURL binary to do so.
|
||||||
|
fetch_onion_instance_stats: true
|
||||||
|
|
||||||
|
# TOR's Sock proxy address that CURL uses to connect to hidden services
|
||||||
|
tor_sock_proxy_address: "127.0.0.1"
|
||||||
|
tor_sock_proxy_port: 9050
|
||||||
|
|
||||||
|
# Minutes before refreshing the instance stats
|
||||||
|
minutes_between_refresh: 30
|
|
@ -1,5 +1,13 @@
|
||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
|
tor-socks-proxy:
|
||||||
|
container_name: tor-socks-proxy
|
||||||
|
image: peterdavehello/tor-socks-proxy:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8853:53/udp"
|
||||||
|
- "127.0.0.1:9150:9150/tcp"
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
instances:
|
instances:
|
||||||
build: .
|
build: .
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
6
src/helpers/helpers.cr
Normal file
6
src/helpers/helpers.cr
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
require "yaml"
|
||||||
|
|
||||||
|
def load_config
|
||||||
|
config = YAML.parse(File.read("config.yml"))
|
||||||
|
return config
|
||||||
|
end
|
|
@ -18,6 +18,10 @@ require "http/client"
|
||||||
require "kemal"
|
require "kemal"
|
||||||
require "uri"
|
require "uri"
|
||||||
|
|
||||||
|
require "./helpers/*"
|
||||||
|
|
||||||
|
CONFIG = load_config()
|
||||||
|
|
||||||
Kemal::CLI.new ARGV
|
Kemal::CLI.new ARGV
|
||||||
|
|
||||||
macro rendered(filename)
|
macro rendered(filename)
|
||||||
|
@ -68,6 +72,22 @@ spawn do
|
||||||
|
|
||||||
case type = host.split(".")[-1]
|
case type = host.split(".")[-1]
|
||||||
when "onion"
|
when "onion"
|
||||||
|
type = "onion"
|
||||||
|
|
||||||
|
if CONFIG["fetch_onion_instance_stats"]?
|
||||||
|
begin
|
||||||
|
args = Process.parse_arguments("--socks5-hostname '#{CONFIG["tor_sock_proxy_address"]}:#{CONFIG["tor_sock_proxy_port"]}' 'http://#{uri.host}/api/v1/stats'")
|
||||||
|
response = nil
|
||||||
|
Process.run("curl", args: args) do |result|
|
||||||
|
data = result.output.read_line
|
||||||
|
response = JSON.parse(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
stats = response
|
||||||
|
rescue ex
|
||||||
|
stats = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
when "i2p"
|
when "i2p"
|
||||||
else
|
else
|
||||||
type = uri.scheme.not_nil!
|
type = uri.scheme.not_nil!
|
||||||
|
@ -105,7 +125,7 @@ spawn do
|
||||||
INSTANCES.clear
|
INSTANCES.clear
|
||||||
INSTANCES.merge! instances
|
INSTANCES.merge! instances
|
||||||
|
|
||||||
sleep 5.minutes
|
sleep CONFIG["minutes_between_refresh"].as_i.minutes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue