photosite/src/generate.ts

79 lines
1.7 KiB
TypeScript

import 'dotenv/config';
import { createLog } from './log';
import type { Logger } from 'winston';
import { Database } from 'sqlite3';
import { readFile, readdir, realpath } from 'fs/promises';
import { join } from 'path';
import { Shell } from './shell';
import { hash } from './hash';
class Generate {
private log : Logger;
private files : string[];
private inbox : string = typeof process.env.INBOX !== 'undefined' ? process.env.INBOX : '~/Photos/toprocess';
constructor () {
this.log = createLog('generate');
this.log.info(`Generating site: ${new Date()}`);
this.generate();
}
private async generate () {
//check version
//sync
await this.checkInbox();
//validate
}
private async checkInbox () {
let inbox : string;
let images : string[];
try {
inbox = await realpath(this.inbox);
} catch (err) {
this.log.error(err);
return;
}
try {
images = await 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 => join(inbox, el));
console.dir(images)
}
private async img (file : string) {
const cmd : string[] = ['bash', 'scripts/img.sh', file];
const shell : Shell = new Shell(cmd);
try {
await shell.execute();
} catch (err) {
this.log.error(err);
return;
}
this.log.info(`Processed image file for ${file}`);
}
}
new Generate();