diff --git a/packages/builder/src/components/common/Dropzone.svelte b/packages/builder/src/components/common/Dropzone.svelte index a36a40c6d7..5eedd2d7fa 100644 --- a/packages/builder/src/components/common/Dropzone.svelte +++ b/packages/builder/src/components/common/Dropzone.svelte @@ -89,7 +89,11 @@ class={`file-icon ${determineFileIcon(selectedImage.extension)}`} /> {selectedImage.name} -

{selectedImage.size / 1000}KB

+

+ {#if selectedImage.size <= 1000000} + {selectedImage.size / 1000}KB + {:else}{selectedImage.size / 1000000}MB{/if} +

diff --git a/packages/server/src/api/controllers/static.js b/packages/server/src/api/controllers/static.js index 672d71aab9..0720948731 100644 --- a/packages/server/src/api/controllers/static.js +++ b/packages/server/src/api/controllers/static.js @@ -70,8 +70,7 @@ exports.processLocalFileUpload = async function(ctx) { ) try { - // TODO: get file sizes of images after resize - await Promise.all(fileProcessOperations) + const processedFiles = await Promise.all(fileProcessOperations) let pendingFileUploads // local document used to track which files need to be uploaded @@ -88,12 +87,12 @@ exports.processLocalFileUpload = async function(ctx) { }) pendingFileUploads.uploads = [ - ...filesToProcess, + ...processedFiles, ...pendingFileUploads.uploads, ] await db.put(pendingFileUploads) - ctx.body = filesToProcess + ctx.body = processedFiles } catch (err) { ctx.throw(500, err) } diff --git a/packages/server/src/utilities/fileProcessor.js b/packages/server/src/utilities/fileProcessor.js index 151e6a6e17..3e580e9e37 100644 --- a/packages/server/src/utilities/fileProcessor.js +++ b/packages/server/src/utilities/fileProcessor.js @@ -6,19 +6,25 @@ const FORMATS = { IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"], } -function processImage({ path, outputPath }) { - return sharp(path) +async function processImage(file) { + const imgMeta = await sharp(file.path) .resize(300) - .toFile(outputPath) + .toFile(file.outputPath) + + return { + ...file, + ...imgMeta, + } } -function process(file) { +async function process(file) { if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) { - return processImage(file) + return await processImage(file) } // No processing required - return fsPromises.copyFile(file.path, file.outputPath) + await fsPromises.copyFile(file.path, file.outputPath) + return file } exports.process = process