commit ce73485bc3002a844f7d2a6dcfb2cd39c132eb1a Author: Taywon Date: Mon Jan 15 20:33:13 2024 +0000 initial release (don't judge me pls) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5f19d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2568c0c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "2" +services: + node: + image: "node:16" + user: "node" + restart: unless-stopped + working_dir: /home/node/app + environment: + - NODE_ENV=production + volumes: + - ./:/home/node/app + - /media/hddmain/security:/snapshot + ports: + - 7256:80 + command: "npm start" \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..a155dc2 --- /dev/null +++ b/index.js @@ -0,0 +1,49 @@ +const express = require('express'); +const app = express(); +const port = 80; + +const http = require("http"); +const fs = require('fs'); + +const SNAPSHOT_URL = "http://192.168.1.68/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=admin&password=WX12cv06," + +function snapshotPath(){ + let date = new Date(); + + return "/snapshot/snapshot-" + + date.getFullYear() + + date.getMonth() + + date.getDay() + + "-" + + date.getHours() + + date.getMinutes() + + date.getSeconds() + + "-" + + date.getMilliseconds() + +".jpg"; +} + + +function snapshot() { + http.get(SNAPSHOT_URL, (res) => { + res.pipe(fs.createWriteStream(snapshotPath())); + }); +} + +app.get('/snapshot', (req, res) => { + try{ + snapshot(); + res.send('ok'); + } catch(e) + { + res.status(500).send(e); + } + }); + +app.get('/', (req, res) => { + res.send('Hello World!'); +}); + +app.listen(port, () => { + console.log(`Example app listening at http://localhost:${port}`); +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..323c133 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "relay", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "npm install && node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "dateformat": "^5.0.3", + "express": "^4.18.2" + } +}