From f34dae0cd58c64029194ec8f6c24e328b69ac8b1 Mon Sep 17 00:00:00 2001 From: JemyCheung Date: Fri, 11 Oct 2019 20:42:52 +0800 Subject: [PATCH 1/3] repair mimeType --- src/upload.js | 5 ++++- src/utils.js | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/upload.js b/src/upload.js index 66af78da..52b31f6b 100644 --- a/src/upload.js +++ b/src/upload.js @@ -65,10 +65,13 @@ export class UploadManager { this.putExtra.fname = this.file.name; } if (this.putExtra.mimeType && this.putExtra.mimeType.length) { - if (!isContainFileMimeType(this.file.type, this.putExtra.mimeType)){ + var compareMimeType = isContainFileMimeType(this.file.type, this.putExtra.mimeType); + if (compareMimeType == null){ let err = new Error("file type doesn't match with what you specify"); this.onError(err); return; + }else{ + this.putExtra.mimeType = [compareMimeType]; } } let upload = getUploadUrl(this.config, this.token).then(res => { diff --git a/src/utils.js b/src/utils.js index bcb25d43..d9b0ef37 100644 --- a/src/utils.js +++ b/src/utils.js @@ -266,7 +266,13 @@ function getUpHosts(token) { export function isContainFileMimeType(fileType, mimeType){ - return mimeType.indexOf(fileType) > -1; + var rtType = null; + mimeType.forEach(elem => { + if(fileType == elem){ + rtType = fileType; + } + }); + return rtType; } export function createObjectURL(file) { From b26109b4b85ef2e4619ea35b575d33feaf3a3dfd Mon Sep 17 00:00:00 2001 From: JemyCheung Date: Sat, 12 Oct 2019 09:16:59 +0800 Subject: [PATCH 2/3] recode --- src/upload.js | 18 +++++++++--------- src/utils.js | 15 ++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/upload.js b/src/upload.js index 52b31f6b..db283efa 100644 --- a/src/upload.js +++ b/src/upload.js @@ -5,7 +5,7 @@ import { setLocalFileInfo, removeLocalFileInfo, getLocalFileInfo, - isContainFileMimeType, + findMimeType, sum, getDomainFromUrl, getPortFromUrl, @@ -65,14 +65,14 @@ export class UploadManager { this.putExtra.fname = this.file.name; } if (this.putExtra.mimeType && this.putExtra.mimeType.length) { - var compareMimeType = isContainFileMimeType(this.file.type, this.putExtra.mimeType); - if (compareMimeType == null){ - let err = new Error("file type doesn't match with what you specify"); - this.onError(err); - return; - }else{ - this.putExtra.mimeType = [compareMimeType]; - } + var compareMimeType = findMimeType(this.file.type, this.putExtra.mimeType); + if (compareMimeType == null || compareMimeType == undefined) { + let err = new Error("file type doesn't match with what you specify"); + this.onError(err); + return; + } else { + this.putExtra.mimeType = [compareMimeType]; + } } let upload = getUploadUrl(this.config, this.token).then(res => { this.uploadUrl = res; diff --git a/src/utils.js b/src/utils.js index d9b0ef37..165e76b3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -264,15 +264,12 @@ function getUpHosts(token) { } } - -export function isContainFileMimeType(fileType, mimeType){ - var rtType = null; - mimeType.forEach(elem => { - if(fileType == elem){ - rtType = fileType; - } - }); - return rtType; +export function findMimeType(fileType, mimeType) { + return mimeType.find((elem) => { + if (fileType == elem) { + return elem; + } + }); } export function createObjectURL(file) { From 50941e1eb0104d2779ed4e91d5cf5ee44e836d32 Mon Sep 17 00:00:00 2001 From: JemyCheung Date: Sat, 12 Oct 2019 13:02:03 +0800 Subject: [PATCH 3/3] utils.findMimeType --- src/utils.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 165e76b3..edc2d455 100644 --- a/src/utils.js +++ b/src/utils.js @@ -266,9 +266,7 @@ function getUpHosts(token) { export function findMimeType(fileType, mimeType) { return mimeType.find((elem) => { - if (fileType == elem) { - return elem; - } + return fileType == elem; }); }