mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 18:27:22 +00:00
Merge branch 'features/media-lib' of github.com:strapi/strapi into features/media-lib-ctb-option
This commit is contained in:
commit
82cde9a194
@ -86,6 +86,7 @@ const formatAttribute = (key, attribute, { model }) => {
|
|||||||
type: 'media',
|
type: 'media',
|
||||||
multiple: attribute.collection ? true : false,
|
multiple: attribute.collection ? true : false,
|
||||||
required: attribute.required ? true : false,
|
required: attribute.required ? true : false,
|
||||||
|
allowedTypes: attribute.allowedTypes,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
@ -291,7 +291,7 @@ describe('Type validators', () => {
|
|||||||
expect(validator.isValidSync(attributes.img)).toBe(true);
|
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 = {
|
const attributes = {
|
||||||
img: {
|
img: {
|
||||||
type: 'media',
|
type: 'media',
|
||||||
|
@ -49,20 +49,10 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
|
|||||||
multiple: yup.boolean(),
|
multiple: yup.boolean(),
|
||||||
required: validators.required,
|
required: validators.required,
|
||||||
unique: validators.unique,
|
unique: validators.unique,
|
||||||
allowedTypes: yup.lazy(value => {
|
allowedTypes: yup
|
||||||
if (Array.isArray(value) && value.includes('all')) {
|
|
||||||
return yup
|
|
||||||
.array()
|
|
||||||
.of(yup.string().oneOf(['all']))
|
|
||||||
.min(1)
|
|
||||||
.max(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return yup
|
|
||||||
.array()
|
.array()
|
||||||
.of(yup.string().oneOf(['images', 'videos', 'files']))
|
.of(yup.string().oneOf(['images', 'videos', 'files']))
|
||||||
.min(1);
|
.min(1),
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,7 @@ const hasComponent = model => {
|
|||||||
const isConfigurable = attribute => _.get(attribute, 'configurable', true);
|
const isConfigurable = attribute => _.get(attribute, 'configurable', true);
|
||||||
|
|
||||||
const isRelation = attribute =>
|
const isRelation = attribute =>
|
||||||
_.has(attribute, 'target') ||
|
_.has(attribute, 'target') || _.has(attribute, 'model') || _.has(attribute, 'collection');
|
||||||
_.has(attribute, 'model') ||
|
|
||||||
_.has(attribute, 'collection');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a component's attributes
|
* Formats a component's attributes
|
||||||
@ -57,9 +55,7 @@ const formatAttribute = (key, attribute, { model }) => {
|
|||||||
if (_.has(attribute, 'type')) return attribute;
|
if (_.has(attribute, 'type')) return attribute;
|
||||||
|
|
||||||
// format relations
|
// format relations
|
||||||
const relation = (model.associations || []).find(
|
const relation = (model.associations || []).find(assoc => assoc.alias === key);
|
||||||
assoc => assoc.alias === key
|
|
||||||
);
|
|
||||||
const { plugin, configurable } = attribute;
|
const { plugin, configurable } = attribute;
|
||||||
let targetEntity = attribute.model || attribute.collection;
|
let targetEntity = attribute.model || attribute.collection;
|
||||||
|
|
||||||
@ -69,6 +65,7 @@ const formatAttribute = (key, attribute, { model }) => {
|
|||||||
multiple: attribute.collection ? true : false,
|
multiple: attribute.collection ? true : false,
|
||||||
required: attribute.required ? true : false,
|
required: attribute.required ? true : false,
|
||||||
configurable: configurable === false ? false : undefined,
|
configurable: configurable === false ? false : undefined,
|
||||||
|
allowedTypes: attribute.allowedTypes,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
@ -93,14 +93,6 @@
|
|||||||
"name": "File"
|
"name": "File"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/media-types",
|
|
||||||
"handler": "media-types.getMediaTypes",
|
|
||||||
"config": {
|
|
||||||
"policies": []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -89,44 +89,6 @@ module.exports = {
|
|||||||
ctx.body = { data };
|
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) {
|
async find(ctx) {
|
||||||
const data = await strapi.plugins['upload'].services.upload.fetchAll(ctx.query);
|
const data = await strapi.plugins['upload'].services.upload.fetchAll(ctx.query);
|
||||||
|
|
||||||
|
@ -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 };
|
|
||||||
},
|
|
||||||
};
|
|
@ -38,10 +38,6 @@
|
|||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"sha256": {
|
|
||||||
"type": "string",
|
|
||||||
"configurable": false
|
|
||||||
},
|
|
||||||
"ext": {
|
"ext": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"configurable": false
|
"configurable": false
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
"immutable": "^3.8.2",
|
"immutable": "^3.8.2",
|
||||||
"invariant": "^2.2.1",
|
"invariant": "^2.2.1",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
"mime-db": "1.43.0",
|
|
||||||
"mime-type": "3.0.7",
|
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
"react-copy-to-clipboard": "^5.0.1",
|
"react-copy-to-clipboard": "^5.0.1",
|
||||||
"react-dom": "^16.9.0",
|
"react-dom": "^16.9.0",
|
||||||
|
@ -32,7 +32,6 @@ module.exports = {
|
|||||||
name: usedName,
|
name: usedName,
|
||||||
alternativeText: fileInfo.alternativeText,
|
alternativeText: fileInfo.alternativeText,
|
||||||
caption: fileInfo.caption,
|
caption: fileInfo.caption,
|
||||||
// sha256: niceHash(buffer),
|
|
||||||
hash: generateFileName(usedName),
|
hash: generateFileName(usedName),
|
||||||
ext,
|
ext,
|
||||||
mime: type,
|
mime: type,
|
||||||
|
38
yarn.lock
38
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"
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1"
|
||||||
integrity sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=
|
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"
|
version "1.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||||
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
||||||
@ -9249,13 +9249,6 @@ inflight@^1.0.4:
|
|||||||
once "^1.3.0"
|
once "^1.3.0"
|
||||||
wrappy "1"
|
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:
|
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"
|
version "2.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
|
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"
|
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
|
||||||
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
|
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
|
||||||
|
|
||||||
media-typer@0.3.0, media-typer@^0.3.0:
|
media-typer@0.3.0:
|
||||||
version "0.3.0"
|
version "0.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
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"
|
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.43.0.tgz#0a12e0502650e473d735535050e7c8f4eb4fae58"
|
||||||
integrity sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==
|
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:
|
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"
|
version "2.1.26"
|
||||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.26.tgz#9c921fc09b7e149a65dfdc0da4d20997200b0a06"
|
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"
|
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
||||||
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
|
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:
|
pbkdf2@^3.0.3:
|
||||||
version "3.0.17"
|
version "3.0.17"
|
||||||
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6"
|
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"
|
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
||||||
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
|
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:
|
util-promisify@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/util-promisify/-/util-promisify-2.1.0.tgz#3c2236476c4d32c5ff3c47002add7c13b9a82a53"
|
resolved "https://registry.yarnpkg.com/util-promisify/-/util-promisify-2.1.0.tgz#3c2236476c4d32c5ff3c47002add7c13b9a82a53"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user