Work on files module
This commit is contained in:
parent
ad46b4a476
commit
273252ceae
|
@ -14,8 +14,11 @@ interface ImageObject {
|
|||
name: string;
|
||||
}
|
||||
export declare class Files {
|
||||
private static sequencesDir;
|
||||
static init(sequencesDir: 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 enumerateSequence(path: string): Promise<ImageObject[]>;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ const imageExtensions = [
|
|||
'.bmp'
|
||||
];
|
||||
class Files {
|
||||
static async init(sequencesDir) {
|
||||
this.sequencesDir = sequencesDir;
|
||||
return this.exists(sequencesDir);
|
||||
}
|
||||
static async exists(path) {
|
||||
try {
|
||||
await (0, promises_1.access)(path);
|
||||
|
@ -27,35 +31,72 @@ class Files {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
static async enumerateSequences(path) {
|
||||
static async enumerateSequences() {
|
||||
const dirs = [];
|
||||
let all;
|
||||
let stats;
|
||||
let dirPath;
|
||||
path = await (0, promises_1.realpath)(path);
|
||||
const paths = [
|
||||
await (0, promises_1.realpath)(this.sequencesDir)
|
||||
];
|
||||
for (let path of paths) {
|
||||
try {
|
||||
all = await (0, promises_1.readdir)(path);
|
||||
}
|
||||
catch (err) {
|
||||
throw err;
|
||||
}
|
||||
for (let elem of all) {
|
||||
if (elem.substring(0, 1) === '.') {
|
||||
continue;
|
||||
}
|
||||
dirPath = (0, path_1.join)(path, elem);
|
||||
try {
|
||||
stats = await (0, promises_1.lstat)(dirPath);
|
||||
}
|
||||
catch (err) {
|
||||
continue;
|
||||
}
|
||||
if (!stats.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (!this.isSequence(dirPath)) {
|
||||
continue;
|
||||
}
|
||||
dirs.push({
|
||||
path: dirPath,
|
||||
hash: hash_1.Hashes.stringHash(dirPath),
|
||||
name: (0, path_1.basename)(dirPath)
|
||||
});
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
static async isSequence(dirPath) {
|
||||
let sequence = false;
|
||||
let all;
|
||||
let stats;
|
||||
let filePath;
|
||||
try {
|
||||
all = await (0, promises_1.readdir)(path);
|
||||
all = await (0, promises_1.readdir)(dirPath);
|
||||
}
|
||||
catch (err) {
|
||||
throw err;
|
||||
//
|
||||
}
|
||||
for (let elem of all) {
|
||||
dirPath = (0, path_1.join)(path, elem);
|
||||
filePath = (0, path_1.join)(dirPath, elem);
|
||||
try {
|
||||
stats = await (0, promises_1.lstat)(dirPath);
|
||||
if (stats.isDirectory()) {
|
||||
dirs.push({
|
||||
path: dirPath,
|
||||
hash: hash_1.Hashes.stringHash(dirPath),
|
||||
name: (0, path_1.basename)(dirPath)
|
||||
});
|
||||
}
|
||||
stats = await (0, promises_1.lstat)(filePath);
|
||||
}
|
||||
catch (err) {
|
||||
//
|
||||
}
|
||||
if (stats.isFile() && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
||||
sequence = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
return sequence;
|
||||
}
|
||||
static async enumerateVideos(path) {
|
||||
const videos = [];
|
||||
|
@ -100,6 +141,9 @@ class Files {
|
|||
throw err;
|
||||
}
|
||||
for (let elem of all) {
|
||||
if (elem.substring(0, 1) === '.') {
|
||||
continue;
|
||||
}
|
||||
filePath = (0, path_1.join)(path, elem);
|
||||
try {
|
||||
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,C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files_1.Files.exists(sequences);
|
||||
sequencesExists = await files_1.Files.init(sequences);
|
||||
if (!sequencesExists) {
|
||||
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
||||
process.exit(8);
|
||||
|
@ -282,7 +282,7 @@ function exposureSet(exposure) {
|
|||
sequence.setExposure(exposure);
|
||||
}
|
||||
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);
|
||||
if (typeof seq == 'undefined' || seq == null) {
|
||||
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) => {
|
||||
const sequencesArr = await files_1.Files.enumerateSequences(sequences);
|
||||
const sequencesArr = await files_1.Files.enumerateSequences();
|
||||
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
||||
const html = index({ sequences: sequencesArr, width, height, wsPort });
|
||||
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 { Hashes } from '../hash';
|
||||
import { basename, extname, join } from 'path';
|
||||
import { envString } from '../env';
|
||||
|
||||
interface SequenceObject {
|
||||
path : string,
|
||||
|
@ -37,6 +38,13 @@ const imageExtensions : string[] = [
|
|||
];
|
||||
|
||||
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> {
|
||||
try {
|
||||
await access(path);
|
||||
|
@ -46,39 +54,75 @@ export class Files {
|
|||
}
|
||||
}
|
||||
|
||||
public static async enumerateSequences (path : string) : Promise<SequenceObject[]> {
|
||||
public static async enumerateSequences () : Promise<SequenceObject[]> {
|
||||
const dirs : SequenceObject[] = [];
|
||||
let all : string[];
|
||||
let stats : Stats;
|
||||
let dirPath : string;
|
||||
|
||||
path = await realpath(path);
|
||||
const paths : string[] = [
|
||||
await realpath(this.sequencesDir)
|
||||
];
|
||||
|
||||
try {
|
||||
all = await readdir(path)
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
for (let elem of all) {
|
||||
dirPath = join(path, elem);
|
||||
for (let path of paths) {
|
||||
try {
|
||||
stats = await lstat(dirPath);
|
||||
if (stats.isDirectory()) {
|
||||
dirs.push({
|
||||
path : dirPath,
|
||||
hash : Hashes.stringHash(dirPath),
|
||||
name : basename(dirPath)
|
||||
});
|
||||
}
|
||||
all = await readdir(path)
|
||||
} catch (err) {
|
||||
//
|
||||
throw err;
|
||||
}
|
||||
|
||||
for (let elem of all) {
|
||||
if (elem.substring(0, 1) === '.') {
|
||||
continue;
|
||||
}
|
||||
dirPath = join(path, elem);
|
||||
try {
|
||||
stats = await lstat(dirPath);
|
||||
} catch (err) {
|
||||
continue;
|
||||
}
|
||||
if (!stats.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (!this.isSequence(dirPath)) {
|
||||
continue;
|
||||
}
|
||||
dirs.push({
|
||||
path : dirPath,
|
||||
hash : Hashes.stringHash(dirPath),
|
||||
name : basename(dirPath)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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[]> {
|
||||
const videos : VideoObject[] = [];
|
||||
let all : string[];
|
||||
|
@ -127,6 +171,9 @@ export class Files {
|
|||
}
|
||||
|
||||
for (let elem of all) {
|
||||
if (elem.substring(0, 1) === '.') {
|
||||
continue;
|
||||
}
|
||||
filePath = join(path, elem);
|
||||
try {
|
||||
stats = await lstat(filePath);
|
||||
|
|
|
@ -140,7 +140,7 @@ async function settings () {
|
|||
process.exit(7);
|
||||
} else {
|
||||
sequences = process.env['SEQUENCES'];
|
||||
sequencesExists = await Files.exists(sequences);
|
||||
sequencesExists = await Files.init(sequences);
|
||||
if (!sequencesExists) {
|
||||
log.error(`The SEQUENCES directory in .env, ${sequences}, does not exist`);
|
||||
process.exit(8);
|
||||
|
@ -277,7 +277,7 @@ function exposureSet (exposure : number) {
|
|||
}
|
||||
|
||||
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);
|
||||
if (typeof seq == 'undefined' || seq == null) {
|
||||
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) => {
|
||||
const sequencesArr : SequenceObject[] = await Files.enumerateSequences(sequences);
|
||||
const sequencesArr : SequenceObject[] = await Files.enumerateSequences();
|
||||
//const videosArr : VideoObject[] = await Files.enumerateVideos(videos);
|
||||
const html : string = index({ sequences : sequencesArr, width, height, wsPort });
|
||||
res.send(html);
|
||||
|
|
Loading…
Reference in New Issue