Service decorators - oh the evil I have wraught....

This commit is contained in:
2026-04-29 19:44:25 +01:00
parent 8bb18bce05
commit 532e7eac81
21 changed files with 1129 additions and 79 deletions
+43
View File
@@ -0,0 +1,43 @@
// @ts-ignore
import { walk } from '@root/walk';
import {Dirent} from "node:fs";
import {fileTypeFromFile} from "file-type";
import FFMpegService from "../services/FFMpegService";
import TaskInterface from "../interfaces/TaskInterface";
export default class ScanFoldersTask implements TaskInterface {
private hasRun: boolean = false;
constructor(protected mount: string) {
}
shouldRun(): boolean {
return !this.hasRun;
}
async run(): Promise<void> {
this.hasRun = true;
return this.scanFolder();
}
async scanFolder() {
return walk(this.mount, async (err: any, pathname: string, dirent: Dirent) => {
if (err) return false;
if (dirent.isDirectory()) await this.processFolder(pathname, dirent);
if (dirent.isFile()) await this.processFile(pathname, dirent);
return true;
});
}
async processFolder(pathname: string, dirent: Dirent) {
console.log('folder', pathname);
}
async processFile(pathname: string, dirent: Dirent) {
console.log('file', pathname);
const type = await fileTypeFromFile(pathname);
if (type === undefined || type.mime.startsWith('audio')) {
console.log(await FFMpegService.checkFile(pathname));
}
}
}