Prechádzať zdrojové kódy

Fix Compressor docs, pass files array to compressor:complete event (#3682)

* Fix Compressor docs

* Remove unused test commands

* Add note that all options are passed

* Add event to types

* Update website/src/docs/compressor.md

Co-authored-by: Merlijn Vos <merlijn@soverin.net>

* Update packages/@uppy/compressor/types/index.d.ts

Co-authored-by: Merlijn Vos <merlijn@soverin.net>

* add files array as callback to compressor:complete

Co-authored-by: Merlijn Vos <merlijn@soverin.net>
Artur Paikin 2 rokov pred
rodič
commit
b0e01ff082

+ 0 - 2
package.json

@@ -156,8 +156,6 @@
     "e2e:generate": "yarn workspace e2e generate-test",
     "test:companion": "yarn workspace @uppy/companion test",
     "test:companion:watch": "yarn workspace @uppy/companion test --watch",
-    "test:endtoend:local": "yarn workspace @uppy-tests/end2end test:endtoend:local",
-    "test:endtoend": "yarn workspace @uppy-tests/end2end test:endtoend",
     "test:locale-packs": "yarn locale-packs:unused && yarn locale-packs:warnings",
     "test:locale-packs:unused": "yarn workspace @uppy-dev/locale-pack test unused",
     "test:locale-packs:warnings": "yarn workspace @uppy-dev/locale-pack test warnings",

+ 3 - 1
packages/@uppy/compressor/src/index.js

@@ -43,6 +43,7 @@ export default class Compressor extends BasePlugin {
 
   async prepareUpload (fileIDs) {
     let totalCompressedSize = 0
+    const compressedFiles = []
     const compressAndApplyResult = this.#RateLimitedQueue.wrapPromiseFunction(
       async (file) => {
         try {
@@ -60,6 +61,7 @@ export default class Compressor extends BasePlugin {
             data: compressedBlob,
           })
           this.uppy.setFileMeta(file.id, { name, type })
+          compressedFiles.push(file)
         } catch (err) {
           this.uppy.log(`[Image Compressor] Failed to compress ${file.id}:`, 'warning')
           this.uppy.log(err, 'warning')
@@ -98,7 +100,7 @@ export default class Compressor extends BasePlugin {
     // while waiting for all the files to complete pre-processing.
     await Promise.all(promises)
 
-    this.uppy.emit('compressor:complete')
+    this.uppy.emit('compressor:complete', compressedFiles)
 
     // Only show informer if Compressor mananged to save at least a kilobyte
     if (totalCompressedSize > 1024) {

+ 9 - 0
packages/@uppy/compressor/types/index.d.ts

@@ -1,4 +1,5 @@
 import type { PluginOptions, BasePlugin } from '@uppy/core'
+import { UppyFile } from '@uppy/utils'
 import type CompressorLocale from './generatedLocale'
 
 export interface CompressorOptions extends PluginOptions {
@@ -7,6 +8,14 @@ export interface CompressorOptions extends PluginOptions {
   locale?: CompressorLocale
 }
 
+export type CompressorCompleteCallback<TMeta> = (files: UppyFile<TMeta>[]) => void;
+
+declare module '@uppy/core' {
+  export interface UppyEventMap<TMeta> {
+    'compressor:complete': CompressorCompleteCallback<TMeta>
+  }
+}
+
 declare class Compressor extends BasePlugin<CompressorOptions> {}
 
 export default Compressor

+ 5 - 3
website/src/docs/compressor.md

@@ -43,6 +43,8 @@ uppy.use(Compressor, {
 })
 ```
 
+You can also pass any of the [Compressor.js options](https://github.com/fengyuanchen/compressorjs#options) here.
+
 ### `id`
 
 * Type: `string`
@@ -53,13 +55,13 @@ A unique identifier for this plugin. It defaults to `'Compressor'`.
 ### `quality`
 
 * Type: `number`
-* Default: `0.8`
+* Default: `0.6`
 
 This option is passed to [Compressor.js](https://github.com/fengyuanchen/compressorjs).
 
-The quality of the output image. It must be a number between `0` and `1`. If this argument is anything else, the default values `0.92` and `0.80` are used for `image/jpeg` and `image/webp` respectively. Other arguments are ignored. Be careful to use `1` as it may make the size of the output image become larger.
+The quality of the output image. It must be a number between `0` and `1`. Be careful to use `1` as it may make the size of the output image become larger.
 
-**Note:** This option only available for `image/jpeg` and `image/webp` images.
+> **Note:** This option is only available for `image/jpeg` and `image/webp` images.
 
 ### `limit`