Skip to content
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

[KS-55] 临时修复任务进度回退问题 #668

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading