mirror of
https://github.com/strapi/strapi.git
synced 2025-11-23 21:53:05 +00:00
Use mime-types to set extension
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
b5b140bb32
commit
904b2b438b
@ -31,6 +31,10 @@ module.exports = strapi => ({
|
|||||||
try {
|
try {
|
||||||
const url = new URL(ctx.query.url);
|
const url = new URL(ctx.query.url);
|
||||||
|
|
||||||
|
if (!['http:', 'https:'].includes(url.protocol)) {
|
||||||
|
throw new Error('Invalid URL');
|
||||||
|
}
|
||||||
|
|
||||||
if (!isValidDomain(url.hostname)) {
|
if (!isValidDomain(url.hostname)) {
|
||||||
throw new Error('Invalid URL');
|
throw new Error('Invalid URL');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
"koa-range": "0.3.0",
|
"koa-range": "0.3.0",
|
||||||
"koa-static": "^5.0.0",
|
"koa-static": "^5.0.0",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
|
"mime-types": "2.1.26",
|
||||||
"node-fetch": "2.6.0",
|
"node-fetch": "2.6.0",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
"react-copy-to-clipboard": "^5.0.1",
|
"react-copy-to-clipboard": "^5.0.1",
|
||||||
|
|||||||
@ -12,6 +12,8 @@ const crypto = require('crypto');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const filenamify = require('filenamify');
|
const filenamify = require('filenamify');
|
||||||
|
const mime = require('mime-types');
|
||||||
|
|
||||||
const { bytesToKbytes } = require('../utils/file');
|
const { bytesToKbytes } = require('../utils/file');
|
||||||
|
|
||||||
const randomSuffix = () => crypto.randomBytes(5).toString('hex');
|
const randomSuffix = () => crypto.randomBytes(5).toString('hex');
|
||||||
@ -31,8 +33,8 @@ const combineFilters = params => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
|
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
|
||||||
const ext = path.extname(filename);
|
const ext = '.' + mime.extension(type);
|
||||||
const baseName = path.basename(filename, ext);
|
const baseName = path.basename(filename, path.extname(filename));
|
||||||
|
|
||||||
const usedName = fileInfo.name || baseName;
|
const usedName = fileInfo.name || baseName;
|
||||||
|
|
||||||
|
|||||||
@ -11853,7 +11853,7 @@ 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-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.1.26, 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"
|
||||||
integrity sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==
|
integrity sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user