diff options
| author | Bob Zeleznik <zzzman@gmail.com> | 2020-03-19 12:04:34 -0400 |
|---|---|---|
| committer | Bob Zeleznik <zzzman@gmail.com> | 2020-03-19 12:04:34 -0400 |
| commit | e82bac3d8a0e796b8477b2e875e685c16a224a8d (patch) | |
| tree | f7cae22f57af776595411230ef88e7f15753c1ce /src/server/DashUploadUtils.ts | |
| parent | 85a67ff30d86fa51b4534f717d3857aa23b732d1 (diff) | |
| parent | b0e121a9d767ca30e5b6732e3aeabbda0e0a7e97 (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/server/DashUploadUtils.ts')
| -rw-r--r-- | src/server/DashUploadUtils.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index bc5d1d95b..2af816df8 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -60,7 +60,7 @@ export namespace DashUploadUtils { const types = type.split("/"); const category = types[0]; - const format = `.${types[1]}`; + let format = `.${types[1]}`; switch (category) { case "image": @@ -77,8 +77,12 @@ export namespace DashUploadUtils { return UploadPdf(file); } case "audio": + const components = format.split(";"); + if (components.length > 1) { + format = components[0]; + } if (audioFormats.includes(format)) { - return MoveParsedFile(file, Directory.audio); + return UploadAudio(file, format); } } @@ -86,12 +90,6 @@ export namespace DashUploadUtils { return { source: file, result: new Error(`Could not upload unsupported file (${name}) with upload type (${type}).`) }; } - async function UploadAudio(file: File) { - const { path: sourcePath } = file; - - return MoveParsedFile(file, Directory.audio); - } - async function UploadPdf(file: File) { const { path: sourcePath } = file; const dataBuffer = readFileSync(sourcePath); @@ -105,6 +103,13 @@ export namespace DashUploadUtils { return MoveParsedFile(file, Directory.pdfs); } + const manualSuffixes = [".webm"]; + + async function UploadAudio(file: File, format: string) { + const suffix = manualSuffixes.includes(format) ? format : undefined; + return MoveParsedFile(file, Directory.audio, suffix); + } + /** * Uploads an image specified by the @param source to Dash's /public/files/ * directory, and returns information generated during that upload @@ -193,9 +198,10 @@ export namespace DashUploadUtils { }; }; - export async function MoveParsedFile(file: File, destination: Directory): Promise<Upload.FileResponse> { + export async function MoveParsedFile(file: File, destination: Directory, suffix: string | undefined = undefined): Promise<Upload.FileResponse> { const { path: sourcePath } = file; - const name = path.basename(sourcePath); + let name = path.basename(sourcePath); + suffix && (name += suffix); return new Promise(resolve => { const destinationPath = serverPathToFile(destination, name); rename(sourcePath, destinationPath, error => { |
