From f0207bab0218ba3222b277a908dbf42303f5b09c Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Fri, 24 Jul 2026 17:40:27 +0100 Subject: add database stuff to repo --- 174bg/database/README.md | 3 +++ 174bg/database/deploy.ps1 | 3 +++ 174bg/database/docker-compose.yaml | 25 +++++++++++++++++++ .../volumes/pocketbase/pb_hooks/main.pb.js | 29 ++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 174bg/database/README.md create mode 100644 174bg/database/deploy.ps1 create mode 100644 174bg/database/docker-compose.yaml create mode 100644 174bg/database/volumes/pocketbase/pb_hooks/main.pb.js (limited to '174bg/database') diff --git a/174bg/database/README.md b/174bg/database/README.md new file mode 100644 index 0000000..dff7245 --- /dev/null +++ b/174bg/database/README.md @@ -0,0 +1,3 @@ +# [db.174bg.net](https://db.174bg.net) + +The [pocketbase](https://pocketbase.io/) database for 174bg.net. \ No newline at end of file diff --git a/174bg/database/deploy.ps1 b/174bg/database/deploy.ps1 new file mode 100644 index 0000000..7265083 --- /dev/null +++ b/174bg/database/deploy.ps1 @@ -0,0 +1,3 @@ +$ROOT = "/docker-compose/db.174bg.net/"; + +scp ".\volumes\pocketbase\pb_hooks\main.pb.js" "root@docker-compose:$ROOT/volumes/pocketbase/pb_hooks/main.pb.js" \ No newline at end of file diff --git a/174bg/database/docker-compose.yaml b/174bg/database/docker-compose.yaml new file mode 100644 index 0000000..89b7dec --- /dev/null +++ b/174bg/database/docker-compose.yaml @@ -0,0 +1,25 @@ +services: + pocketbase: + build: + context: . + dockerfile_inline: | + FROM alpine:3.22 + + ARG PB_VERSION=0.39.9 + + RUN apk add --no-cache \ + unzip \ + ca-certificates + + ADD https://github.com/pocketbase/pocketbase/releases/download/v$${PB_VERSION}/pocketbase_$${PB_VERSION}_linux_amd64.zip /tmp/pb.zip + RUN unzip /tmp/pb.zip -d /pb/ + + EXPOSE 8080 + + CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8080"] + ports: + - "50499:8080" + restart: unless-stopped + volumes: + - ./volumes/pocketbase/pb_data:/pb/pb_data + - ./volumes/pocketbase/pb_hooks:/pb/pb_hooks \ No newline at end of file diff --git a/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js b/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js new file mode 100644 index 0000000..b7d385d --- /dev/null +++ b/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js @@ -0,0 +1,29 @@ +routerAdd("GET", "/heartbeat", (e) => { + try { + const result = new DynamicModel({ + "value": nullString(), + }) + + let dateNow = Date.now(); + + try { + $app.db() + .newQuery(`SELECT value FROM key_value_store WHERE key = "heartbeat"`) + .one(result); + } catch (error) { + return e.json(404, { "error": "Heartbeat not found" }); + } + + let heartbeatValue = parseInt(result.value); + let timeDifference = dateNow - heartbeatValue; + let withinThreshold = timeDifference <= 60000; // 60 seconds threshold + + return e.json(200, { "timeDifference": timeDifference, "withinThreshold": withinThreshold }); + } catch (error) { + return e.json(500, { "error": "Internal Server Error", "details": error.message }); + } +}); + +cronAdd("heartbeat", "* * * * *", () => { + $app.db().newQuery(`UPDATE key_value_store SET value = ${Date.now()} WHERE key = "heartbeat"`).execute() +}) \ No newline at end of file -- cgit v1.2.3