Compare commits
2 Commits
acf0efd4b5
...
977076711a
| Author | SHA1 | Date | |
|---|---|---|---|
| 977076711a | |||
| e82cc2ac83 |
35
index.js
35
index.js
@ -5,14 +5,14 @@ const port = 80;
|
|||||||
const http = require("http");
|
const http = require("http");
|
||||||
const fs = require('fs');
|
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_LIVING_ROOM_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,"
|
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(){
|
function formatDate()
|
||||||
let date = new Date();
|
{
|
||||||
|
let date = new Date();
|
||||||
|
|
||||||
return "/snapshot/snapshot-"
|
return date.getFullYear()
|
||||||
+ date.getFullYear()
|
|
||||||
+ "-"
|
+ "-"
|
||||||
+ String(date.getMonth() + 1).padStart(2, '0')
|
+ String(date.getMonth() + 1).padStart(2, '0')
|
||||||
+ "-"
|
+ "-"
|
||||||
@ -24,26 +24,39 @@ function snapshotPath(){
|
|||||||
+ "-"
|
+ "-"
|
||||||
+ String(date.getSeconds()).padStart(2, '0')
|
+ String(date.getSeconds()).padStart(2, '0')
|
||||||
+ "_"
|
+ "_"
|
||||||
+ date.getMilliseconds()
|
+ date.getMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
function snapshotPath(room){
|
||||||
|
return "/snapshot/snapshot-"
|
||||||
|
+ room + "-"
|
||||||
|
+ formatDate()
|
||||||
+".jpg";
|
+".jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function snapshotPathCamGarage(){
|
||||||
|
return snapshotPath("garage");
|
||||||
|
}
|
||||||
|
|
||||||
function snapshotSalon() {
|
function snapshotPathCamLivingRoom(){
|
||||||
http.get(SNAPSHOT_SALON_URL, (res) => {
|
return snapshotPath("living_room");
|
||||||
res.pipe(fs.createWriteStream(snapshotPath()));
|
}
|
||||||
|
|
||||||
|
function snapshotLivingRoom() {
|
||||||
|
http.get(SNAPSHOT_LIVING_ROOM_URL, (res) => {
|
||||||
|
res.pipe(fs.createWriteStream(snapshotPathCamLivingRoom()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function snapshotGarage() {
|
function snapshotGarage() {
|
||||||
http.get(SNAPSHOT_GARAGE_URL, (res) => {
|
http.get(SNAPSHOT_GARAGE_URL, (res) => {
|
||||||
res.pipe(fs.createWriteStream(snapshotPath()));
|
res.pipe(fs.createWriteStream(snapshotPathCamGarage()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/snapshot', (req, res) => {
|
app.get('/snapshot', (req, res) => {
|
||||||
try{
|
try{
|
||||||
snapshotSalon();
|
snapshotLivingRoom();
|
||||||
res.send('ok');
|
res.send('ok');
|
||||||
} catch(e)
|
} catch(e)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user