Skip to content

Commit b26109b

Browse files
author
JemyCheung
committed
recode
1 parent f34dae0 commit b26109b

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/upload.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
setLocalFileInfo,
66
removeLocalFileInfo,
77
getLocalFileInfo,
8-
isContainFileMimeType,
8+
findMimeType,
99
sum,
1010
getDomainFromUrl,
1111
getPortFromUrl,
@@ -65,14 +65,14 @@ export class UploadManager {
6565
this.putExtra.fname = this.file.name;
6666
}
6767
if (this.putExtra.mimeType && this.putExtra.mimeType.length) {
68-
var compareMimeType = isContainFileMimeType(this.file.type, this.putExtra.mimeType);
69-
if (compareMimeType == null){
70-
let err = new Error("file type doesn't match with what you specify");
71-
this.onError(err);
72-
return;
73-
}else{
74-
this.putExtra.mimeType = [compareMimeType];
75-
}
68+
var compareMimeType = findMimeType(this.file.type, this.putExtra.mimeType);
69+
if (compareMimeType == null || compareMimeType == undefined) {
70+
let err = new Error("file type doesn't match with what you specify");
71+
this.onError(err);
72+
return;
73+
} else {
74+
this.putExtra.mimeType = [compareMimeType];
75+
}
7676
}
7777
let upload = getUploadUrl(this.config, this.token).then(res => {
7878
this.uploadUrl = res;

src/utils.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,12 @@ function getUpHosts(token) {
264264
}
265265
}
266266

267-
268-
export function isContainFileMimeType(fileType, mimeType){
269-
var rtType = null;
270-
mimeType.forEach(elem => {
271-
if(fileType == elem){
272-
rtType = fileType;
273-
}
274-
});
275-
return rtType;
267+
export function findMimeType(fileType, mimeType) {
268+
return mimeType.find((elem) => {
269+
if (fileType == elem) {
270+
return elem;
271+
}
272+
});
276273
}
277274

278275
export function createObjectURL(file) {

0 commit comments

Comments
 (0)