Use mime-types to set extension

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-04-03 13:35:33 +02:00
parent b5b140bb32
commit 904b2b438b
4 changed files with 10 additions and 3 deletions

View File

@ -31,6 +31,10 @@ module.exports = strapi => ({
try {
const url = new URL(ctx.query.url);
if (!['http:', 'https:'].includes(url.protocol)) {
throw new Error('Invalid URL');
}
if (!isValidDomain(url.hostname)) {
throw new Error('Invalid URL');
}

View File

@ -20,6 +20,7 @@
"koa-range": "0.3.0",
"koa-static": "^5.0.0",
"lodash": "^4.17.11",
"mime-types": "2.1.26",
"node-fetch": "2.6.0",
"react": "^16.9.0",
"react-copy-to-clipboard": "^5.0.1",

View File

@ -12,6 +12,8 @@ const crypto = require('crypto');
const _ = require('lodash');
const util = require('util');
const filenamify = require('filenamify');
const mime = require('mime-types');
const { bytesToKbytes } = require('../utils/file');
const randomSuffix = () => crypto.randomBytes(5).toString('hex');
@ -31,8 +33,8 @@ const combineFilters = params => {
module.exports = {
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
const ext = path.extname(filename);
const baseName = path.basename(filename, ext);
const ext = '.' + mime.extension(type);
const baseName = path.basename(filename, path.extname(filename));
const usedName = fileInfo.name || baseName;

View File

@ -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"
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"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.26.tgz#9c921fc09b7e149a65dfdc0da4d20997200b0a06"
integrity sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==