Diffs assembly status to find new `uploads` and `results`, and emits
`transloadit:upload` and `transloadit:result` events accordingly.
Also emits `transloadit:complete` for newly finished assemblies
and `transloadit:assembly-error` for assemblies that failed.
This feature needs to store some custom data with the RestoreFiles
plugin. It does this by adding a `restore:get-data` event that gets a
callback as a parameter. This callback stores custom plugin data. It's
not great but idk.
core.on('restore:get-data', (setData) => {
setData({ whatever: 'beepboop' })
})
Fixes#315
This patch makes some function options that can return Promises a bit
easier to use. Previously, most of these required that the user returned
a Promise, even if they were doing sync work. Also, if an error was
thrown inside the provided function, it would actually throw the error
instead of rejecting a Promise, thus not allowing Uppy to show an error
notification or anything.
Instead, these options now use this pattern:
```js
Promise.resolve()
.then(() => this.opts.onSomething(argument))
```
Inside a `.then()` handler, both a Promise and a plain value can be
returned, and the resulting Promise will be resolved with the correct
value. Also, any sync errors `throw`n inside a `.then()` handler cause
the returned Promise to be rejected.
This adds back the ability to run assemblies without uploading any
files, which is useful in case the assembly uses an import robot.
To do this, this patch adds a new state key to the Transloadit plugin's
state, named `uploadsAssemblies` (open to bikeshedding lol)
This key associates assembly IDs with the upload ID that triggered them.
This allows figuring out which assemblies need to finish before
resolving the upload promise.
The upload ID is now passed into preprocessors and postprocessors so
they can use it to store metadata that is related to an upload instead
of a single file.
When `alwaysRunAssembly` is set to true, and zero files are available
for upload, an assembly is created anyway for the options returned by
`getAssemblyOptions(null)`.
It turns out that `afterUpload` actually didn't work correctly if
multiple assemblies were used for a single upload. I changed it so that
it does, and incidentally that also made it work again with zero-file
assemblies.
This patch adds a `getAssemblyOptions` function option to the
Transloadit plugin. This option can return an object or a Promise for an
object to configure the Transloadit assembly. The returned object can
contain `params`, a `signature`, and `fields`.
`getAssemblyOptions` is called on each file, so each file can return a
different set of options. Files that returned the same options are
bundled together and run through a single assembly. Files that return
different options will be run through different assemblies.
This means that it is now possible to make assembly parameters depend on
user input from eg. the MetaData plugin, and have different parameters
for different files. It's now also possible to generate very short-lived
signatures on the server when an upload starts.
Previously, the initial assembly data was reused in the complete event…
🙈
This patch fetches the assembly status again when the socket emits
`assembly_finished`, so we're always up to date.
This adds a new parameter to the transloadit:upload and
transloadit:result events, containing the assembly data.
```js
uppy.on('transloadit:upload', (file, assembly) => {
console.log('an upload was completed with template id', assembly.template_id)
})
```
```js
uppy.on('transloadit:result', (stepName, result, assembly) => {
console.log(`${stepName}:`, result, 'from', assembly)
})
```
The `transloadit:assembly` event is emitted when an assembly is created.
It receives the assembly data in the first parameter, and the file IDs
of the files that it belongs to in the second parameter.
```js
uppy.on('transloadit:assembly', (assembly, fileIDs) => {
const files = fileIDs.map((id) => uppy.getState().files[id])
console.log({ assembly, files })
})
```
The `afterUpload` handler wasn't returning a Promise anymore after I
changed it to support multiple simultaneous assemblies. Now it works
again, and `core.upload()` will reject if the assembly failed.