diff options
Diffstat (limited to 'src/server/DashUploadUtils.ts')
-rw-r--r-- | src/server/DashUploadUtils.ts | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index f13580865..552ab57a5 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -16,6 +16,7 @@ import { clientPathToFile, Directory, pathToDirectory, serverPathToFile } from ' import { resolvedServerUrl } from "./server_Initialization"; import { AcceptableMedia, Upload } from './SharedMediaTypes'; import request = require('request-promise'); +import formidable = require('formidable'); const { exec } = require("child_process"); const parse = require('pdf-parse'); const ffmpeg = require("fluent-ffmpeg"); @@ -25,7 +26,8 @@ export enum SizeSuffix { Small = "_s", Medium = "_m", Large = "_l", - Original = "_o" + Original = "_o", + None = "" } export function InjectSize(filename: string, size: SizeSuffix) { @@ -69,7 +71,7 @@ export namespace DashUploadUtils { else { console.log(`stdout: ${stdout}`); const data = { size: 0, path: videoId + ".mp4", name: videoId, type: "video/mp4" }; - const file = { ...data, toJSON: () => data }; + const file = { ...data, toJSON: () => ({ ...data, filename: data.path.replace(/.*\//, ""), mtime: null, length: 0, mime: "", toJson: () => undefined as any }) }; res(MoveParsedFile(file, Directory.videos)); } }); @@ -78,7 +80,7 @@ export namespace DashUploadUtils { export async function upload(file: File): Promise<Upload.FileResponse> { const { type, path, name } = file; - const types = type.split("/"); + const types = type?.split("/") ?? []; const category = types[0]; let format = `.${types[1]}`; @@ -242,7 +244,7 @@ export namespace DashUploadUtils { // Use the request library to parse out file level image information in the headers const { headers } = (await new Promise<any>((resolve, reject) => { request.head(resolvedUrl, (error, res) => error ? reject(error) : resolve(res)); - }).catch(error => console.error(error))); + }).catch(console.error)); try { // Compute the native width and height ofthe image with an npm module const { width: nativeWidth, height: nativeHeight } = await requestImageSize(resolvedUrl); @@ -256,7 +258,7 @@ export namespace DashUploadUtils { filename, ...results }; - } catch (e) { + } catch (e: any) { console.log(e); return e; } @@ -272,7 +274,7 @@ export namespace DashUploadUtils { * @param suffix If the file doesn't have a suffix and you want to provide it one * to appear in the new location */ - export async function MoveParsedFile(file: File, destination: Directory, suffix: string | undefined = undefined, text?: string): Promise<Upload.FileResponse> { + export async function MoveParsedFile(file: formidable.File, destination: Directory, suffix: string | undefined = undefined, text?: string): Promise<Upload.FileResponse> { const { path: sourcePath } = file; let name = path.basename(sourcePath); suffix && (name += suffix); |