return processed file sizes
This commit is contained in:
parent
9be2b7d691
commit
af9b8ac9bd
|
@ -89,7 +89,11 @@
|
||||||
class={`file-icon ${determineFileIcon(selectedImage.extension)}`} />
|
class={`file-icon ${determineFileIcon(selectedImage.extension)}`} />
|
||||||
<span class="filename">{selectedImage.name}</span>
|
<span class="filename">{selectedImage.name}</span>
|
||||||
</div>
|
</div>
|
||||||
<p>{selectedImage.size / 1000}KB</p>
|
<p>
|
||||||
|
{#if selectedImage.size <= 1000000}
|
||||||
|
{selectedImage.size / 1000}KB
|
||||||
|
{:else}{selectedImage.size / 1000000}MB{/if}
|
||||||
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<div class="delete-button" on:click={removeFile}>
|
<div class="delete-button" on:click={removeFile}>
|
||||||
<i class="ri-close-line" />
|
<i class="ri-close-line" />
|
||||||
|
|
|
@ -70,8 +70,7 @@ exports.processLocalFileUpload = async function(ctx) {
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: get file sizes of images after resize
|
const processedFiles = await Promise.all(fileProcessOperations)
|
||||||
await Promise.all(fileProcessOperations)
|
|
||||||
|
|
||||||
let pendingFileUploads
|
let pendingFileUploads
|
||||||
// local document used to track which files need to be uploaded
|
// local document used to track which files need to be uploaded
|
||||||
|
@ -88,12 +87,12 @@ exports.processLocalFileUpload = async function(ctx) {
|
||||||
})
|
})
|
||||||
|
|
||||||
pendingFileUploads.uploads = [
|
pendingFileUploads.uploads = [
|
||||||
...filesToProcess,
|
...processedFiles,
|
||||||
...pendingFileUploads.uploads,
|
...pendingFileUploads.uploads,
|
||||||
]
|
]
|
||||||
await db.put(pendingFileUploads)
|
await db.put(pendingFileUploads)
|
||||||
|
|
||||||
ctx.body = filesToProcess
|
ctx.body = processedFiles
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(500, err)
|
ctx.throw(500, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,25 @@ const FORMATS = {
|
||||||
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
|
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
|
||||||
}
|
}
|
||||||
|
|
||||||
function processImage({ path, outputPath }) {
|
async function processImage(file) {
|
||||||
return sharp(path)
|
const imgMeta = await sharp(file.path)
|
||||||
.resize(300)
|
.resize(300)
|
||||||
.toFile(outputPath)
|
.toFile(file.outputPath)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...file,
|
||||||
|
...imgMeta,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function process(file) {
|
async function process(file) {
|
||||||
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
||||||
return processImage(file)
|
return await processImage(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No processing required
|
// No processing required
|
||||||
return fsPromises.copyFile(file.path, file.outputPath)
|
await fsPromises.copyFile(file.path, file.outputPath)
|
||||||
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.process = process
|
exports.process = process
|
||||||
|
|
Loading…
Reference in New Issue