|
@@ -113,16 +113,53 @@ module.exports = class Transloadit extends Plugin {
|
|
return this.opts.waitForEncoding || this.opts.waitForMetadata
|
|
return this.opts.waitForEncoding || this.opts.waitForMetadata
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO if/when the transloadit API returns tus upload metadata in the
|
|
|
|
+ // file objects in the assembly status, change this to use a unique ID
|
|
|
|
+ // instead of checking the file name and size.
|
|
|
|
+ findFile ({ name, size }) {
|
|
|
|
+ const files = this.core.state.files
|
|
|
|
+ for (const id in files) {
|
|
|
|
+ if (!files.hasOwnProperty(id)) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if (files[id].name === name && files[id].size === size) {
|
|
|
|
+ return files[id]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ onFileUploadComplete (uploadedFile) {
|
|
|
|
+ const file = this.findFile(uploadedFile)
|
|
|
|
+ this.updateState({
|
|
|
|
+ files: Object.assign({}, this.state.files, {
|
|
|
|
+ [uploadedFile.id]: {
|
|
|
|
+ id: file.id,
|
|
|
|
+ uploadedFile
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ this.core.bus.emit('transloadit:upload', uploadedFile)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ onResult (stepName, result) {
|
|
|
|
+ const file = this.state.files[result.original_id]
|
|
|
|
+ result.localId = file.id
|
|
|
|
+ this.updateState({
|
|
|
|
+ results: this.state.results.concat(result)
|
|
|
|
+ })
|
|
|
|
+ this.core.bus.emit('transloadit:result', stepName, result)
|
|
|
|
+ }
|
|
|
|
+
|
|
connectSocket () {
|
|
connectSocket () {
|
|
this.socket = new StatusSocket(
|
|
this.socket = new StatusSocket(
|
|
this.state.assembly.websocket_url,
|
|
this.state.assembly.websocket_url,
|
|
this.state.assembly
|
|
this.state.assembly
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ this.socket.on('upload', this.onFileUploadComplete.bind(this))
|
|
|
|
+
|
|
if (this.opts.waitForEncoding) {
|
|
if (this.opts.waitForEncoding) {
|
|
- this.socket.on('result', (stepName, result) => {
|
|
|
|
- this.core.bus.emit('transloadit:result', stepName, result)
|
|
|
|
- })
|
|
|
|
|
|
+ this.socket.on('result', this.onResult.bind(this))
|
|
}
|
|
}
|
|
|
|
|
|
this.assemblyReady = new Promise((resolve, reject) => {
|
|
this.assemblyReady = new Promise((resolve, reject) => {
|
|
@@ -179,6 +216,12 @@ module.exports = class Transloadit extends Plugin {
|
|
install () {
|
|
install () {
|
|
this.core.addPreProcessor(this.prepareUpload)
|
|
this.core.addPreProcessor(this.prepareUpload)
|
|
this.core.addPostProcessor(this.afterUpload)
|
|
this.core.addPostProcessor(this.afterUpload)
|
|
|
|
+
|
|
|
|
+ this.updateState({
|
|
|
|
+ assembly: null,
|
|
|
|
+ files: {},
|
|
|
|
+ results: []
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
uninstall () {
|
|
uninstall () {
|