70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
const express = require('express');
|
|
const app = express();
|
|
const port = 80;
|
|
|
|
const http = require("http");
|
|
const fs = require('fs');
|
|
|
|
const SNAPSHOT_SALON_URL = "http://192.168.1.68/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=admin&password=WX12cv06,"
|
|
const SNAPSHOT_GARAGE_URL = "http://192.168.1.69/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()
|
|
+ "-"
|
|
+ String(date.getMonth() + 1).padStart(2, '0')
|
|
+ "-"
|
|
+ String(date.getDate()).padStart(2, '0')
|
|
+ "_"
|
|
+ String(date.getHours()).padStart(2, '0')
|
|
+ "-"
|
|
+ String(date.getMinutes()).padStart(2, '0')
|
|
+ "-"
|
|
+ String(date.getSeconds()).padStart(2, '0')
|
|
+ "_"
|
|
+ date.getMilliseconds()
|
|
+".jpg";
|
|
}
|
|
|
|
|
|
function snapshotSalon() {
|
|
http.get(SNAPSHOT_SALON_URL, (res) => {
|
|
res.pipe(fs.createWriteStream(snapshotPath()));
|
|
});
|
|
}
|
|
|
|
function snapshotGarage() {
|
|
http.get(SNAPSHOT_GARAGE_URL, (res) => {
|
|
res.pipe(fs.createWriteStream(snapshotPath()));
|
|
});
|
|
}
|
|
|
|
app.get('/snapshot', (req, res) => {
|
|
try{
|
|
snapshotSalon();
|
|
res.send('ok');
|
|
} catch(e)
|
|
{
|
|
res.status(500).send(e);
|
|
}
|
|
});
|
|
|
|
app.get('/snapshotGarage', (req, res) => {
|
|
try{
|
|
snapshotGarage();
|
|
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}`);
|
|
}); |