Skip to content

Commit

Permalink
[KS-55] 临时修复任务进度回退问题 (#668)
Browse files Browse the repository at this point in the history
* 临时修复任务进度回退问题

* 更新版本号
  • Loading branch information
yinxulai authored Jul 26, 2024
1 parent 666bcb7 commit 028c17c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 9 deletions.
47 changes: 47 additions & 0 deletions export-codes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 本脚本用于软著申请导出代码

const fs = require('fs');
const path = require('path');

// 指定输出文件路径
const outputFilePath = 'code.txt';

// 递归扫描目录下的所有文件
function scanDirectory(dirPath) {
const files = fs.readdirSync(dirPath);
for (const file of files) {
const filePath = path.join(dirPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
scanDirectory(filePath);
} else {
appendFileContent(filePath);
}
}
}

function removeBlankLines(text) {
// 使用正则表达式匹配并移除所有空白行
return text.replace(/^\s*[\r\n]/gm, '');
}

function removeComments(code) {
// 使用正则表达式匹配并移除所有注释
return code.replace(
/\/\*[\s\S]*?\*\/|\/\/.*|#.*(?:\n|$)/g,
(match) => {
// 检查是否为多行注释,如果是则返回换行符,否则返回空字符串
return /^\/\*/.test(match) ? '\n' : '';
}
);
}
// 将文件内容写入输出文件
function appendFileContent(filePath) {
const fileContent = fs.readFileSync(filePath, 'utf8');
const safeContent = removeBlankLines(removeComments(fileContent))
fs.appendFileSync(outputFilePath, `${filePath}\n${safeContent}\n\n`)
}

// 开始扫描当前目录
scanDirectory('./packages/harmony/library/src');
console.log(`文件内容已输出到 ${outputFilePath}`);
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qiniu-js",
"version": "4.0.0-beta.3",
"version": "4.0.0-beta.4",
"description": "Qiniu browser upload sdk",
"miniprogram": "output",
"main": "output/index.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/common/src/upload/common/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export function updateTotalIntoProgress(progress: Progress): Progress {
totalPercent += value.percent
}

const newPercent = totalPercent / detailValues.length

// 在失败重试等场景中,进度回退是正常业务导致的,但是客户要求进度不能回退
if (newPercent > progress.percent) progress.percent = newPercent // 防止进度倒流

progress.size = totalSize
progress.percent = totalPercent / detailValues.length
return progress
}

Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/upload/multipartv1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ export const createMultipartUploadV1Task = (file: UploadFile, config: UploadConf
level: normalizedConfig.logLevel,
prefix: 'MultipartUploadChildQueue'
},
concurrentLimit: 1,
concurrentLimit: 1, // 此接口只能串行
// TODO 动态创建任务会导致任务进度倒退
tasksCreator: async () => {
const sliceResult = await file.slice(4 * 1024 * 1024)
if (isErrorResult(sliceResult)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/upload/multipartv2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ export const createMultipartUploadV2Task = (file: UploadFile, config: UploadConf
prefix: 'MultipartUploadChildQueue'
},
concurrentLimit: 3,

// TODO 动态创建任务会导致任务进度倒退
tasksCreator: async () => {
const sliceResult = await file.slice(4 * 1024 * 1024)
if (isErrorResult(sliceResult)) {
Expand Down
7 changes: 7 additions & 0 deletions packages/harmony/library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change logs

## v1.0.2 (2024-07-26)

### 改动

- 优化进度处理,避免进度回退
- 其他实现细节优化

## v1.0.1 (2024-07-09)

### 改动
Expand Down
7 changes: 4 additions & 3 deletions packages/harmony/library/oh-package.json5
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"modelVersion": "5.0.0",
"name": "@qiniu/upload",
"version": "1.0.1",
"keywords": ["qiniu", "upload", "oss"],
"description": "Qiniu Cloud object storage upload sdk",
"version": "1.0.2",
"homepage": "https://www.qiniu.com",
"keywords": ["七牛", "qiniu", "upload", "oss"],
"repository": "https://github.com/qiniu/js-sdk.git",
"description": "七牛云对象存储上传 SDK,终身免费 10G 存储空间",
"main": "index.ets",
"artifactType": "original",
"author": "qiniu",
Expand Down
2 changes: 1 addition & 1 deletion packages/wechat-miniprogram/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qiniu/wechat-miniprogram-upload",
"version": "1.0.2",
"version": "1.0.3",
"description": "Qiniu wechat-miniprogram upload sdk",
"miniprogram": "output",
"main": "output/index.js",
Expand Down

0 comments on commit 028c17c

Please sign in to comment.