aboutsummaryrefslogtreecommitdiff
path: root/src/server/DashUploadUtils.ts
diff options
context:
space:
mode:
authorJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
committerJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
commitcd93c88b8fee83a99342eac4dc60f7b4373fa843 (patch)
treeb00d1f46c802752c90e54bb21be785a05e05195e /src/server/DashUploadUtils.ts
parent4997c3de20a381eac30224a7a550afa66174f07d (diff)
parent3a733aa0fd24517e83649824dec0fc8bcc0bde43 (diff)
added tutorial tool, still need to integrate with metadatatool
Diffstat (limited to 'src/server/DashUploadUtils.ts')
-rw-r--r--src/server/DashUploadUtils.ts21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index a2747257a..f76371b0d 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -221,9 +221,7 @@ export namespace DashUploadUtils {
const parseExifData = async (source: string) => {
const image = await request.get(source, { encoding: null });
const { /* data, */ error } = await new Promise<{ data: ExifData; error: string | undefined }>(resolve => {
- new ExifImage({ image }, (exifError, data) => {
- resolve({ data, error: exifError?.message });
- });
+ new ExifImage({ image }, (exifError, data) => resolve({ data, error: exifError?.message }));
});
return error ? { data: undefined, error } : { data: await exifr.parse(image), error };
};
@@ -295,7 +293,7 @@ export namespace DashUploadUtils {
try {
// Compute the native width and height ofthe image with an npm module
- const { width: nativeWidth, height: nativeHeight } = await requestImageSize(resolvedUrl);
+ const { width: nativeWidth, height: nativeHeight } = await requestImageSize(resolvedUrl).catch(() => ({ width: 0, height: 0 }));
// Bundle up the information into an object
return {
source,
@@ -307,7 +305,6 @@ export namespace DashUploadUtils {
...results,
};
} catch (e: unknown) {
- console.log(e);
return new Error(e ? e.toString?.() : 'unkown error');
}
};
@@ -450,14 +447,12 @@ export namespace DashUploadUtils {
* 3) the size of the image, in bytes (4432130)
* 4) the content type of the image, i.e. image/(jpeg | png | ...)
*/
- export const UploadImage = async (source: string, filename?: string, prefix: string = ''): Promise<Upload.ImageInformation | Error> => {
- const result = await InspectImage(source);
- if (result instanceof Error) {
- return { name: result.name, message: result.message };
- }
- const outputFile = filename || result.filename || '';
- return UploadInspectedImage(result, outputFile, prefix, isLocal().exec(source) || source.startsWith('data:') ? true : false);
- };
+ export const UploadImage = (source: string, filename?: string, prefix: string = ''): Promise<Upload.ImageInformation | Error> =>
+ InspectImage(source).then(async result =>
+ result instanceof Error
+ ? ({ name: result.name, message: result.message } as Error) //
+ : UploadInspectedImage(result, filename || result.filename || '', prefix, isLocal().exec(source) || source.startsWith('data:') ? true : false)
+ );
type md5 = 'md5';
type falsetype = false;