Skip to content

repair mimeType #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setLocalFileInfo,
removeLocalFileInfo,
getLocalFileInfo,
isContainFileMimeType,
findMimeType,
sum,
getDomainFromUrl,
getPortFromUrl,
Expand Down Expand Up @@ -65,11 +65,14 @@ export class UploadManager {
this.putExtra.fname = this.file.name;
}
if (this.putExtra.mimeType && this.putExtra.mimeType.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这个接口的设计上
既然数组是白名单、null 是无限制
那空数组等同于 null 是不是不太好?
哪怕空数组没什么意义 @nighca

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的空数组是想表达的是无效的意思,主要是感觉这个不像权限那种需要从严控制,所以就等同 null,要是用户给了空数组是代表任何类型都不能上传的话,相当于多了些操作控制

if (!isContainFileMimeType(this.file.type, this.putExtra.mimeType)){
let err = new Error("file type doesn't match with what you specify");
this.onError(err);
return;
}
var compareMimeType = findMimeType(this.file.type, this.putExtra.mimeType);
if (compareMimeType == null || compareMimeType == undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compareMimeType == null 就同时包含了 null 和 undefined

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,是的,find() return结果某些情况下我看有打印null也有undefined,就都加上了,第一次pr是没加undefined

let err = new Error("file type doesn't match with what you specify");
this.onError(err);
return;
} else {
this.putExtra.mimeType = [compareMimeType];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是因为这个吗? @JemyCheung

requestUrl += "/mimeType/" + urlSafeBase64Encode(putExtra.mimeType);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看这个 pr 应该是这样,采用当前文件的 mimeType,而不是名单里的都放到 url 里,不过也很奇怪,没见反应过这个问题,也可能是我遗漏了 @lzfee0227

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

工单和群里用户反馈mimeType数组所有类型全部上传到后台了,经测试是这样 @lzfee0227

}
}
let upload = getUploadUrl(this.config, this.token).then(res => {
this.uploadUrl = res;
Expand Down
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ function getUpHosts(token) {
}
}


export function isContainFileMimeType(fileType, mimeType){
return mimeType.indexOf(fileType) > -1;
export function findMimeType(fileType, mimeType) {
return mimeType.find((elem) => {
return fileType == elem;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该用三等,而且这个直接 return mimeType.find(type => fileType === type) 就好了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢,确实,我没有掌握三等这个写法 @winddies 我下午已经更新去掉了find的用法,经过测试find在IE内核不兼容,采用了forEach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对了,你们是因为什么原因更新的?这个项目的更新是要经过我们这边的 review 的。。。我们也是突然发现你们提了这个 pr 并且已经 merged 了。。。。

}

export function createObjectURL(file) {
Expand Down