Spaces:
Paused
Paused
Commit
·
2a3efb7
1
Parent(s):
50725ac
fixes
Browse files- src/index.mts +12 -8
src/index.mts
CHANGED
|
@@ -52,9 +52,9 @@ app.post("/", async (req: Request, res: Response, _next: NextFunction) => {
|
|
| 52 |
}
|
| 53 |
|
| 54 |
const { projectTempDir, outputTempDir, imageFolder } = setupDirectories();
|
| 55 |
-
await handleFileStorage(dataFile, projectTempDir);
|
| 56 |
|
| 57 |
-
await generateImagesFromData(
|
| 58 |
|
| 59 |
options.projectPath = projectTempDir;
|
| 60 |
options.workspacePath = projectTempDir;
|
|
@@ -100,14 +100,17 @@ async function handleFileStorage(dataFile: fileUpload.UploadedFile | Buffer, pro
|
|
| 100 |
console.log("typeof dataFile: " + typeof dataFile);
|
| 101 |
if (dataFile instanceof Buffer) {
|
| 102 |
console.log("dataFile is a Buffer!");
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
} else if (typeof dataFile === "object" && dataFile.mv) {
|
| 105 |
console.log(`typeof dataFile === "object" && dataFile.mv`);
|
| 106 |
try {
|
| 107 |
console.log("dataFile.name = " + dataFile.name);
|
| 108 |
-
|
| 109 |
-
console.log("path.join(projectTempDir, dataFile.name) = " +
|
| 110 |
-
await dataFile.mv(
|
|
|
|
| 111 |
} catch (error) {
|
| 112 |
throw new Error(`File can't be moved: ${error}`);
|
| 113 |
}
|
|
@@ -115,11 +118,12 @@ async function handleFileStorage(dataFile: fileUpload.UploadedFile | Buffer, pro
|
|
| 115 |
console.log(`unrecognized dataFile format`);
|
| 116 |
throw new Error("Invalid File");
|
| 117 |
}
|
|
|
|
| 118 |
}
|
| 119 |
|
| 120 |
-
function generateImagesFromData(
|
| 121 |
return new Promise<void>((resolve, reject) => {
|
| 122 |
-
ffmpeg(
|
| 123 |
.outputOptions('-vf', 'fps=1')
|
| 124 |
.output(path.join(imageFolder, 'image-%03d.png'))
|
| 125 |
.on('end', resolve)
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
const { projectTempDir, outputTempDir, imageFolder } = setupDirectories();
|
| 55 |
+
const filePath = await handleFileStorage(dataFile, projectTempDir);
|
| 56 |
|
| 57 |
+
await generateImagesFromData(imageFolder, filePath);
|
| 58 |
|
| 59 |
options.projectPath = projectTempDir;
|
| 60 |
options.workspacePath = projectTempDir;
|
|
|
|
| 100 |
console.log("typeof dataFile: " + typeof dataFile);
|
| 101 |
if (dataFile instanceof Buffer) {
|
| 102 |
console.log("dataFile is a Buffer!");
|
| 103 |
+
const filePath = path.join(projectTempDir, "data.mp4");
|
| 104 |
+
await writeFile(filePath, dataFile);
|
| 105 |
+
return filePath;
|
| 106 |
} else if (typeof dataFile === "object" && dataFile.mv) {
|
| 107 |
console.log(`typeof dataFile === "object" && dataFile.mv`);
|
| 108 |
try {
|
| 109 |
console.log("dataFile.name = " + dataFile.name);
|
| 110 |
+
const filePath = path.join(projectTempDir, dataFile.name)
|
| 111 |
+
console.log("path.join(projectTempDir, dataFile.name) = " + filePath);
|
| 112 |
+
await dataFile.mv(filePath);
|
| 113 |
+
return filePath;
|
| 114 |
} catch (error) {
|
| 115 |
throw new Error(`File can't be moved: ${error}`);
|
| 116 |
}
|
|
|
|
| 118 |
console.log(`unrecognized dataFile format`);
|
| 119 |
throw new Error("Invalid File");
|
| 120 |
}
|
| 121 |
+
|
| 122 |
}
|
| 123 |
|
| 124 |
+
function generateImagesFromData(imageFolder: string, filePath: string) {
|
| 125 |
return new Promise<void>((resolve, reject) => {
|
| 126 |
+
ffmpeg(filePath)
|
| 127 |
.outputOptions('-vf', 'fps=1')
|
| 128 |
.output(path.join(imageFolder, 'image-%03d.png'))
|
| 129 |
.on('end', resolve)
|