index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. const Translator = require('@uppy/utils/lib/Translator')
  2. const { Plugin } = require('@uppy/core')
  3. const Tus = require('@uppy/tus')
  4. const Assembly = require('./Assembly')
  5. const Client = require('./Client')
  6. const AssemblyOptions = require('./AssemblyOptions')
  7. const AssemblyWatcher = require('./AssemblyWatcher')
  8. function defaultGetAssemblyOptions (file, options) {
  9. return {
  10. params: options.params,
  11. signature: options.signature,
  12. fields: options.fields
  13. }
  14. }
  15. const COMPANION = 'https://api2.transloadit.com/companion'
  16. // Regex matching acceptable postMessage() origins for authentication feedback from companion.
  17. const ALLOWED_COMPANION_PATTERN = /\.transloadit\.com$/
  18. // Regex used to check if a Companion address is run by Transloadit.
  19. const TL_COMPANION = /https?:\/\/api2(?:-\w+)?\.transloadit\.com\/companion/
  20. const TL_UPPY_SERVER = /https?:\/\/api2(?:-\w+)?\.transloadit\.com\/uppy-server/
  21. /**
  22. * Upload files to Transloadit using Tus.
  23. */
  24. module.exports = class Transloadit extends Plugin {
  25. constructor (uppy, opts) {
  26. super(uppy, opts)
  27. this.type = 'uploader'
  28. this.id = 'Transloadit'
  29. this.title = 'Transloadit'
  30. const defaultLocale = {
  31. strings: {
  32. creatingAssembly: 'Preparing upload...',
  33. creatingAssemblyFailed: 'Transloadit: Could not create Assembly',
  34. encoding: 'Encoding...'
  35. }
  36. }
  37. const defaultOptions = {
  38. service: 'https://api2.transloadit.com',
  39. waitForEncoding: false,
  40. waitForMetadata: false,
  41. alwaysRunAssembly: false,
  42. importFromUploadURLs: false,
  43. signature: null,
  44. params: null,
  45. fields: {},
  46. getAssemblyOptions: defaultGetAssemblyOptions,
  47. locale: defaultLocale
  48. }
  49. this.opts = Object.assign({}, defaultOptions, opts)
  50. this.locale = Object.assign({}, defaultLocale, this.opts.locale)
  51. this.locale.strings = Object.assign({}, defaultLocale.strings, this.opts.locale.strings)
  52. this.translator = new Translator({ locale: this.locale })
  53. this.i18n = this.translator.translate.bind(this.translator)
  54. this._prepareUpload = this._prepareUpload.bind(this)
  55. this._afterUpload = this._afterUpload.bind(this)
  56. this._handleError = this._handleError.bind(this)
  57. this._onFileUploadURLAvailable = this._onFileUploadURLAvailable.bind(this)
  58. this._onRestored = this._onRestored.bind(this)
  59. this._getPersistentData = this._getPersistentData.bind(this)
  60. if (this.opts.params) {
  61. AssemblyOptions.validateParams(this.opts.params)
  62. }
  63. this.client = new Client({
  64. service: this.opts.service
  65. })
  66. // Contains Assembly instances for in-progress Assemblies.
  67. this.activeAssemblies = {}
  68. }
  69. /**
  70. * Attach metadata to files to configure the Tus plugin to upload to Transloadit.
  71. * Also use Transloadit's Companion
  72. *
  73. * See: https://github.com/tus/tusd/wiki/Uploading-to-Transloadit-using-tus#uploading-using-tus
  74. *
  75. * @param {Object} file
  76. * @param {Object} status
  77. */
  78. _attachAssemblyMetadata (file, status) {
  79. // Add the metadata parameters Transloadit needs.
  80. const meta = {
  81. ...file.meta,
  82. assembly_url: status.assembly_url,
  83. filename: file.name,
  84. fieldname: 'file'
  85. }
  86. // Add Assembly-specific Tus endpoint.
  87. const tus = {
  88. ...file.tus,
  89. endpoint: status.tus_url
  90. }
  91. // Set Companion location. We only add this, if 'file' has the attribute
  92. // remote, because this is the criteria to identify remote files.
  93. // We only replace the hostname for Transloadit's companions, so that
  94. // people can also self-host them while still using Transloadit for encoding.
  95. let remote = file.remote
  96. if (file.remote && TL_UPPY_SERVER.test(file.remote.serverUrl)) {
  97. const err = new Error(
  98. 'The https://api2.transloadit.com/uppy-server endpoint was renamed to ' +
  99. 'https://api2.transloadit.com/companion, please update your `serverUrl` ' +
  100. 'options accordingly.')
  101. // Explicitly log this error here because it is caught by the `createAssembly`
  102. // Promise further along.
  103. // That's fine, but createAssembly only shows the informer, we need something a
  104. // little more noisy.
  105. this.uppy.log(err)
  106. throw err
  107. }
  108. if (file.remote && TL_COMPANION.test(file.remote.serverUrl)) {
  109. const newHost = status.companion_url
  110. .replace(/\/$/, '')
  111. const path = file.remote.url
  112. .replace(file.remote.serverUrl, '')
  113. .replace(/^\//, '')
  114. remote = {
  115. ...file.remote,
  116. serverUrl: newHost,
  117. serverPattern: ALLOWED_COMPANION_PATTERN,
  118. url: `${newHost}/${path}`
  119. }
  120. }
  121. // Store the Assembly ID this file is in on the file under the `transloadit` key.
  122. const newFile = {
  123. ...file,
  124. transloadit: {
  125. assembly: status.assembly_id
  126. }
  127. }
  128. // Only configure the Tus plugin if we are uploading straight to Transloadit (the default).
  129. if (!this.opts.importFromUploadURLs) {
  130. Object.assign(newFile, { meta, tus, remote })
  131. }
  132. return newFile
  133. }
  134. _createAssembly (fileIDs, uploadID, options) {
  135. this.uppy.log('[Transloadit] create Assembly')
  136. return this.client.createAssembly({
  137. params: options.params,
  138. fields: options.fields,
  139. expectedFiles: fileIDs.length,
  140. signature: options.signature
  141. }).then((newAssembly) => {
  142. const assembly = new Assembly(newAssembly)
  143. const status = assembly.status
  144. const { assemblies, uploadsAssemblies } = this.getPluginState()
  145. this.setPluginState({
  146. // Store the Assembly status.
  147. assemblies: {
  148. ...assemblies,
  149. [status.assembly_id]: status
  150. },
  151. // Store the list of Assemblies related to this upload.
  152. uploadsAssemblies: {
  153. ...uploadsAssemblies,
  154. [uploadID]: [
  155. ...uploadsAssemblies[uploadID],
  156. status.assembly_id
  157. ]
  158. }
  159. })
  160. const { files } = this.uppy.getState()
  161. const updatedFiles = {}
  162. fileIDs.forEach((id) => {
  163. updatedFiles[id] = this._attachAssemblyMetadata(this.uppy.getFile(id), status)
  164. })
  165. this.uppy.setState({
  166. files: {
  167. ...files,
  168. ...updatedFiles
  169. }
  170. })
  171. this.uppy.emit('transloadit:assembly-created', status, fileIDs)
  172. this._connectAssembly(assembly)
  173. this.uppy.log(`[Transloadit] Created Assembly ${status.assembly_id}`)
  174. return assembly
  175. }).catch((err) => {
  176. err.message = `${this.i18n('creatingAssemblyFailed')}: ${err.message}`
  177. // Reject the promise.
  178. throw err
  179. })
  180. }
  181. _shouldWaitAfterUpload () {
  182. return this.opts.waitForEncoding || this.opts.waitForMetadata
  183. }
  184. /**
  185. * Used when `importFromUploadURLs` is enabled: reserves all files in
  186. * the Assembly.
  187. */
  188. _reserveFiles (assembly, fileIDs) {
  189. return Promise.all(fileIDs.map((fileID) => {
  190. const file = this.uppy.getFile(fileID)
  191. return this.client.reserveFile(assembly, file)
  192. }))
  193. }
  194. /**
  195. * Used when `importFromUploadURLs` is enabled: adds files to the Assembly
  196. * once they have been fully uploaded.
  197. */
  198. _onFileUploadURLAvailable (file) {
  199. if (!file || !file.transloadit || !file.transloadit.assembly) {
  200. return
  201. }
  202. const { assemblies } = this.getPluginState()
  203. const assembly = assemblies[file.transloadit.assembly]
  204. this.client.addFile(assembly, file).catch((err) => {
  205. this.uppy.log(err)
  206. this.uppy.emit('transloadit:import-error', assembly, file.id, err)
  207. })
  208. }
  209. _findFile (uploadedFile) {
  210. const files = this.uppy.getFiles()
  211. for (let i = 0; i < files.length; i++) {
  212. const file = files[i]
  213. // Completed file upload.
  214. if (file.uploadURL === uploadedFile.tus_upload_url) {
  215. return file
  216. }
  217. // In-progress file upload.
  218. if (file.tus && file.tus.uploadUrl === uploadedFile.tus_upload_url) {
  219. return file
  220. }
  221. if (!uploadedFile.is_tus_file) {
  222. // Fingers-crossed check for non-tus uploads, eg imported from S3.
  223. if (file.name === uploadedFile.name && file.size === uploadedFile.size) {
  224. return file
  225. }
  226. }
  227. }
  228. }
  229. _onFileUploadComplete (assemblyId, uploadedFile) {
  230. const state = this.getPluginState()
  231. const file = this._findFile(uploadedFile)
  232. if (!file) {
  233. this.uppy.log('[Transloadit] Couldn’t file the file, it was likely removed in the process')
  234. return
  235. }
  236. this.setPluginState({
  237. files: Object.assign({}, state.files, {
  238. [uploadedFile.id]: {
  239. assembly: assemblyId,
  240. id: file.id,
  241. uploadedFile
  242. }
  243. })
  244. })
  245. this.uppy.emit('transloadit:upload', uploadedFile, this.getAssembly(assemblyId))
  246. }
  247. /**
  248. * Callback when a new Assembly result comes in.
  249. *
  250. * @param {string} assemblyId
  251. * @param {string} stepName
  252. * @param {Object} result
  253. */
  254. _onResult (assemblyId, stepName, result) {
  255. const state = this.getPluginState()
  256. const file = state.files[result.original_id]
  257. // The `file` may not exist if an import robot was used instead of a file upload.
  258. result.localId = file ? file.id : null
  259. const entry = {
  260. result,
  261. stepName,
  262. id: result.id,
  263. assembly: assemblyId
  264. }
  265. this.setPluginState({
  266. results: [...state.results, entry]
  267. })
  268. this.uppy.emit('transloadit:result', stepName, result, this.getAssembly(assemblyId))
  269. }
  270. /**
  271. * When an Assembly has finished processing, get the final state
  272. * and emit it.
  273. *
  274. * @param {Object} status
  275. */
  276. _onAssemblyFinished (status) {
  277. const url = status.assembly_ssl_url
  278. this.client.getAssemblyStatus(url).then((finalStatus) => {
  279. const state = this.getPluginState()
  280. this.setPluginState({
  281. assemblies: Object.assign({}, state.assemblies, {
  282. [finalStatus.assembly_id]: finalStatus
  283. })
  284. })
  285. this.uppy.emit('transloadit:complete', finalStatus)
  286. })
  287. }
  288. /**
  289. * Custom state serialization for the Golden Retriever plugin.
  290. * It will pass this back to the `_onRestored` function.
  291. *
  292. * @param {function} setData
  293. */
  294. _getPersistentData (setData) {
  295. const state = this.getPluginState()
  296. const assemblies = state.assemblies
  297. const uploadsAssemblies = state.uploadsAssemblies
  298. setData({
  299. [this.id]: {
  300. assemblies,
  301. uploadsAssemblies
  302. }
  303. })
  304. }
  305. _onRestored (pluginData) {
  306. const savedState = pluginData && pluginData[this.id] ? pluginData[this.id] : {}
  307. const previousAssemblies = savedState.assemblies || {}
  308. const uploadsAssemblies = savedState.uploadsAssemblies || {}
  309. if (Object.keys(uploadsAssemblies).length === 0) {
  310. // Nothing to restore.
  311. return
  312. }
  313. // Convert loaded Assembly statuses to a Transloadit plugin state object.
  314. const restoreState = (assemblies) => {
  315. const files = {}
  316. const results = []
  317. Object.keys(assemblies).forEach((id) => {
  318. const status = assemblies[id]
  319. status.uploads.forEach((uploadedFile) => {
  320. const file = this._findFile(uploadedFile)
  321. files[uploadedFile.id] = {
  322. id: file.id,
  323. assembly: id,
  324. uploadedFile
  325. }
  326. })
  327. const state = this.getPluginState()
  328. Object.keys(status.results).forEach((stepName) => {
  329. status.results[stepName].forEach((result) => {
  330. const file = state.files[result.original_id]
  331. result.localId = file ? file.id : null
  332. results.push({
  333. id: result.id,
  334. result,
  335. stepName,
  336. assembly: id
  337. })
  338. })
  339. })
  340. })
  341. this.setPluginState({
  342. assemblies,
  343. files,
  344. results,
  345. uploadsAssemblies
  346. })
  347. }
  348. // Set up the Assembly instances for existing Assemblies.
  349. const restoreAssemblies = () => {
  350. const { assemblies } = this.getPluginState()
  351. Object.keys(assemblies).forEach((id) => {
  352. const assembly = new Assembly(assemblies[id])
  353. this._connectAssembly(assembly)
  354. })
  355. }
  356. // Force-update all Assemblies to check for missed events.
  357. const updateAssemblies = () => {
  358. const { assemblies } = this.getPluginState()
  359. return Promise.all(
  360. Object.keys(assemblies).map((id) => {
  361. return this.activeAssemblies[id].update()
  362. })
  363. )
  364. }
  365. // Restore all Assembly state.
  366. this.restored = Promise.resolve().then(() => {
  367. restoreState(previousAssemblies)
  368. restoreAssemblies()
  369. return updateAssemblies()
  370. })
  371. this.restored.then(() => {
  372. this.restored = null
  373. })
  374. }
  375. _connectAssembly (assembly) {
  376. const { status } = assembly
  377. const id = status.assembly_id
  378. this.activeAssemblies[id] = assembly
  379. // Sync local `assemblies` state
  380. assembly.on('status', (newStatus) => {
  381. const { assemblies } = this.getPluginState()
  382. this.setPluginState({
  383. assemblies: {
  384. ...assemblies,
  385. [id]: newStatus
  386. }
  387. })
  388. })
  389. assembly.on('upload', (file) => {
  390. this._onFileUploadComplete(id, file)
  391. })
  392. assembly.on('error', (error) => {
  393. this.uppy.emit('transloadit:assembly-error', assembly.status, error)
  394. })
  395. assembly.on('executing', () => {
  396. this.uppy.emit('transloadit:assembly-executing', assembly.status)
  397. })
  398. if (this.opts.waitForEncoding) {
  399. assembly.on('result', (stepName, result) => {
  400. this._onResult(id, stepName, result)
  401. })
  402. }
  403. if (this.opts.waitForEncoding) {
  404. assembly.on('finished', () => {
  405. this._onAssemblyFinished(assembly.status)
  406. })
  407. } else if (this.opts.waitForMetadata) {
  408. assembly.on('metadata', () => {
  409. this._onAssemblyFinished(assembly.status)
  410. })
  411. }
  412. // No need to connect to the socket if the Assembly has completed by now.
  413. if (assembly.ok === 'ASSEMBLY_COMPLETE') {
  414. return assembly
  415. }
  416. // TODO Do we still need this for anything…?
  417. // eslint-disable-next-line no-unused-vars
  418. const connected = new Promise((resolve, reject) => {
  419. assembly.once('connect', resolve)
  420. assembly.once('status', resolve)
  421. assembly.once('error', reject)
  422. }).then(() => {
  423. this.uppy.log('[Transloadit] Socket is ready')
  424. })
  425. assembly.connect()
  426. return assembly
  427. }
  428. _prepareUpload (fileIDs, uploadID) {
  429. // Only use files without errors
  430. fileIDs = fileIDs.filter((file) => !file.error)
  431. fileIDs.forEach((fileID) => {
  432. const file = this.uppy.getFile(fileID)
  433. this.uppy.emit('preprocess-progress', file, {
  434. mode: 'indeterminate',
  435. message: this.i18n('creatingAssembly')
  436. })
  437. })
  438. const createAssembly = ({ fileIDs, options }) => {
  439. return this._createAssembly(fileIDs, uploadID, options).then((assembly) => {
  440. if (this.opts.importFromUploadURLs) {
  441. return this._reserveFiles(assembly, fileIDs)
  442. }
  443. }).then(() => {
  444. fileIDs.forEach((fileID) => {
  445. const file = this.uppy.getFile(fileID)
  446. this.uppy.emit('preprocess-complete', file)
  447. })
  448. }).catch((err) => {
  449. fileIDs.forEach((fileID) => {
  450. const file = this.uppy.getFile(fileID)
  451. // Clear preprocessing state when the Assembly could not be created,
  452. // otherwise the UI gets confused about the lingering progress keys
  453. this.uppy.emit('preprocess-complete', file)
  454. this.uppy.emit('upload-error', file, err)
  455. })
  456. throw err
  457. })
  458. }
  459. const { uploadsAssemblies } = this.getPluginState()
  460. this.setPluginState({
  461. uploadsAssemblies: {
  462. ...uploadsAssemblies,
  463. [uploadID]: []
  464. }
  465. })
  466. const files = fileIDs.map((id) => this.uppy.getFile(id))
  467. const assemblyOptions = new AssemblyOptions(files, this.opts)
  468. return assemblyOptions.build().then(
  469. (assemblies) => Promise.all(
  470. assemblies.map(createAssembly)
  471. ),
  472. // If something went wrong before any Assemblies could be created,
  473. // clear all processing state.
  474. (err) => {
  475. fileIDs.forEach((fileID) => {
  476. const file = this.uppy.getFile(fileID)
  477. this.uppy.emit('preprocess-complete', file)
  478. this.uppy.emit('upload-error', file, err)
  479. })
  480. throw err
  481. }
  482. )
  483. }
  484. _afterUpload (fileIDs, uploadID) {
  485. // Only use files without errors
  486. fileIDs = fileIDs.filter((file) => !file.error)
  487. const state = this.getPluginState()
  488. // If we're still restoring state, wait for that to be done.
  489. if (this.restored) {
  490. return this.restored.then(() => {
  491. return this._afterUpload(fileIDs, uploadID)
  492. })
  493. }
  494. const assemblyIDs = state.uploadsAssemblies[uploadID]
  495. // If we don't have to wait for encoding metadata or results, we can close
  496. // the socket immediately and finish the upload.
  497. if (!this._shouldWaitAfterUpload()) {
  498. assemblyIDs.forEach((assemblyID) => {
  499. const assembly = this.activeAssemblies[assemblyID]
  500. assembly.close()
  501. delete this.activeAssemblies[assemblyID]
  502. })
  503. const assemblies = assemblyIDs.map((id) => this.getAssembly(id))
  504. this.uppy.addResultData(uploadID, { transloadit: assemblies })
  505. return Promise.resolve()
  506. }
  507. // If no Assemblies were created for this upload, we also do not have to wait.
  508. // There's also no sockets or anything to close, so just return immediately.
  509. if (assemblyIDs.length === 0) {
  510. this.uppy.addResultData(uploadID, { transloadit: [] })
  511. return Promise.resolve()
  512. }
  513. // AssemblyWatcher tracks completion state of all Assemblies in this upload.
  514. const watcher = new AssemblyWatcher(this.uppy, assemblyIDs)
  515. fileIDs.forEach((fileID) => {
  516. const file = this.uppy.getFile(fileID)
  517. this.uppy.emit('postprocess-progress', file, {
  518. mode: 'indeterminate',
  519. message: this.i18n('encoding')
  520. })
  521. })
  522. watcher.on('assembly-complete', (id) => {
  523. const files = this.getAssemblyFiles(id)
  524. files.forEach((file) => {
  525. this.uppy.emit('postprocess-complete', file)
  526. })
  527. })
  528. watcher.on('assembly-error', (id, error) => {
  529. // Clear postprocessing state for all our files.
  530. const files = this.getAssemblyFiles(id)
  531. files.forEach((file) => {
  532. // TODO Maybe make a postprocess-error event here?
  533. this.uppy.emit('upload-error', file, error)
  534. this.uppy.emit('postprocess-complete', file)
  535. })
  536. })
  537. return watcher.promise.then(() => {
  538. const assemblies = assemblyIDs.map((id) => this.getAssembly(id))
  539. // Remove the Assembly ID list for this upload,
  540. // it's no longer going to be used anywhere.
  541. const state = this.getPluginState()
  542. const uploadsAssemblies = { ...state.uploadsAssemblies }
  543. delete uploadsAssemblies[uploadID]
  544. this.setPluginState({ uploadsAssemblies })
  545. this.uppy.addResultData(uploadID, {
  546. transloadit: assemblies
  547. })
  548. })
  549. }
  550. _handleError (err, uploadID) {
  551. this.uppy.log(`[Transloadit] _handleError in upload ${uploadID}`)
  552. this.uppy.log(err)
  553. const state = this.getPluginState()
  554. const assemblyIDs = state.uploadsAssemblies[uploadID]
  555. assemblyIDs.forEach((assemblyID) => {
  556. if (this.activeAssemblies[assemblyID]) {
  557. this.activeAssemblies[assemblyID].close()
  558. }
  559. })
  560. }
  561. install () {
  562. this.uppy.addPreProcessor(this._prepareUpload)
  563. this.uppy.addPostProcessor(this._afterUpload)
  564. // We may need to close socket.io connections on error.
  565. this.uppy.on('error', this._handleError)
  566. if (this.opts.importFromUploadURLs) {
  567. // No uploader needed when importing; instead we take the upload URL from an existing uploader.
  568. this.uppy.on('upload-success', this._onFileUploadURLAvailable)
  569. } else {
  570. this.uppy.use(Tus, {
  571. // Disable tus-js-client fingerprinting, otherwise uploading the same file at different times
  572. // will upload to the same Assembly.
  573. resume: false,
  574. // Disable Companion's retry optimisation; we need to change the endpoint on retry
  575. // so it can't just reuse the same tus.Upload instance server-side.
  576. useFastRemoteRetry: false,
  577. // Only send Assembly metadata to the tus endpoint.
  578. metaFields: ['assembly_url', 'filename', 'fieldname']
  579. })
  580. }
  581. this.uppy.on('restore:get-data', this._getPersistentData)
  582. this.uppy.on('restored', this._onRestored)
  583. this.setPluginState({
  584. // Contains Assembly status objects, indexed by their ID.
  585. assemblies: {},
  586. // Contains arrays of Assembly IDs, indexed by the upload ID that they belong to.
  587. uploadsAssemblies: {},
  588. // Contains file data from Transloadit, indexed by their Transloadit-assigned ID.
  589. files: {},
  590. // Contains result data from Transloadit.
  591. results: []
  592. })
  593. }
  594. uninstall () {
  595. this.uppy.removePreProcessor(this._prepareUpload)
  596. this.uppy.removePostProcessor(this._afterUpload)
  597. this.uppy.off('error', this._handleError)
  598. if (this.opts.importFromUploadURLs) {
  599. this.uppy.off('upload-success', this._onFileUploadURLAvailable)
  600. }
  601. }
  602. getAssembly (id) {
  603. const state = this.getPluginState()
  604. return state.assemblies[id]
  605. }
  606. getAssemblyFiles (assemblyID) {
  607. return this.uppy.getFiles().filter((file) => {
  608. return file && file.transloadit && file.transloadit.assembly === assemblyID
  609. })
  610. }
  611. }
  612. module.exports.COMPANION = COMPANION
  613. module.exports.UPPY_SERVER = COMPANION