64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
import readline from "readline";
|
|
|
|
const user = process.argv[2];
|
|
|
|
// Estensioni foto/video
|
|
const photoExt = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".tiff", ".heic", ".heif"];
|
|
const videoExt = [".mp4", ".mov", ".avi", ".mkv", ".webm", ".m4v"];
|
|
|
|
function isMediaFile(filename) {
|
|
const lower = filename.toLowerCase();
|
|
return photoExt.some(ext => lower.endsWith(ext)) ||
|
|
videoExt.some(ext => lower.endsWith(ext));
|
|
}
|
|
|
|
console.log(`Node attivo per utente: ${user}`);
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
crlfDelay: Infinity
|
|
});
|
|
|
|
rl.on("line", line => {
|
|
// Esempio: "/path/dir/ CLOSE_WRITE,CLOSE file.jpg"
|
|
const parts = line.trim().split(/\s+/);
|
|
|
|
const path = parts[0];
|
|
const action = parts[1];
|
|
const file = parts[2];
|
|
|
|
if (!file) return;
|
|
|
|
if (!isMediaFile(file)) {
|
|
console.log(`Ignorato (non media): ${file}`);
|
|
return;
|
|
}
|
|
|
|
let type = null;
|
|
|
|
// ADD → solo CLOSE_WRITE o CLOSE_WRITE,CLOSE
|
|
if (/^CLOSE_WRITE(,CLOSE)?$/.test(action)) {
|
|
type = "ADD";
|
|
}
|
|
|
|
// ADD → MOVED_TO (solo se esatto)
|
|
else if (action === "MOVED_TO") {
|
|
type = "ADD";
|
|
}
|
|
|
|
// DEL → MOVED_FROM
|
|
else if (action === "MOVED_FROM") {
|
|
type = "DEL";
|
|
}
|
|
|
|
// DEL → DELETE
|
|
else if (action === "DELETE") {
|
|
type = "DEL";
|
|
}
|
|
|
|
else {
|
|
return;
|
|
}
|
|
|
|
console.log(`${type} ${file} ${path} ${user}`);
|
|
});
|