49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
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}`);
|
|
}); |