-
Notifications
You must be signed in to change notification settings - Fork 520
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
添加支持多 host 自动切换 & 补全测试 #505
Conversation
* @returns Promise | ||
* @description 直传接口 | ||
*/ | ||
export function direct( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
挪进来是为了方便统一 mock 测试
Codecov Report
@@ Coverage Diff @@
## master #505 +/- ##
===========================================
+ Coverage 43.22% 72.36% +29.13%
===========================================
Files 15 20 +5
Lines 849 1071 +222
Branches 155 206 +51
===========================================
+ Hits 367 775 +408
+ Misses 472 296 -176
+ Partials 10 0 -10
Continue to review full report at Codecov.
|
src/api/index.mock.ts
Outdated
return this.callInterceptor('initUploadParts', defaultData, ...args) | ||
} | ||
|
||
public deleteUploadedChunks(...args: any[]): ReturnType<typeof api.deleteUploadedChunks> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法没地方用,所以测不到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要的话,单独写个这个方法的 test 就好了?
new Logger('', true, 'OFF') | ||
const last = new Logger('', true, 'OFF') | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了使用 private 的属性用了 // @ts-ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还有这种操作?
比起 as any 有什么优势吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那不是说明 id 改成 public 更适合?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nighca 你觉得呢 = =
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那不是说明 id 改成 public 更适合?
NIP: 或者也可以说,这边测试用例里就不太应该用 id
?如果有充分的理由说明应该 private,而且这边应该用,那我觉得只要能绕过去,怎么操作都可以,我自己倾向更简单的做法
return utils.request(url, { method: 'GET' }) | ||
} | ||
|
||
export type UploadUrlConfig = Partial<Pick<Config, 'upprotocol' | 'uphost' | 'region' | 'useCdnDomain'>> | ||
|
||
/** 获取上传url */ | ||
export async function getUploadUrl(config: UploadUrlConfig, token: string): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/upload/direct.ts
Outdated
const result = await request<UploadCompleteData>(this.uploadUrl, { | ||
method: 'POST', | ||
body: formData, | ||
await this.checkAndUpdateUploadHost() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
每次请求开始前都去更新 this 上的 host
src/upload/direct.ts
Outdated
@@ -35,6 +33,7 @@ export default class Direct extends Base { | |||
|
|||
this.logger.info('Direct progress finish.') | |||
this.finishDirectProgress() | |||
this.checkAndUnfreezeHost() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请求结束后去检查是否需要解冻
@@ -110,7 +113,11 @@ export function createXHR(): XMLHttpRequest { | |||
return new XMLHttpRequest() | |||
} | |||
|
|||
return window.ActiveXObject('Microsoft.XMLHTTP') | |||
if (window.ActiveXObject) { | |||
return new window.ActiveXObject('Microsoft.XMLHTTP') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIP:经过测试,我们的 SDK 3.x 实际不支持 IE、1.x 是支持的(还测出了几个 BUG),暂时不考虑在当前 PR 进行兼容 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Logger('', true, 'OFF') | ||
const last = new Logger('', true, 'OFF') | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还有这种操作?
比起 as any 有什么优势吗?
应该是支持的,只是某些版本 IE 不能用 xhr 的 onProgress 啥的接口而已 |
README.md
Outdated
* code: `number` 请求错误状态码,可查阅码值对应 [说明](https://developer.qiniu.com/kodo/api/3928/error-responses)。 | ||
* isRequestError: 用于区分是否为 xhr 请求错误;当 xhr 请求出现错误并且后端通过 HTTP 状态码返回了错误信息时,该参数为 `true`;否则为 `undefined`。 | ||
* `QiniuNetworkError` | ||
* code: `number` 固定为 `0`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该说清楚这是 xhr.status 的那个 0
或者 xhr.status 为 0 会进这里
你注释里那句话也可以粘进来
8b5496f
to
34c5d7c
Compare
7302f84
to
23ba618
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
本次改动