From 8fbabe4223749bcc723ebb8cd603460617508754 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 6 Oct 2021 14:25:01 +0200 Subject: [PATCH] @uppy/transloadit: pass fields to transloadit (#3228) * @uppy/transloadit: pass fields to transloadit Co-authored-by: Merlijn Vos Fixes: https://github.com/transloadit/uppy/issues/3189 * inline `normalizeAssemblyOptions` Co-authored-by: Merlijn Vos --- .../@uppy/transloadit/src/AssemblyOptions.js | 21 +++++++------------ test/endtoend/transloadit2/main.js | 20 +++++++----------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/packages/@uppy/transloadit/src/AssemblyOptions.js b/packages/@uppy/transloadit/src/AssemblyOptions.js index e7358bef8d..a9ae2803ee 100644 --- a/packages/@uppy/transloadit/src/AssemblyOptions.js +++ b/packages/@uppy/transloadit/src/AssemblyOptions.js @@ -24,19 +24,6 @@ function validateParams (params) { } } -/** - * Normalize Uppy-specific Assembly option features to a Transloadit- - * compatible object. - */ -function normalizeAssemblyOptions (file, assemblyOptions) { - // eslint-disable-next-line no-param-reassign - assemblyOptions.fields = Array.isArray(assemblyOptions.fields) - ? Object.fromEntries(assemblyOptions.fields.map((fieldName) => [fieldName, file.meta[fieldName]])) - : {} - - return assemblyOptions -} - /** * Combine Assemblies with the same options into a single Assembly for all the * relevant files. @@ -78,9 +65,15 @@ class AssemblyOptions { const options = this.opts const assemblyOptions = await options.getAssemblyOptions(file, options) + if (Array.isArray(assemblyOptions.fields)) { + assemblyOptions.fields = Object.fromEntries( + assemblyOptions.fields.map((fieldName) => [fieldName, file.meta[fieldName]]) + ) + } else if (assemblyOptions.fields == null) { + assemblyOptions.fields = {} + } validateParams(assemblyOptions.params) - normalizeAssemblyOptions(file, assemblyOptions) return { fileIDs: [file.id], diff --git a/test/endtoend/transloadit2/main.js b/test/endtoend/transloadit2/main.js index 48986ad68a..969058714e 100644 --- a/test/endtoend/transloadit2/main.js +++ b/test/endtoend/transloadit2/main.js @@ -33,24 +33,20 @@ function initUppyTransloadit (transloaditKey) { auth: { key: transloaditKey }, template_id: 'uppyTransloadit', }, + fields: { + message: 'test', + }, } }, waitForEncoding: true, }) - uppyTransloadit.on('transloadit:result', (stepName, result) => { + uppyTransloadit.on('transloadit:result', (_, __, assembly) => { // use transloadit encoding result here. - console.log('Result here ====>', stepName, result) - console.log('Cropped image url is here ====>', result.url) - - const img = new Image() - img.onload = function onload () { - const result = document.createElement('div') - result.setAttribute('id', 'uppy-result') - result.textContent = 'ok' - document.body.appendChild(result) - } - img.src = result.url + const result = document.createElement('div') + result.setAttribute('id', 'uppy-result') + result.textContent = assembly.fields.message === 'test' ? 'ok' : 'fail' + document.body.appendChild(result) }) }