From 2b5c332e09b810648f08cf7d7f42398f8ade127c Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 9 Mar 2020 11:05:18 +0100 Subject: [PATCH 1/5] Clean up Signed-off-by: Alexandre Bodin --- .../controllers/Upload.js | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/packages/strapi-plugin-upload/controllers/Upload.js b/packages/strapi-plugin-upload/controllers/Upload.js index d1af8c7c03..01f167c5f2 100644 --- a/packages/strapi-plugin-upload/controllers/Upload.js +++ b/packages/strapi-plugin-upload/controllers/Upload.js @@ -89,44 +89,6 @@ module.exports = { ctx.body = { data }; }, - async replaceFile(ctx) { - const { id } = ctx.params; - - const uploadService = strapi.plugins.upload.services.upload; - - // Retrieve provider configuration. - const { enabled } = strapi.plugins.upload.config; - - // Verify if the file upload is enable. - if (enabled === false) { - throw strapi.errors.badRequest(null, { - errors: [{ id: 'Upload.status.disabled', message: 'File upload is disabled' }], - }); - } - - const data = await strapi.plugins['upload'].services.upload.fetch({ id }); - - if (!data) { - return ctx.notFound('file.notFound'); - } - - const { fileInfo } = await validateUploadBody(uploadSchema, ctx.request.body); - - const { file = {} } = ctx.request.files || {}; - - if (_.isUndefined(file)) { - throw strapi.errors.badRequest(null, { - errors: [{ id: 'Upload.status.empty', message: 'File is missing' }], - }); - } - - const enhancedFile = uploadService.enhanceFile(file, fileInfo); - - const updatedFile = await uploadService.update(id, enhancedFile); - - ctx.body = updatedFile; - }, - async find(ctx) { const data = await strapi.plugins['upload'].services.upload.fetchAll(ctx.query); From 02d042769f49cb759f1d43e4eedd08a51d71c298 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 10 Mar 2020 17:26:15 +0100 Subject: [PATCH 2/5] Remove file sha that was not standard Signed-off-by: Alexandre Bodin --- packages/strapi-plugin-upload/models/File.settings.json | 4 ---- packages/strapi-plugin-upload/services/Upload.js | 1 - 2 files changed, 5 deletions(-) diff --git a/packages/strapi-plugin-upload/models/File.settings.json b/packages/strapi-plugin-upload/models/File.settings.json index 302dc297c7..f9381212e6 100644 --- a/packages/strapi-plugin-upload/models/File.settings.json +++ b/packages/strapi-plugin-upload/models/File.settings.json @@ -38,10 +38,6 @@ "configurable": false, "required": true }, - "sha256": { - "type": "string", - "configurable": false - }, "ext": { "type": "string", "configurable": false diff --git a/packages/strapi-plugin-upload/services/Upload.js b/packages/strapi-plugin-upload/services/Upload.js index b292169d36..d34805abb7 100644 --- a/packages/strapi-plugin-upload/services/Upload.js +++ b/packages/strapi-plugin-upload/services/Upload.js @@ -32,7 +32,6 @@ module.exports = { name: usedName, alternativeText: fileInfo.alternativeText, caption: fileInfo.caption, - // sha256: niceHash(buffer), hash: generateFileName(usedName), ext, mime: type, From 32c021db3751e0a56cdf6a6cafa1028ecb538d11 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 12 Mar 2020 09:28:01 +0100 Subject: [PATCH 3/5] Remove allowedType all option Signed-off-by: Alexandre Bodin --- .../validation/__tests__/types.test.js | 2 +- .../controllers/validation/types.js | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/types.test.js b/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/types.test.js index 5a48d4171c..8543b12911 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/types.test.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/types.test.js @@ -291,7 +291,7 @@ describe('Type validators', () => { expect(validator.isValidSync(attributes.img)).toBe(true); }); - test.each(['all', 'images', 'files', 'videos'])('%s is an allowed types', type => { + test.each(['images', 'files', 'videos'])('%s is an allowed types', type => { const attributes = { img: { type: 'media', diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/types.js b/packages/strapi-plugin-content-type-builder/controllers/validation/types.js index e34c8f5572..e6dcd44d87 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/types.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/types.js @@ -49,20 +49,10 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => { multiple: yup.boolean(), required: validators.required, unique: validators.unique, - allowedTypes: yup.lazy(value => { - if (Array.isArray(value) && value.includes('all')) { - return yup - .array() - .of(yup.string().oneOf(['all'])) - .min(1) - .max(1); - } - - return yup - .array() - .of(yup.string().oneOf(['images', 'videos', 'files'])) - .min(1); - }), + allowedTypes: yup + .array() + .of(yup.string().oneOf(['images', 'videos', 'files'])) + .min(1), }; } From c4bf0cdb67adec986f03e5039ce4400b80df20ef Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 12 Mar 2020 09:44:04 +0100 Subject: [PATCH 4/5] Add allowedTypes in media type meta Signed-off-by: Alexandre Bodin --- .../services/ContentTypes.js | 1 + .../utils/attributes.js | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/strapi-plugin-content-manager/services/ContentTypes.js b/packages/strapi-plugin-content-manager/services/ContentTypes.js index 5caee17eef..c00286fdd4 100644 --- a/packages/strapi-plugin-content-manager/services/ContentTypes.js +++ b/packages/strapi-plugin-content-manager/services/ContentTypes.js @@ -86,6 +86,7 @@ const formatAttribute = (key, attribute, { model }) => { type: 'media', multiple: attribute.collection ? true : false, required: attribute.required ? true : false, + allowedTypes: attribute.allowedTypes, }; } else { return { diff --git a/packages/strapi-plugin-content-type-builder/utils/attributes.js b/packages/strapi-plugin-content-type-builder/utils/attributes.js index d28a6a4a32..9b183487eb 100644 --- a/packages/strapi-plugin-content-type-builder/utils/attributes.js +++ b/packages/strapi-plugin-content-type-builder/utils/attributes.js @@ -29,9 +29,7 @@ const hasComponent = model => { const isConfigurable = attribute => _.get(attribute, 'configurable', true); const isRelation = attribute => - _.has(attribute, 'target') || - _.has(attribute, 'model') || - _.has(attribute, 'collection'); + _.has(attribute, 'target') || _.has(attribute, 'model') || _.has(attribute, 'collection'); /** * Formats a component's attributes @@ -57,9 +55,7 @@ const formatAttribute = (key, attribute, { model }) => { if (_.has(attribute, 'type')) return attribute; // format relations - const relation = (model.associations || []).find( - assoc => assoc.alias === key - ); + const relation = (model.associations || []).find(assoc => assoc.alias === key); const { plugin, configurable } = attribute; let targetEntity = attribute.model || attribute.collection; @@ -69,6 +65,7 @@ const formatAttribute = (key, attribute, { model }) => { multiple: attribute.collection ? true : false, required: attribute.required ? true : false, configurable: configurable === false ? false : undefined, + allowedTypes: attribute.allowedTypes, }; } else { return { From eb76a07daf1abd89ab2e1dd4f5c33a4d94040134 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 12 Mar 2020 14:25:50 +0100 Subject: [PATCH 5/5] Update media-lib features according to spec changes Signed-off-by: Alexandre Bodin --- .../strapi-plugin-upload/config/routes.json | 8 ---- .../controllers/media-types.js | 18 --------- packages/strapi-plugin-upload/package.json | 2 - yarn.lock | 38 +------------------ 4 files changed, 2 insertions(+), 64 deletions(-) delete mode 100644 packages/strapi-plugin-upload/controllers/media-types.js diff --git a/packages/strapi-plugin-upload/config/routes.json b/packages/strapi-plugin-upload/config/routes.json index 4cd62678bd..41641926cd 100644 --- a/packages/strapi-plugin-upload/config/routes.json +++ b/packages/strapi-plugin-upload/config/routes.json @@ -93,14 +93,6 @@ "name": "File" } } - }, - { - "method": "GET", - "path": "/media-types", - "handler": "media-types.getMediaTypes", - "config": { - "policies": [] - } } ] } diff --git a/packages/strapi-plugin-upload/controllers/media-types.js b/packages/strapi-plugin-upload/controllers/media-types.js deleted file mode 100644 index 619c818d37..0000000000 --- a/packages/strapi-plugin-upload/controllers/media-types.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const db = require('mime-db'); -const mime = require('mime-type')(db); - -module.exports = { - async getMediaTypes(ctx) { - const data = { - types: ['images', 'videos', 'files'], - mimeTypes: { - images: mime.glob('image/*'), - videos: mime.glob('video/*'), - }, - }; - - ctx.body = { data }; - }, -}; diff --git a/packages/strapi-plugin-upload/package.json b/packages/strapi-plugin-upload/package.json index e7ea59ff7b..255339cc8d 100644 --- a/packages/strapi-plugin-upload/package.json +++ b/packages/strapi-plugin-upload/package.json @@ -16,8 +16,6 @@ "immutable": "^3.8.2", "invariant": "^2.2.1", "lodash": "^4.17.11", - "mime-db": "1.43.0", - "mime-type": "3.0.7", "react": "^16.9.0", "react-copy-to-clipboard": "^5.0.1", "react-dom": "^16.9.0", diff --git a/yarn.lock b/yarn.lock index 45677635bb..91b7511151 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6959,7 +6959,7 @@ escape-string-regexp@1.0.2: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1" integrity sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE= -escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.3, escape-string-regexp@^1.0.5: +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= @@ -9249,13 +9249,6 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits-ex@^1.1.2: - version "1.2.3" - resolved "https://registry.yarnpkg.com/inherits-ex/-/inherits-ex-1.2.3.tgz#ba0da6258e9b855f98429e82ea97c4cc0e4e459d" - integrity sha512-DCZqD7BpjXqaha8IKcoAE3ZZr6Hi12ropV1h+3pBnirE14mNRwLuYySvYxUSBemTQ40SjAxPL8BTk2Xw/3IF9w== - dependencies: - xtend "^4.0.0" - inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" @@ -11661,7 +11654,7 @@ mdn-data@2.0.4: resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b" integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA== -media-typer@0.3.0, media-typer@^0.3.0: +media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= @@ -11817,16 +11810,6 @@ mime-db@1.43.0, "mime-db@>= 1.43.0 < 2": resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.43.0.tgz#0a12e0502650e473d735535050e7c8f4eb4fae58" integrity sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ== -mime-type@3.0.7: - version "3.0.7" - resolved "https://registry.yarnpkg.com/mime-type/-/mime-type-3.0.7.tgz#15c21e4833edd1ac5ddf04fffb49164d17bef57b" - integrity sha512-NyWtbAKERuLQIv+1jjEdWGrWepVlubZEW0fTs4K9T6UWW45iMBpgrwpP5GIl8/5trHLviOcQfA6zEth3T8WhNA== - dependencies: - media-typer "^0.3.0" - minimatch "^3.0.4" - path.js "^1.0.7" - util-ex "^0.3.15" - mime-types@^2.0.8, mime-types@^2.1.12, mime-types@^2.1.18, mime-types@~2.1.17, mime-types@~2.1.19, mime-types@~2.1.24: version "2.1.26" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.26.tgz#9c921fc09b7e149a65dfdc0da4d20997200b0a06" @@ -13383,15 +13366,6 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -path.js@^1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/path.js/-/path.js-1.0.7.tgz#7d136b607de19bfd98ba068874926287e6534939" - integrity sha1-fRNrYH3hm/2YugaIdJJih+ZTSTk= - dependencies: - escape-string-regexp "^1.0.3" - inherits-ex "^1.1.2" - util-ex "^0.3.10" - pbkdf2@^3.0.3: version "3.0.17" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6" @@ -17909,14 +17883,6 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= -util-ex@^0.3.10, util-ex@^0.3.15: - version "0.3.15" - resolved "https://registry.yarnpkg.com/util-ex/-/util-ex-0.3.15.tgz#f9261cda13c4327d0740cbe67be1227ded8b0058" - integrity sha1-+SYc2hPEMn0HQMvme+Eife2LAFg= - dependencies: - inherits-ex "^1.1.2" - xtend "^4.0.0" - util-promisify@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/util-promisify/-/util-promisify-2.1.0.tgz#3c2236476c4d32c5ff3c47002add7c13b9a82a53"