initial release (don't judge me pls)
This commit is contained in:
commit
ce73485bc3
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal 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
49
index.js
Normal 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
16
package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user