Skip to content

Commit 028c17c

Browse files
authored
[KS-55] 临时修复任务进度回退问题 (#668)
* 临时修复任务进度回退问题 * 更新版本号
1 parent 666bcb7 commit 028c17c

File tree

9 files changed

+71
-9
lines changed

9 files changed

+71
-9
lines changed

export-codes.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// 本脚本用于软著申请导出代码
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// 指定输出文件路径
7+
const outputFilePath = 'code.txt';
8+
9+
// 递归扫描目录下的所有文件
10+
function scanDirectory(dirPath) {
11+
const files = fs.readdirSync(dirPath);
12+
for (const file of files) {
13+
const filePath = path.join(dirPath, file);
14+
const stats = fs.statSync(filePath);
15+
if (stats.isDirectory()) {
16+
scanDirectory(filePath);
17+
} else {
18+
appendFileContent(filePath);
19+
}
20+
}
21+
}
22+
23+
function removeBlankLines(text) {
24+
// 使用正则表达式匹配并移除所有空白行
25+
return text.replace(/^\s*[\r\n]/gm, '');
26+
}
27+
28+
function removeComments(code) {
29+
// 使用正则表达式匹配并移除所有注释
30+
return code.replace(
31+
/\/\*[\s\S]*?\*\/|\/\/.*|#.*(?:\n|$)/g,
32+
(match) => {
33+
// 检查是否为多行注释,如果是则返回换行符,否则返回空字符串
34+
return /^\/\*/.test(match) ? '\n' : '';
35+
}
36+
);
37+
}
38+
// 将文件内容写入输出文件
39+
function appendFileContent(filePath) {
40+
const fileContent = fs.readFileSync(filePath, 'utf8');
41+
const safeContent = removeBlankLines(removeComments(fileContent))
42+
fs.appendFileSync(outputFilePath, `${filePath}\n${safeContent}\n\n`)
43+
}
44+
45+
// 开始扫描当前目录
46+
scanDirectory('./packages/harmony/library/src');
47+
console.log(`文件内容已输出到 ${outputFilePath}`);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qiniu-js",
3-
"version": "4.0.0-beta.3",
3+
"version": "4.0.0-beta.4",
44
"description": "Qiniu browser upload sdk",
55
"miniprogram": "output",
66
"main": "output/index.js",

packages/common/src/upload/common/context/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ export function updateTotalIntoProgress(progress: Progress): Progress {
3232
totalPercent += value.percent
3333
}
3434

35+
const newPercent = totalPercent / detailValues.length
36+
37+
// 在失败重试等场景中,进度回退是正常业务导致的,但是客户要求进度不能回退
38+
if (newPercent > progress.percent) progress.percent = newPercent // 防止进度倒流
39+
3540
progress.size = totalSize
36-
progress.percent = totalPercent / detailValues.length
3741
return progress
3842
}
3943

packages/common/src/upload/multipartv1/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ export const createMultipartUploadV1Task = (file: UploadFile, config: UploadConf
201201
level: normalizedConfig.logLevel,
202202
prefix: 'MultipartUploadChildQueue'
203203
},
204-
concurrentLimit: 1,
204+
concurrentLimit: 1, // 此接口只能串行
205+
// TODO 动态创建任务会导致任务进度倒退
205206
tasksCreator: async () => {
206207
const sliceResult = await file.slice(4 * 1024 * 1024)
207208
if (isErrorResult(sliceResult)) {

packages/common/src/upload/multipartv2/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ export const createMultipartUploadV2Task = (file: UploadFile, config: UploadConf
317317
prefix: 'MultipartUploadChildQueue'
318318
},
319319
concurrentLimit: 3,
320+
321+
// TODO 动态创建任务会导致任务进度倒退
320322
tasksCreator: async () => {
321323
const sliceResult = await file.slice(4 * 1024 * 1024)
322324
if (isErrorResult(sliceResult)) {

packages/harmony/library/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change logs
22

3+
## v1.0.2 (2024-07-26)
4+
5+
### 改动
6+
7+
- 优化进度处理,避免进度回退
8+
- 其他实现细节优化
9+
310
## v1.0.1 (2024-07-09)
411

512
### 改动

packages/harmony/library/oh-package.json5

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"modelVersion": "5.0.0",
33
"name": "@qiniu/upload",
4-
"version": "1.0.1",
5-
"keywords": ["qiniu", "upload", "oss"],
6-
"description": "Qiniu Cloud object storage upload sdk",
4+
"version": "1.0.2",
5+
"homepage": "https://www.qiniu.com",
6+
"keywords": ["七牛", "qiniu", "upload", "oss"],
77
"repository": "https://github.com/qiniu/js-sdk.git",
8+
"description": "七牛云对象存储上传 SDK,终身免费 10G 存储空间",
89
"main": "index.ets",
910
"artifactType": "original",
1011
"author": "qiniu",

packages/wechat-miniprogram/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qiniu/wechat-miniprogram-upload",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Qiniu wechat-miniprogram upload sdk",
55
"miniprogram": "output",
66
"main": "output/index.js",

0 commit comments

Comments
 (0)