aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--174bg/database/README.md3
-rw-r--r--174bg/database/deploy.ps13
-rw-r--r--174bg/database/docker-compose.yaml25
-rw-r--r--174bg/database/volumes/pocketbase/pb_hooks/main.pb.js29
4 files changed, 60 insertions, 0 deletions
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