photosite/dist/generate.js

65 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2024-01-08 20:10:39 +00:00
require("dotenv/config");
const log_1 = require("./log");
2024-01-08 20:38:27 +00:00
const promises_1 = require("fs/promises");
const path_1 = require("path");
2024-01-08 20:10:39 +00:00
const shell_1 = require("./shell");
class Generate {
constructor() {
2024-01-08 20:38:27 +00:00
this.inbox = typeof process.env.INBOX !== 'undefined' ? process.env.INBOX : '~/Photos/toprocess';
this.log = (0, log_1.createLog)('generate');
this.log.info(`Generating site: ${new Date()}`);
2024-01-08 20:38:27 +00:00
this.generate();
}
async generate() {
await this.checkInbox();
}
2024-01-08 20:10:39 +00:00
async checkInbox() {
2024-01-08 20:38:27 +00:00
let inbox;
let images;
try {
inbox = await (0, promises_1.realpath)(this.inbox);
}
catch (err) {
this.log.error(err);
return;
}
try {
images = await (0, promises_1.readdir)(inbox);
}
catch (err) {
this.log.error(err);
return;
}
images = images.filter(el => {
if (el.toLowerCase().indexOf('.jpg') !== -1
|| el.toLowerCase().indexOf('.jpeg') !== -1
|| el.toLowerCase().indexOf('.tif') !== -1
|| el.toLowerCase().indexOf('.tiff') !== -1) {
return true;
}
return false;
});
if (images.length === 0) {
this.log.info(`No new images found`);
return;
}
images = images.map(el => (0, path_1.join)(inbox, el));
console.dir(images);
2024-01-08 20:10:39 +00:00
}
async img(file) {
const cmd = ['bash', 'scripts/img.sh', file];
const shell = new shell_1.Shell(cmd);
try {
await shell.execute();
}
catch (err) {
this.log.error(err);
return;
}
this.log.info(`Processed image file for ${file}`);
}
}
new Generate();
//# sourceMappingURL=generate.js.map