-
Notifications
You must be signed in to change notification settings - Fork 516
[KODO-13155] 添加服务端文件签名校验 #532
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
Conversation
test/demo1/main.js
Outdated
checkCrc: true, | ||
checkByMD5: true, | ||
forceDirect: true, |
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.
mark
Codecov Report
@@ Coverage Diff @@
## master #532 +/- ##
==========================================
+ Coverage 73.96% 74.39% +0.43%
==========================================
Files 20 21 +1
Lines 1060 1117 +57
Branches 197 210 +13
==========================================
+ Hits 784 831 +47
- Misses 276 286 +10
Continue to review full report at Codecov.
|
个人倾向将新添加的 简单说一下两个配置代表的实际功能
合并的理由
|
跟产品讨论了一下,产品支持移除 |
@@ -0,0 +1,60 @@ | |||
/* eslint-disable no-bitwise */ |
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.
并且写一下
现成第三方库为什么不满足需求
以及相对于被参考的第三方库来说,修改了什么东西(后续被参考的第三方库如果修复了什么 bug 这里就能溯源跟进)
src/utils/crc32.ts
Outdated
if (file.size <= MB) { | ||
// arrayBuffer 方法 jest(jsdom) 暂时不支持、所以不对该方法添加单测 | ||
// https://github.com/jsdom/jsdom/issues/3206 => https://github.com/jsdom/jsdom/issues/2555 | ||
const block = await file.arrayBuffer() |
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.
现在兼容到 IE 什么版本的?支持这个吗?
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.
ie
不支持
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.
所以到底是兼容到什么版本?ie 9?
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.
10
src/utils/crc32.ts
Outdated
// https://github.com/jsdom/jsdom/issues/3206 => https://github.com/jsdom/jsdom/issues/2555 | ||
const block = await file.arrayBuffer() | ||
this.append(new Uint8Array(block)) | ||
return (this.crc ^ -1) >>> 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.
^ -1) >>> 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.
没必要
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.
一个基础运算、没必要、别人做了不等于我们要做
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.
如果别人都做了,你应该证明的是为什么唯独你不用做…
比如这个 -1
是运算过程中的内部概念,为什么要消费者去处理
这跟代码长短无关,如果因为代码短事情就简单,你就不会花了这么久都找不到问题出在 >>> 0
上
README.md
Outdated
@@ -215,6 +215,7 @@ qiniu.compressImage(file, options).then(data => { | |||
* config.region: 选择上传域名区域;当为 `null` 或 `undefined` 时,自动分析上传域名区域,当指定了 `uphost` 时,此设置项无效。 | |||
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。 | |||
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。 | |||
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名、上传时服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误,默认为 false,不开启。 |
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:在语文里,顿号真的不是这么用的… 而且这里是可以用句号的,没必要强行搞顿号
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.
是不是应该说 上传前
上传后
而不是 上传时
另外 返回错误
的错误信息封装了吗?用户会拿到一个什么 error
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.
是不是应该说 上传前 上传后 而不是 上传时
上传时
泛指整个上传过程
之所以不写是上传前
还是上传后
是因为分片和直传的实现不同,
同时也没必要暴露这么精确的概念给用户。
另外 返回错误 的错误信息封装了吗?用户会拿到一个什么 error
没有针对这个错误单独封装 Error
,用户会拿到 QiniuRequestError
,通过 code
消费错误信息
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.
我只是觉得这两个 上传时
很难理解而已
你这里至少提一下这个错误对应的 code
是多少吧
README.md
Outdated
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名、上传时服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误,默认为 false,不开启。 | ||
* config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 false,不开启。 |
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.
这个不能想当然的 另外如果你要删掉这个,那就发大版本 breaking change |
这不是从技术实现手段上看的,而是从需求上看的 |
我也感觉这个结论有点草率;如果内容失效的可能性很小(或者失效导致的后果可以接受),而设备对性能敏感(比如移动设备等),去掉本地的 md5 验证可能是合理的 除了 @lzfee0227 提的几个问题,其他我没有问题 |
实际上、现在读分片、如果关闭 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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
@@ -215,8 +215,8 @@ qiniu.compressImage(file, options).then(data => { | |||
* config.region: 选择上传域名区域;当为 `null` 或 `undefined` 时,自动分析上传域名区域,当指定了 `uphost` 时,此设置项无效。 | |||
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。 | |||
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。 | |||
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名、上传时服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误,默认为 false,不开启。 | |||
* config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 false,不开启。 | |||
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名,服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误(`code`: 406),默认为 `false`,不开启。 |
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.
406 -> 406
jira-issue
改动
checkByServer
启用上述两个功能(默认关闭)