Skip to content

Commit 6f260fc

Browse files
committed
fix: update upload file
1 parent 3f39886 commit 6f260fc

File tree

5 files changed

+218
-523
lines changed

5 files changed

+218
-523
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ module.exports = {
1010
}],
1111
'import/no-unresolved': 'off',
1212
'arrow-body-style': ['error', 'always'],
13+
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
1314
},
1415
};

command/upload.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,38 @@ export const uploadCommand = new Command('upload')
1313
.argument('[pattern]', 'glob pattern', '*')
1414
.argument('[remote]', 'remote path', sep)
1515
.option('-t --token [token]', 'access token')
16-
.option('-b --bytes <number>', 'Split upload bytes size', Number, 1073741824)
16+
.option('-b --bytes <number>', 'split upload bytes size', Number, 1073741824)
1717
.option('--thread', 'Thread')
18-
.action(async (pattern, remote, options, command) => {
19-
const { pcs } = command;
20-
18+
.action(async (pattern, remote, options, { pcs }) => {
2119
const files = await glob(pattern, {
2220
nodir: true,
2321
});
2422
const { bytes } = options;
25-
2623
const temp = join(os.tmpdir(), 'pcs-cli');
27-
try {
28-
// 串行上传
29-
files.reduce(async (previousValue, currentValue) => {
30-
await previousValue;
31-
const fileStat = statSync(currentValue);
3224

25+
try {
26+
for await (const file of files) {
27+
const fileStat = statSync(file);
3328
if (Number.isInteger(bytes) && fileStat.size > bytes) {
3429
// 分片上传
35-
const pieces = await splitFile(currentValue, bytes, temp);
30+
const pieces = await splitFile(file, bytes, temp);
3631
const blocks = [];
3732

3833
// eslint-disable-next-line no-restricted-syntax
3934
for (const piece of pieces as string[]) {
4035
//
4136
// eslint-disable-next-line no-await-in-loop
42-
const { md5 } = await pcs.upload(piece, '', 'overwrite', 'tmpfile') as any;
37+
const { md5 } = await pcs.upload(piece, '', 'overwrite', 'tmpfile');
4338
blocks.push(md5);
4439
}
4540
const param = {
4641
block_list: blocks,
4742
};
48-
return pcs.createSuperFile(join(remote, currentValue), param) as unknown as Promise<void>;
43+
await pcs.createSuperFile(join(remote, file), param);
4944
}
50-
console.log(`${chalk.blueBright('==>')} Uploading ${currentValue}`);
51-
return pcs.upload(currentValue, join(remote, currentValue)) as Promise<void>;
52-
}, Promise.resolve());
53-
54-
// todo
45+
console.log(`${chalk.blueBright('==>')} Uploading ${file}`);
46+
await pcs.upload(file, join(remote, file));
47+
}
5548
} catch (err: any) {
5649
const { response: { data } } = err;
5750
console.log(`error code ${data.error_code} : ${data.error_msg}`);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"axios": "^1.13.2",
4242
"bytes": "^3.1.2",
4343
"chalk": "^5.6.2",
44-
"cliui": "^9.0.1",
44+
"cliui": "^8.0.1",
4545
"commander": "^14.0.2",
4646
"dayjs": "^1.11.19",
4747
"glob": "^13.0.0",
@@ -50,8 +50,8 @@
5050
"prompts": "^2.4.2"
5151
},
5252
"devDependencies": {
53-
"@commitlint/cli": "^19.2.2",
54-
"@commitlint/config-conventional": "^19.2.2",
53+
"@commitlint/cli": "^20.2.0",
54+
"@commitlint/config-conventional": "^20.2.0",
5555
"@rollup/plugin-commonjs": "^25.0.7",
5656
"@rollup/plugin-json": "^6.1.0",
5757
"@rollup/plugin-node-resolve": "^15.2.3",

0 commit comments

Comments
 (0)