Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,244 Bytes
652f343 7bea24d 652f343 7bea24d 652f343 7bea24d 652f343 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import path from "node:path"
import { promises as fs } from "node:fs"
import { VideoTask } from "../types.mts"
import { readTask } from "./readTask.mts"
export const readTasks = async (taskDirFilePath: string): Promise<VideoTask[]> => {
let tasksFiles: string[] = []
try {
const filesInDir = await fs.readdir(taskDirFilePath)
console.log("filesInDir:", filesInDir)
// we only keep valid files (in UUID.json format)
tasksFiles = filesInDir.filter(fileName => fileName.match(/[a-z0-9\-]\.json/i))
console.log("tasksfiles:", tasksFiles)
} catch (err) {
console.log(`failed to read tasks: ${err}`)
}
const tasks: VideoTask[] = []
for (const taskFileName of tasksFiles) {
console.log("taskFileName:", taskFileName)
const taskFilePath = path.join(taskDirFilePath, taskFileName)
try {
const task = await readTask(taskFilePath)
tasks.push(task)
} catch (parsingErr) {
console.log(`failed to read ${taskFileName}: ${parsingErr}`)
console.log(`deleting corrupted file ${taskFileName}`)
try {
await fs.unlink(taskFilePath)
} catch (unlinkErr) {
console.log(`failed to unlink ${taskFileName}: ${unlinkErr}`)
}
}
}
return tasks
}
|