From 98cca8f98d05ceaeccde550e8afd6492d5ba656e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 11:51:59 +0100 Subject: [PATCH 1/4] transloadit: Add global metadata as `fields` --- src/plugins/Transloadit/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 5cbf4a92f3..7596f29c68 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -3,14 +3,6 @@ const Plugin = require('../../core/Plugin') const Client = require('./Client') const StatusSocket = require('./Socket') -function defaultGetAssemblyOptions (file, options) { - return { - params: options.params, - signature: options.signature, - fields: options.fields - } -} - /** * Upload files to Transloadit using Tus. */ @@ -37,7 +29,13 @@ module.exports = class Transloadit extends Plugin { signature: null, params: null, fields: {}, - getAssemblyOptions: defaultGetAssemblyOptions, + getAssemblyOptions: (file, options) => ({ + params: options.params, + signature: options.signature, + // Include global metadata as fields by default. + // Works great together with the Form plugin :) + fields: Object.assign({}, this.uppy.getState().meta, options.fields) + }), locale: defaultLocale } From efd03d96bb5529e88748bfd41bb00c3ce87c0ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 13:02:45 +0100 Subject: [PATCH 2/4] Revert "transloadit: Add global metadata as `fields`" This reverts commit 98cca8f98d05ceaeccde550e8afd6492d5ba656e. --- src/plugins/Transloadit/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 7596f29c68..5cbf4a92f3 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -3,6 +3,14 @@ const Plugin = require('../../core/Plugin') const Client = require('./Client') const StatusSocket = require('./Socket') +function defaultGetAssemblyOptions (file, options) { + return { + params: options.params, + signature: options.signature, + fields: options.fields + } +} + /** * Upload files to Transloadit using Tus. */ @@ -29,13 +37,7 @@ module.exports = class Transloadit extends Plugin { signature: null, params: null, fields: {}, - getAssemblyOptions: (file, options) => ({ - params: options.params, - signature: options.signature, - // Include global metadata as fields by default. - // Works great together with the Form plugin :) - fields: Object.assign({}, this.uppy.getState().meta, options.fields) - }), + getAssemblyOptions: defaultGetAssemblyOptions, locale: defaultLocale } From 955f63e30dd299a6cc0d8bf4a323560c210fed1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 13:03:09 +0100 Subject: [PATCH 3/4] transloadit: Pass `fields: true` to add global metadata as fields. --- src/plugins/Transloadit/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 5cbf4a92f3..54a4f101d6 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -87,11 +87,25 @@ module.exports = class Transloadit extends Plugin { getAssemblyOptions (fileIDs) { const options = this.opts + + const normalizeAssemblyOptions = (assemblyOptions) => { + const globalMeta = this.uppy.getState().meta + // Include global metadata as fields. Works great together with the Form plugin :) + if (assemblyOptions.fields === true) { + assemblyOptions.fields = Object.assign({}, globalMeta) + } + if (!assemblyOptions.fields) { + assemblyOptions.fields = {} + } + return assemblyOptions + } + return Promise.all( fileIDs.map((fileID) => { const file = this.uppy.getFile(fileID) const promise = Promise.resolve() .then(() => options.getAssemblyOptions(file, options)) + .then(normalizeAssemblyOptions) return promise.then((assemblyOptions) => { this.validateParams(assemblyOptions.params) From 43a1aae5f4bf074529eeefa05746a94d2458b890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 8 Feb 2018 21:44:41 +0100 Subject: [PATCH 4/4] transloadit: Accept array of meta field names in `fields` parameter. --- src/plugins/Transloadit/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 54a4f101d6..62ad9e83bc 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -88,11 +88,13 @@ module.exports = class Transloadit extends Plugin { getAssemblyOptions (fileIDs) { const options = this.opts - const normalizeAssemblyOptions = (assemblyOptions) => { - const globalMeta = this.uppy.getState().meta - // Include global metadata as fields. Works great together with the Form plugin :) - if (assemblyOptions.fields === true) { - assemblyOptions.fields = Object.assign({}, globalMeta) + const normalizeAssemblyOptions = (file, assemblyOptions) => { + if (Array.isArray(assemblyOptions.fields)) { + const fieldNames = assemblyOptions.fields + assemblyOptions.fields = {} + fieldNames.forEach((fieldName) => { + assemblyOptions.fields[fieldName] = file.meta[fieldName] + }) } if (!assemblyOptions.fields) { assemblyOptions.fields = {} @@ -105,7 +107,7 @@ module.exports = class Transloadit extends Plugin { const file = this.uppy.getFile(fileID) const promise = Promise.resolve() .then(() => options.getAssemblyOptions(file, options)) - .then(normalizeAssemblyOptions) + .then((assemblyOptions) => normalizeAssemblyOptions(file, assemblyOptions)) return promise.then((assemblyOptions) => { this.validateParams(assemblyOptions.params)