aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/ApiManagers/UploadManager.ts23
-rw-r--r--src/server/DashUploadUtils.ts59
2 files changed, 18 insertions, 64 deletions
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index 398b007b5..0ee0a34df 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -44,25 +44,10 @@ export default class UploadManager extends ApiManager {
register({
method: Method.POST,
- subscription: "/uploadVideosandConcatenate",
- secureHandler: async ({ req, res }) => {
- const form = new formidable.IncomingForm();
- form.keepExtensions = true;
- form.uploadDir = pathToDirectory(Directory.parsed_files);
- return new Promise<void>(resolve => {
- form.parse(req, async (_err, _fields, files) => {
- const results: Upload.FileResponse[] = [];
-
- // create an array of all the file paths
- const filePaths: string[] = Object.keys(files).map(key => files[key].path);
- console.log("uploading files", Array.isArray(filePaths));
- const result = await DashUploadUtils.concatenateVideos(filePaths);
- console.log('concatenated', result);
- result && !(result.result instanceof Error) && results.push(result);
- _success(res, results)
- resolve();
- });
- });
+ subscription: "/concatVideos",
+ secureHandler: async ({ req, res }) => {
+ // req.body contains the array of server paths to the videos
+ _success(res, await DashUploadUtils.concatVideos(req.body));
}
});
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 148b0df65..be30c115d 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -63,21 +63,20 @@ export namespace DashUploadUtils {
const { imageFormats, videoFormats, applicationFormats, audioFormats } = AcceptableMedia; //TODO:glr
- export async function concatenateVideos(filePaths: string[]): Promise<Upload.FileResponse> {
+ export async function concatVideos(filePaths: string[]): Promise<Upload.AccessPathInfo> {
// make a list of paths to create the ordered text file for ffmpeg
- //const filePaths = videoFiles.map(file => file.path);
- // write the text file to the file system
const inputListName = 'concat.txt';
const textFilePath = path.join(filesDirectory, inputListName);
// make a list of paths to create the ordered text file for ffmpeg
- const filePathsText = filePaths.map(filePath => `file '${filePath}'`).join('\n');
+ const filePathsText = filePaths.map(filePath => `file '${filePath}'`).join('\n');
+ // write the text file to the file system
writeFile(textFilePath, filePathsText, (err) => console.log(err));
- console.log(filePathsText)
+ console.log('fileTextPaths', filePathsText)
// make output file name based on timestamp
- const outputFileName = `output-${Utils.GenerateGuid()}.mkv`;
- // create the output file path in the parsed_file directory
- const outputFilePath = path.join(filesDirectory, outputFileName);
+ const outputFileName = `output-${Utils.GenerateGuid()}.mp4`;
+ // create the output file path in the videos directory
+ const outputFilePath = path.join(pathToDirectory(Directory.videos), outputFileName);
// concatenate the videos
await new Promise((resolve, reject) => {
@@ -92,45 +91,15 @@ export namespace DashUploadUtils {
.on("end", resolve);
})
- // delete concat.txt from the file system
- unlinkSync(textFilePath);
-
- // read the output file from the file system
- // const outputFile = fs.readFileSync(outputFilePath);
-
- // make a new blob object with the output file buffer
- // const outputFileBlob = new Blob([outputFile.buffer], { type: 'x-matroska/mkv' });
-
- // TODO: make with toJSON()
+ // delete concat.txt from the file system
+ unlinkSync(textFilePath);
+ // delete the old segment videos from the server
+ filePaths.forEach(filePath => unlinkSync(filePath));
- // make a data object
- const outputFileObject: formidable.File = {
- size: 0,
- name: outputFileName,
- path: outputFilePath,
- // size: outputFileBlob.size,
- type: 'video/x-matroska;codecs=avc1,opus',
- lastModifiedDate: new Date(),
-
- toJSON: () => ({ ...outputFileObject, filename: outputFilePath.replace(/.*\//, ""), mtime: null, length: 0, mime: "", toJson: () => undefined as any })
+ // return the path(s) to the output file
+ return {
+ accessPaths: getAccessPaths(Directory.videos, outputFileName)
}
-
- // const file = { ...outputFileObject, toJSON: () => ({ ...outputFileObject, filename: outputFilePath.replace(/.*\//, ""), mtime: null, length: 0, mime: "", toJson: () => undefined as any }) };
-
- // this will convert it to mp4 and save it to the server
- //return await MoveParsedFile(outputFileObject, Directory.videos);
-
- return await upload(outputFileObject);
-
- // // return only the output (first) file to the videos directory
- // return {
- // source: file, result: {
- // accessPaths: {
- // agnostic: getAccessPaths(Directory.videos, outputFileName)
- // },
- // rawText: undefined
- // }
- // }
}
export function uploadYoutube(videoId: string): Promise<Upload.FileResponse> {