diff options
author | bobzel <zzzman@gmail.com> | 2023-12-28 11:17:43 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2023-12-28 11:17:43 -0500 |
commit | fa6214e763fc341ad355c95424ae76f14450d8ce (patch) | |
tree | 3fc3e1025ffefd15bc76687f8693c0da4a9ae560 /src | |
parent | 3f5a1d34d4aa90f605500d464660c896e8168808 (diff) |
fixed uploading unsupported file. changed admzip reference.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/ApiManagers/UploadManager.ts | 6 | ||||
-rw-r--r-- | src/server/DashUploadUtils.ts | 22 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts index 9b0457a25..06f4f1a9d 100644 --- a/src/server/ApiManagers/UploadManager.ts +++ b/src/server/ApiManagers/UploadManager.ts @@ -13,7 +13,7 @@ import ApiManager, { Registration } from './ApiManager'; import { SolrManager } from './SearchManager'; import * as uuid from 'uuid'; import { DashVersion } from '../../fields/DocSymbols'; -const AdmZip = require('adm-zip'); +import * as AdmZip from 'adm-zip'; const imageDataUri = require('image-data-uri'); const fs = require('fs'); @@ -265,7 +265,7 @@ export default class UploadManager extends ApiManager { try { zip.extractEntryTo(entry.entryName, publicDirectory, true, false); createReadStream(pathname).pipe(createWriteStream(targetname)); - Jimp.read(pathname).then(img => { + Jimp.read(pathname).then((img:any) => { DashUploadUtils.imageResampleSizes(extension).forEach(({ width, suffix }) => { const outputPath = InjectSize(targetname, suffix); if (!width) createReadStream(pathname).pipe(createWriteStream(outputPath)); @@ -346,7 +346,7 @@ export default class UploadManager extends ApiManager { return imageDataUri.outputFile(uri, serverPathToFile(Directory.images, InjectSize(filename, origSuffix))).then((savedName: string) => { const ext = path.extname(savedName).toLowerCase(); if (AcceptableMedia.imageFormats.includes(ext)) { - Jimp.read(savedName).then(img => + Jimp.read(savedName).then((img:any) => (!origSuffix ? [{ width: 400, suffix: SizeSuffix.Medium }] : Object.values(DashUploadUtils.Sizes)) // .forEach(({ width, suffix }) => { const outputPath = serverPathToFile(Directory.images, InjectSize(filename, suffix) + ext); diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index cd9b635bd..0161a8d38 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -211,8 +211,8 @@ export namespace DashUploadUtils { const result = await UploadImage(filepath, basename(filepath)); return { source: file, result }; } - fs.unlink(path, () => {}); - return { source: file, result: { name: 'Unsupported image format', message: `Could not upload unsupported file (${name}). Please convert to an .jpg` } }; + fs.unlink(filepath, () => {}); + return { source: file, result: { name: 'Unsupported image format', message: `Could not upload unsupported file (${originalFilename}). Please convert to an .jpg` } }; case 'video': if (format.includes('x-matroska')) { console.log('case video'); @@ -247,15 +247,15 @@ export namespace DashUploadUtils { // ); // file.path = file.path.replace('.mov', '.mp4').replace('.MOV', '.mp4'); // format = '.mp4'; - fs.unlink(path, () => {}); - return { source: file, result: { name: 'Unsupported video format', message: `Could not upload unsupported file (${name}). Please convert to an .mp4` } }; + fs.unlink(filepath, () => {}); + return { source: file, result: { name: 'Unsupported video format', message: `Could not upload unsupported file (${originalFilename}). Please convert to an .mp4` } }; } } if (videoFormats.includes(format) || format.includes('.webm')) { return MoveParsedFile(file, Directory.videos); } - fs.unlink(path, () => {}); - return { source: file, result: { name: 'Unsupported video format', message: `Could not upload unsupported file (${name}). Please convert to an .mp4` } }; + fs.unlink(filepath, () => {}); + return { source: file, result: { name: 'Unsupported video format', message: `Could not upload unsupported file (${originalFilename}). Please convert to an .mp4` } }; case 'application': if (applicationFormats.includes(format)) { const val = UploadPdf(file); @@ -269,8 +269,8 @@ export namespace DashUploadUtils { if (audioFormats.includes(format)) { return UploadAudio(file, format); } - fs.unlink(path, () => {}); - return { source: file, result: { name: 'Unsupported audio format', message: `Could not upload unsupported file (${name}). Please convert to an .mp3` } }; + fs.unlink(filepath, () => {}); + return { source: file, result: { name: 'Unsupported audio format', message: `Could not upload unsupported file (${originalFilename}). Please convert to an .mp3` } }; case 'text': if (types[1] == 'csv') { return UploadCsv(file); @@ -278,7 +278,7 @@ export namespace DashUploadUtils { } console.log(red(`Ignoring unsupported file (${originalFilename}) with upload type (${type}).`)); - fs.unlink(path, () => {}); + fs.unlink(filepath, () => {}); return { source: file, result: new Error(`Could not upload unsupported file (${originalFilename}) with upload type (${type}).`) }; } @@ -615,13 +615,13 @@ export namespace DashUploadUtils { buffer = buffer2; } catch (e) {} return Jimp.read(buffer ?? fileIn) - .then(async img => { + .then(async (img:any) => { await Promise.all( sizes.filter(({ width }) => width) .map(({ width, suffix }) => img = img.resize(width, Jimp.AUTO).write(outputPath(suffix)) )); // prettier-ignore return writtenFiles; }) - .catch(e => { + .catch((e:any) => { console.log('ERROR' + e); return writtenFiles; }); |