@uppy/compressor: ignore remote files, calculate savings correctly (#3578)

This commit is contained in:
Artur Paikin 2022-03-16 20:17:16 +00:00 committed by GitHub
parent fc6f8f3fe5
commit 953ae5c929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -46,8 +46,9 @@ export default class Compressor extends BasePlugin {
async (file) => {
try {
const compressedBlob = await this.compress(file.data)
this.uppy.log(`[Image Compressor] Image ${file.id} size before/after compression: ${file.data.size} / ${compressedBlob.size}`)
totalCompressedSize += compressedBlob.size
const compressedSavingsSize = file.data.size - compressedBlob.size
this.uppy.log(`[Image Compressor] Image ${file.id} compressed by ${prettierBytes(compressedSavingsSize)}`)
totalCompressedSize += compressedSavingsSize
this.uppy.setFileState(file.id, {
data: compressedBlob,
size: compressedBlob.size,
@ -66,6 +67,10 @@ export default class Compressor extends BasePlugin {
message: this.i18n('compressingImages'),
})
if (file.isRemote) {
return Promise.resolve()
}
// Some browsers (Firefox) add blobs with empty file type, when files are
// added from a folder. Uppy auto-detects type from extension, but leaves the original blob intact.
// However, Compressor.js failes when file has no type, so we set it here

View file

@ -23,6 +23,7 @@ import Form from '@uppy/form'
import ImageEditor from '@uppy/image-editor'
import DropTarget from '@uppy/drop-target'
import Audio from '@uppy/audio'
import Compressor from '@uppy/compressor'
/* eslint-enable import/no-extraneous-dependencies */
// DEV CONFIG: create a .env file in the project root directory to customize those values.
@ -91,6 +92,7 @@ export default () => {
.use(DropTarget, {
target: document.body,
})
.use(Compressor)
switch (UPLOADER) {
case 'tus':