initial release (don't judge me pls)

This commit is contained in:
Taywon 2024-01-15 20:33:13 +00:00
commit ce73485bc3
4 changed files with 82 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
package-lock.json

15
docker-compose.yml Normal file
View File

@ -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"

49
index.js Normal file
View File

@ -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}`);
});

16
package.json Normal file
View File

@ -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"
}
}