Work on generate script
This commit is contained in:
parent
120ba4545f
commit
1e789a16cc
|
@ -1,4 +1,5 @@
|
|||
node_modules
|
||||
.env
|
||||
www
|
||||
*.DS_Store
|
||||
*.DS_Store
|
||||
data
|
|
@ -2,13 +2,51 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv/config");
|
||||
const log_1 = require("./log");
|
||||
const promises_1 = require("fs/promises");
|
||||
const path_1 = require("path");
|
||||
const shell_1 = require("./shell");
|
||||
class Generate {
|
||||
constructor() {
|
||||
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()}`);
|
||||
this.generate();
|
||||
}
|
||||
async generate() {
|
||||
await this.checkInbox();
|
||||
}
|
||||
async checkInbox() {
|
||||
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);
|
||||
}
|
||||
async img(file) {
|
||||
const cmd = ['bash', 'scripts/img.sh', file];
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;AAA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AM,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,IAAA,WAAI,EAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,CAAC;IAEO,KAAK,CAAC,GAAG,CAAE,IAAa;QAC/B,MAAM,GAAG,GAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;QACxD,MAAM,KAAK,GAAW,IAAI,aAAK,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC;YACJ,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;CACD;AAED,IAAI,QAAQ,EAAE,CAAC"}
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hash = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const crypto_1 = require("crypto");
|
||||
function hash(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hashSum = (0, crypto_1.createHash)('sha256');
|
||||
const stream = (0, fs_1.createReadStream)(path);
|
||||
stream.on('error', (err) => reject(err));
|
||||
stream.on('data', (chunk) => hashSum.update(chunk));
|
||||
stream.on('end', () => resolve(hashSum.digest('hex')));
|
||||
});
|
||||
}
|
||||
exports.hash = hash;
|
||||
module.exports = { hash };
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hash/index.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AACtC,mCAA0C;AAE1C,SAAgB,IAAI,CAAE,IAAa;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkB,EAAE,MAAiB,EAAE,EAAE;QAC5D,MAAM,OAAO,GAAU,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAS,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACjD,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACJ,CAAC;AARD,oBAQC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,CAAC"}
|
|
@ -1,5 +1,9 @@
|
|||
CREATE TABLE IF NOT EXISTS photos {
|
||||
|
||||
id TEXT PRIMARY KEY,
|
||||
created INTEGER,
|
||||
updated INTEGER,
|
||||
|
||||
deleted INTEGER DEFAULT 0
|
||||
}
|
||||
|
||||
CREATE TABLE IF NOT EXISTS version {
|
||||
|
|
|
@ -1,19 +1,66 @@
|
|||
import 'dotenv/config';
|
||||
import { createLog } from './log';
|
||||
import type { Logger } from 'winston';
|
||||
import { Shell } from './shell';
|
||||
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) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import { createReadStream } from 'fs';
|
||||
import { createHash, Hash } from 'crypto';
|
||||
|
||||
export function hash (path : string) : Promise<string> {
|
||||
return new Promise((resolve : Function, reject : Function) => {
|
||||
const hashSum : Hash = createHash('sha256');
|
||||
const stream : any = createReadStream(path);
|
||||
stream.on('error', (err : Error) => reject(err));
|
||||
stream.on('data', (chunk : Buffer) => hashSum.update(chunk));
|
||||
stream.on('end', () => resolve(hashSum.digest('hex')));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { hash };
|
Loading…
Reference in New Issue