Work on files module
This commit is contained in:
parent
ad46b4a476
commit
273252ceae
|
@ -14,8 +14,11 @@ interface ImageObject {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
export declare class Files {
|
export declare class Files {
|
||||||
|
private static sequencesDir;
|
||||||
|
static init(sequencesDir: string): Promise<boolean>;
|
||||||
static exists(path: string): Promise<boolean>;
|
static exists(path: string): Promise<boolean>;
|
||||||
static enumerateSequences(path: string): Promise<SequenceObject[]>;
|
static enumerateSequences(): Promise<SequenceObject[]>;
|
||||||
|
static isSequence(dirPath: string): Promise<boolean>;
|
||||||
static enumerateVideos(path: string): Promise<VideoObject[]>;
|
static enumerateVideos(path: string): Promise<VideoObject[]>;
|
||||||
static enumerateSequence(path: string): Promise<ImageObject[]>;
|
static enumerateSequence(path: string): Promise<ImageObject[]>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ const imageExtensions = [
|
||||||
'.bmp'
|
'.bmp'
|
||||||
];
|
];
|
||||||
class Files {
|
class Files {
|
||||||
|
static async init(sequencesDir) {
|
||||||
|
this.sequencesDir = sequencesDir;
|
||||||
|
return this.exists(sequencesDir);
|
||||||
|
}
|
||||||
static async exists(path) {
|
static async exists(path) {
|
||||||
try {
|
try {
|
||||||
await (0, promises_1.access)(path);
|
await (0, promises_1.access)(path);
|
||||||
|
@ -27,12 +31,15 @@ class Files {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async enumerateSequences(path) {
|
static async enumerateSequences() {
|
||||||
const dirs = [];
|
const dirs = [];
|
||||||
let all;
|
let all;
|
||||||
let stats;
|
let stats;
|
||||||
let dirPath;
|
let dirPath;
|
||||||
path = await (0, promises_1.realpath)(path);
|
const paths = [
|
||||||
|
await (0, promises_1.realpath)(this.sequencesDir)
|
||||||
|
];
|
||||||
|
for (let path of paths) {
|
||||||
try {
|
try {
|
||||||
all = await (0, promises_1.readdir)(path);
|
all = await (0, promises_1.readdir)(path);
|
||||||
}
|
}
|
||||||
|
@ -40,10 +47,22 @@ class Files {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
for (let elem of all) {
|
for (let elem of all) {
|
||||||
|
if (elem.substring(0, 1) === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
dirPath = (0, path_1.join)(path, elem);
|
dirPath = (0, path_1.join)(path, elem);
|
||||||
try {
|
try {
|
||||||
stats = await (0, promises_1.lstat)(dirPath);
|
stats = await (0, promises_1.lstat)(dirPath);
|
||||||
if (stats.isDirectory()) {
|
}
|
||||||
|
catch (err) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!stats.isDirectory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!this.isSequence(dirPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
dirs.push({
|
dirs.push({
|
||||||
path: dirPath,
|
path: dirPath,
|
||||||
hash: hash_1.Hashes.stringHash(dirPath),
|
hash: hash_1.Hashes.stringHash(dirPath),
|
||||||
|
@ -51,11 +70,33 @@ class Files {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dirs;
|
||||||
|
}
|
||||||
|
static async isSequence(dirPath) {
|
||||||
|
let sequence = false;
|
||||||
|
let all;
|
||||||
|
let stats;
|
||||||
|
let filePath;
|
||||||
|
try {
|
||||||
|
all = await (0, promises_1.readdir)(dirPath);
|
||||||
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
for (let elem of all) {
|
||||||
|
filePath = (0, path_1.join)(dirPath, elem);
|
||||||
|
try {
|
||||||
|
stats = await (0, promises_1.lstat)(filePath);
|
||||||
}
|
}
|
||||||
return dirs;
|
catch (err) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
if (stats.isFile() && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
||||||
|
sequence = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sequence;
|
||||||
}
|
}
|
||||||
static async enumerateVideos(path) {
|
static async enumerateVideos(path) {
|
||||||
const videos = [];
|
const videos = [];
|
||||||
|
@ -100,6 +141,9 @@ class Files {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
for (let elem of all) {
|
for (let elem of all) {
|
||||||
|
if (elem.substring(0, 1) === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
filePath = (0, path_1.join)(path, elem);
|
filePath = (0, path_1.join)(path, elem);
|
||||||
try {
|
try {
|
||||||
stats = await (0, promises_1.lstat)(filePath);
|
stats = await (0, promises_1.lstat)(filePath);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":";;;AAAA,0CAA+D;AAE/D,kCAAiC;AACjC,+BAA+C;AAoB/C,MAAM,eAAe,GAAc;IAClC,MAAM;IACN,MAAM;IACN,MAAM;CACN,CAAC;AAEF,MAAM,eAAe,GAAc;IAClC,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;CACN,CAAC;AAEF,MAAa,KAAK;IACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAE,IAAa;QACxC,IAAI,CAAC;YACJ,MAAM,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC;YACnB,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAE,IAAa;QACpD,MAAM,IAAI,GAAsB,EAAE,CAAC;QACnC,IAAI,GAAc,CAAC;QACnB,IAAI,KAAa,CAAC;QAClB,IAAI,OAAgB,CAAC;QAErB,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,CAAC;YACJ,GAAG,GAAG,MAAM,IAAA,kBAAO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AAI,eAAe,CAAC,OAAO,CAAC,IAAA,cAAO,EAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC7F,IAAI,CAAC,IAAI,CAAC;wBACT,IAAI,EAAG,QAAQ;wBACf,IAAI,EAAG,aAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;wBAClC,IAAI,EAAG,IAAA,eAAQ,EAAC,QAAQ,CAAC;qBACzB,CAAC,CAAC;gBACJ,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,EAAE;YACH,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA1JD,sBA0JC;AAGD,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC"}
|
|
@ -151,7 +151,7 @@ async function settings() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sequences = process.env['SEQUENCES'];
|
sequences = process.env['SEQUENCES'];
|
||||||
sequencesExists = await files_1.Files.exists(sequences);
|
sequencesExists = await files_1.Files.init(sequences);
|
||||||
if (!sequencesExists) {
|
if (!sequencesExists) {
|
||||||
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
||||||
process.exit(8);
|
process.exit(8);
|
||||||
|
@ -282,7 +282,7 @@ function exposureSet(exposure) {
|
||||||
sequence.setExposure(exposure);
|
sequence.setExposure(exposure);
|
||||||
}
|
}
|
||||||
async function select(id) {
|
async function select(id) {
|
||||||
const sequencesArr = await files_1.Files.enumerateSequences(sequences);
|
const sequencesArr = await files_1.Files.enumerateSequences();
|
||||||
const seq = sequencesArr.find(el => el.hash === id);
|
const seq = sequencesArr.find(el => el.hash === id);
|
||||||
if (typeof seq == 'undefined' || seq == null) {
|
if (typeof seq == 'undefined' || seq == null) {
|
||||||
log.error('Sequence not found, maybe deleted?', new Error(`Cannot find sequence ${id}`));
|
log.error('Sequence not found, maybe deleted?', new Error(`Cannot find sequence ${id}`));
|
||||||
|
@ -405,7 +405,7 @@ function scale(msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.get('/', async (req, res, next) => {
|
app.get('/', async (req, res, next) => {
|
||||||
const sequencesArr = await files_1.Files.enumerateSequences(sequences);
|
const sequencesArr = await files_1.Files.enumerateSequences();
|
||||||
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
||||||
const html = index({ sequences: sequencesArr, width, height, wsPort });
|
const html = index({ sequences: sequencesArr, width, height, wsPort });
|
||||||
res.send(html);
|
res.send(html);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@ import { access, lstat, readdir, realpath } from 'fs/promises';
|
||||||
import type { Stats } from 'fs';
|
import type { Stats } from 'fs';
|
||||||
import { Hashes } from '../hash';
|
import { Hashes } from '../hash';
|
||||||
import { basename, extname, join } from 'path';
|
import { basename, extname, join } from 'path';
|
||||||
|
import { envString } from '../env';
|
||||||
|
|
||||||
interface SequenceObject {
|
interface SequenceObject {
|
||||||
path : string,
|
path : string,
|
||||||
|
@ -37,6 +38,13 @@ const imageExtensions : string[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export class Files {
|
export class Files {
|
||||||
|
private static sequencesDir : string;
|
||||||
|
|
||||||
|
public static async init (sequencesDir : string) : Promise<boolean>{
|
||||||
|
this.sequencesDir = sequencesDir;
|
||||||
|
return this.exists(sequencesDir);
|
||||||
|
}
|
||||||
|
|
||||||
public static async exists (path : string) : Promise<boolean> {
|
public static async exists (path : string) : Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await access(path);
|
await access(path);
|
||||||
|
@ -46,14 +54,17 @@ export class Files {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async enumerateSequences (path : string) : Promise<SequenceObject[]> {
|
public static async enumerateSequences () : Promise<SequenceObject[]> {
|
||||||
const dirs : SequenceObject[] = [];
|
const dirs : SequenceObject[] = [];
|
||||||
let all : string[];
|
let all : string[];
|
||||||
let stats : Stats;
|
let stats : Stats;
|
||||||
let dirPath : string;
|
let dirPath : string;
|
||||||
|
|
||||||
path = await realpath(path);
|
const paths : string[] = [
|
||||||
|
await realpath(this.sequencesDir)
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let path of paths) {
|
||||||
try {
|
try {
|
||||||
all = await readdir(path)
|
all = await readdir(path)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -61,24 +72,57 @@ export class Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let elem of all) {
|
for (let elem of all) {
|
||||||
|
if (elem.substring(0, 1) === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
dirPath = join(path, elem);
|
dirPath = join(path, elem);
|
||||||
try {
|
try {
|
||||||
stats = await lstat(dirPath);
|
stats = await lstat(dirPath);
|
||||||
if (stats.isDirectory()) {
|
} catch (err) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!stats.isDirectory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!this.isSequence(dirPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
dirs.push({
|
dirs.push({
|
||||||
path : dirPath,
|
path : dirPath,
|
||||||
hash : Hashes.stringHash(dirPath),
|
hash : Hashes.stringHash(dirPath),
|
||||||
name : basename(dirPath)
|
name : basename(dirPath)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async isSequence (dirPath : string) : Promise<boolean> {
|
||||||
|
let sequence : boolean = false;
|
||||||
|
let all : string[];
|
||||||
|
let stats : Stats;
|
||||||
|
let filePath : string;
|
||||||
|
try {
|
||||||
|
all = await readdir(dirPath);
|
||||||
|
} catch (err) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
for (let elem of all) {
|
||||||
|
filePath = join(dirPath, elem);
|
||||||
|
try {
|
||||||
|
stats = await lstat(filePath);
|
||||||
|
} catch (err) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
if (stats.isFile() && imageExtensions.indexOf(extname(basename(elem).toLowerCase())) !== -1) {
|
||||||
|
sequence = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
|
||||||
public static async enumerateVideos (path : string) : Promise<VideoObject[]> {
|
public static async enumerateVideos (path : string) : Promise<VideoObject[]> {
|
||||||
const videos : VideoObject[] = [];
|
const videos : VideoObject[] = [];
|
||||||
let all : string[];
|
let all : string[];
|
||||||
|
@ -127,6 +171,9 @@ export class Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let elem of all) {
|
for (let elem of all) {
|
||||||
|
if (elem.substring(0, 1) === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
filePath = join(path, elem);
|
filePath = join(path, elem);
|
||||||
try {
|
try {
|
||||||
stats = await lstat(filePath);
|
stats = await lstat(filePath);
|
||||||
|
|
|
@ -140,7 +140,7 @@ async function settings () {
|
||||||
process.exit(7);
|
process.exit(7);
|
||||||
} else {
|
} else {
|
||||||
sequences = process.env['SEQUENCES'];
|
sequences = process.env['SEQUENCES'];
|
||||||
sequencesExists = await Files.exists(sequences);
|
sequencesExists = await Files.init(sequences);
|
||||||
if (!sequencesExists) {
|
if (!sequencesExists) {
|
||||||
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
||||||
process.exit(8);
|
process.exit(8);
|
||||||
|
@ -277,7 +277,7 @@ function exposureSet (exposure : number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function select (id : string) : Promise<boolean> {
|
async function select (id : string) : Promise<boolean> {
|
||||||
const sequencesArr : SequenceObject[] = await Files.enumerateSequences(sequences);
|
const sequencesArr : SequenceObject[] = await Files.enumerateSequences();
|
||||||
const seq : SequenceObject = sequencesArr.find(el => el.hash === id);
|
const seq : SequenceObject = sequencesArr.find(el => el.hash === id);
|
||||||
if (typeof seq == 'undefined' || seq == null) {
|
if (typeof seq == 'undefined' || seq == null) {
|
||||||
log.error('Sequence not found, maybe deleted?', new Error(`Cannot find sequence ${id}`));
|
log.error('Sequence not found, maybe deleted?', new Error(`Cannot find sequence ${id}`));
|
||||||
|
@ -410,7 +410,7 @@ function scale (msg : Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', async (req : Request, res : Response, next : NextFunction) => {
|
app.get('/', async (req : Request, res : Response, next : NextFunction) => {
|
||||||
const sequencesArr : SequenceObject[] = await Files.enumerateSequences(sequences);
|
const sequencesArr : SequenceObject[] = await Files.enumerateSequences();
|
||||||
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
||||||
const html : string = index({ sequences : sequencesArr, width, height, wsPort });
|
const html : string = index({ sequences : sequencesArr, width, height, wsPort });
|
||||||
res.send(html);
|
res.send(html);
|
||||||
|
|
Loading…
Reference in New Issue