Skip to content

Commit

Permalink
Fix Compressor docs, pass files array to compressor:complete event (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>

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

Co-authored-by: Merlijn Vos <[email protected]>

* add files array as callback to compressor:complete

Co-authored-by: Merlijn Vos <[email protected]>
  • Loading branch information
arturi and Murderlon authored May 18, 2022
1 parent 888fc83 commit b0e01ff
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/@uppy/compressor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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')
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions packages/@uppy/compressor/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
8 changes: 5 additions & 3 deletions website/src/docs/compressor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`

Expand Down

0 comments on commit b0e01ff

Please sign in to comment.