Skip to content

修复非浏览器环境下没有 window 对象导致的错误 #460

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 13 commits into from
Jul 23, 2020

Conversation

winddies
Copy link
Contributor

@winddies winddies commented Jul 16, 2020

fix #459
考虑到 #354 ,感觉加个参数可能更合适点

@nighca nighca changed the title 修复 node 环境下没有 window 对象导致的错误 修复非浏览器环境下没有 window 对象导致的错误 Jul 16, 2020
nighca
nighca previously approved these changes Jul 16, 2020
Copy link
Contributor

@nighca nighca left a comment

Choose a reason for hiding this comment

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

🆗

@winddies
Copy link
Contributor Author

@nighca 有空看一下

Copy link
Contributor

@nighca nighca left a comment

Choose a reason for hiding this comment

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

之前说的比如 xhr 这样的问题怎么说了,解决这边的 window 的问题之后真的能在 RN 环境里用吗

src/utils.ts Outdated
}
return 'https:'

return 'http:'
Copy link
Contributor

Choose a reason for hiding this comment

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

没有 window 的环境是不是默认 https 好一点

README.md Outdated
@@ -197,6 +197,7 @@ qiniu.compressImage(file, options).then(data => {
* config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 false,不开启。
* config.forceDirect: 是否上传全部采用直传方式,为布尔值;为 `true` 时则上传方式全部为直传 form 方式,禁用断点续传,默认 `false`。
* config.chunkSize: `number`,分片上传时每片的大小,必须为正整数,单位为 `MB`,且最大不能超过 1024,默认值 4。因为 chunk 数最大 10000,所以如果文件以你所设的 `chunkSize` 进行分片并且 chunk 数超过 10000,我们会把你所设的 `chunkSize` 扩大二倍,如果仍不符合则继续扩大,直到符合条件。
* config.protocol: 自定义上传域名协议,值为 `https:` 或者 `http:`。
Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得可能还是不需要给外部指定协议?

@winddies
Copy link
Contributor Author

native 那边反应说是可以的, 他们也有 polyfill 处理其他的方面,加参数主要是感觉不同环境下在这里的表现形式差异有点大,有的环境是没有,有的是别的形式,如果后面再有其他的形式,这里就没法很好处理了,所以考虑加个参数

@nighca
Copy link
Contributor

nighca commented Jul 18, 2020

你还记不记得我们最初为什么不直接 HTTPS…我想了下,好像直接 HTTPS 就好了,暂时想不到什么正经的环境会只支持 HTTP 不支持 HTTPS?

@lzfee0227
Copy link
Collaborator

正经的环境会只支持 HTTP 不支持 HTTPS

比如私有云?

README.md Outdated
@@ -191,6 +191,7 @@ qiniu.compressImage(file, options).then(data => {
* config.useCdnDomain: 表示是否使用 cdn 加速域名,为布尔值,`true` 表示使用,默认为 `false`。
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`。
* config.uphost: 上传 `host`,类型为 `string`, 如果设定该参数则优先使用该参数作为上传地址,默认为 `null`。
* config.upProtocol: 自定义上传域名协议,值为 `https:` 或者 `http:`。
Copy link
Contributor

Choose a reason for hiding this comment

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

uphost 先一致吧:upprotocol

src/api.ts Outdated
return utils.request(url, { method: 'GET' })
}

/** 获取上传url */
export async function getUploadUrl(config: Config, token: string): Promise<string> {
const protocol = utils.getAPIProtocol()
const protocol = config.upProtocol || 'https:'
Copy link
Contributor

Choose a reason for hiding this comment

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

测试 case?

@qiniu-bot qiniu-bot added size/M and removed size/S labels Jul 22, 2020
}

let url: string
const token = '4TUDv7mcubtP5yWqzrZiI0YEVLSLEu3NlVvCxT-D:UUEt7wiIOSlS7AoCx9w_pABEFtI=:eyJkZWxldGVBZnRlckRheXMiOjEsInJldHVybkJvZHkiOiJ7XCJrZXlcIjpcIiQoa2V5KVwiLFwiaGFzaFwiOlwiJChldGFnKVwiLFwiZnNpemVcIjokKGZzaXplKSxcImJ1Y2tldFwiOlwiJChidWNrZXQpXCIsXCJuYW1lXCI6XCIkKHg6bmFtZSlcIn0iLCJzY29wZSI6ImtpbmRvbSIsImRlYWRsaW5lIjoxNTk1NDEzNjQxfQ=='
Copy link
Contributor

Choose a reason for hiding this comment

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

这个哪儿来的?一直有效吗?这边会发真实请求吗

建议是单测的话不去依赖真实的线上接口,mock 掉就好

README.md Outdated
@@ -191,6 +191,7 @@ qiniu.compressImage(file, options).then(data => {
* config.useCdnDomain: 表示是否使用 cdn 加速域名,为布尔值,`true` 表示使用,默认为 `false`。
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`。
* config.uphost: 上传 `host`,类型为 `string`, 如果设定该参数则优先使用该参数作为上传地址,默认为 `null`。
* config.upprotocol: 自定义上传域名协议,值为 `https:` 或者 `http:`。
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
Contributor

@nighca nighca left a comment

Choose a reason for hiding this comment

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

🦞

Copy link
Collaborator

@lzfee0227 lzfee0227 left a comment

Choose a reason for hiding this comment

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

l g t m

@CarlJi
Copy link
Contributor

CarlJi commented Jul 23, 2020

/lgtm

@CarlJi
Copy link
Contributor

CarlJi commented Jul 23, 2020

/approve

@qiniu-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: CarlJi, lzfee0227, nighca, winddies
To complete the pull request process, please assign
You can assign the PR to them by writing /assign in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lzfee0227 lzfee0227 merged commit 598b823 into qiniu:master Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-native 环境下,存在 window.location is undefined 的问题
5 participants