// @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 { 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)); } } }