photo_server_json_flutter_c.../watcher_logic.mjs
2026-03-23 12:31:01 +01:00

39 lines
908 B
JavaScript

import fs from "fs";
import readline from "readline";
const user = process.argv[2];
const LOCK_FILE = `./${user}.scan`;
const DELAY = 10000;
let lastEventTime = 0;
let timer = null;
console.log(`Node attivo per utente: ${user}`);
function handleQuietPeriod() {
const now = Date.now();
if (now - lastEventTime < DELAY) return;
if (fs.existsSync(LOCK_FILE)) {
console.log(`Lock ${LOCK_FILE} presente, attendo...`);
timer = setTimeout(handleQuietPeriod, DELAY);
return;
}
console.log(`modificato ${user} (nessuna attività per 10 secondi)`);
fs.writeFileSync(LOCK_FILE, "lock");
}
const rl = readline.createInterface({
input: process.stdin,
crlfDelay: Infinity
});
rl.on("line", line => {
console.log("Evento:", line);
lastEventTime = Date.now();
if (timer) clearTimeout(timer);
timer = setTimeout(handleQuietPeriod, DELAY);
});