@cloudbase/manager-node 3.12.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/storage/index.js +23 -9
- package/lib/utils/http-request.js +3 -3
- package/package.json +4 -3
- package/src/storage/index.ts +27 -13
- package/src/utils/http-request.ts +1 -1
package/CHANGELOG.md
CHANGED
package/lib/storage/index.js
CHANGED
|
@@ -894,26 +894,40 @@ class StorageService {
|
|
|
894
894
|
async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
|
|
895
895
|
const { files, onFileFinish } = options;
|
|
896
896
|
const tempFailedFiles = [];
|
|
897
|
+
let curError = null;
|
|
897
898
|
const res = await uploadFiles(Object.assign(Object.assign({}, options), { files: failedFiles.length
|
|
898
899
|
? files.filter(file => failedFiles.includes(file.Key))
|
|
899
900
|
: files, onFileFinish: (...args) => {
|
|
900
901
|
const error = args[0];
|
|
901
902
|
const fileInfo = args[2];
|
|
902
903
|
if (error) {
|
|
904
|
+
curError = error;
|
|
903
905
|
tempFailedFiles.push(fileInfo.Key);
|
|
904
906
|
}
|
|
905
907
|
onFileFinish === null || onFileFinish === void 0 ? void 0 : onFileFinish.apply(null, args);
|
|
906
908
|
} }));
|
|
907
|
-
if (!
|
|
909
|
+
// if (!tempFailedFiles?.length || times <= 0) return res
|
|
910
|
+
if (!(tempFailedFiles === null || tempFailedFiles === void 0 ? void 0 : tempFailedFiles.length)) {
|
|
908
911
|
return res;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
if (times > 0) {
|
|
915
|
+
return await new Promise((resolve, reject) => {
|
|
916
|
+
setTimeout(() => this.uploadFilesWithRetry({
|
|
917
|
+
uploadFiles,
|
|
918
|
+
options,
|
|
919
|
+
times: times - 1,
|
|
920
|
+
interval,
|
|
921
|
+
failedFiles: tempFailedFiles
|
|
922
|
+
}).then(res => resolve(res))
|
|
923
|
+
.catch(err => reject(err)), interval);
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
if (curError) {
|
|
928
|
+
throw curError;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
917
931
|
}
|
|
918
932
|
}
|
|
919
933
|
/**
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.fetchStream = exports.fetch = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
-
const https_proxy_agent_1 =
|
|
9
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
10
10
|
const error_1 = require("../error");
|
|
11
11
|
// 使用 fetch + 代理
|
|
12
12
|
async function fetch(url, config = {}, proxy) {
|
|
13
13
|
if (proxy || process.env.http_proxy) {
|
|
14
|
-
config.agent = new https_proxy_agent_1.
|
|
14
|
+
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
15
15
|
}
|
|
16
16
|
// 解决中文编码问题
|
|
17
17
|
const escapeUrl = new url_1.URL(url).toString();
|
|
@@ -35,7 +35,7 @@ async function fetch(url, config = {}, proxy) {
|
|
|
35
35
|
exports.fetch = fetch;
|
|
36
36
|
async function fetchStream(url, config = {}, proxy) {
|
|
37
37
|
if (proxy || process.env.http_proxy) {
|
|
38
|
-
config.agent = new https_proxy_agent_1.
|
|
38
|
+
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
39
39
|
}
|
|
40
40
|
// 解决中文编码问题
|
|
41
41
|
const escapeUrl = new url_1.URL(url).toString();
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf lib types && npx tsc",
|
|
8
8
|
"test": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
|
|
9
9
|
"lint": "eslint \"./**/*.ts\"",
|
|
10
|
-
"lint:fix": "eslint --fix \"./**/*.ts\""
|
|
10
|
+
"lint:fix": "eslint --fix \"./**/*.ts\"",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"archiver": "^3.1.1",
|
|
37
38
|
"cos-nodejs-sdk-v5": "2.9.0",
|
|
38
39
|
"del": "^5.1.0",
|
|
39
|
-
"https-proxy-agent": "^
|
|
40
|
+
"https-proxy-agent": "^5.0.1",
|
|
40
41
|
"make-dir": "^3.0.0",
|
|
41
42
|
"micromatch": "^4.0.2",
|
|
42
43
|
"node-fetch": "^2.6.0",
|
package/src/storage/index.ts
CHANGED
|
@@ -1198,6 +1198,7 @@ export class StorageService {
|
|
|
1198
1198
|
private async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
|
|
1199
1199
|
const { files, onFileFinish } = options
|
|
1200
1200
|
const tempFailedFiles = []
|
|
1201
|
+
let curError: any = null
|
|
1201
1202
|
const res = await uploadFiles({
|
|
1202
1203
|
...options,
|
|
1203
1204
|
files: failedFiles.length
|
|
@@ -1207,24 +1208,37 @@ export class StorageService {
|
|
|
1207
1208
|
const error = args[0]
|
|
1208
1209
|
const fileInfo = (args as any)[2]
|
|
1209
1210
|
if (error) {
|
|
1211
|
+
curError = error
|
|
1210
1212
|
tempFailedFiles.push(fileInfo.Key)
|
|
1211
1213
|
}
|
|
1212
1214
|
onFileFinish?.apply(null, args)
|
|
1213
1215
|
}
|
|
1214
1216
|
})
|
|
1215
|
-
if (!tempFailedFiles?.length || times <= 0) return res
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1217
|
+
// if (!tempFailedFiles?.length || times <= 0) return res
|
|
1218
|
+
|
|
1219
|
+
if (!tempFailedFiles?.length) {
|
|
1220
|
+
return res
|
|
1221
|
+
} else {
|
|
1222
|
+
if (times > 0) {
|
|
1223
|
+
return await new Promise((resolve, reject) => {
|
|
1224
|
+
setTimeout(
|
|
1225
|
+
() =>
|
|
1226
|
+
this.uploadFilesWithRetry({
|
|
1227
|
+
uploadFiles,
|
|
1228
|
+
options,
|
|
1229
|
+
times: times - 1,
|
|
1230
|
+
interval,
|
|
1231
|
+
failedFiles: tempFailedFiles
|
|
1232
|
+
}).then(res => resolve(res))
|
|
1233
|
+
.catch(err => reject(err)),
|
|
1234
|
+
interval
|
|
1235
|
+
)
|
|
1236
|
+
})
|
|
1237
|
+
} else {
|
|
1238
|
+
if (curError) {
|
|
1239
|
+
throw curError
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1228
1242
|
}
|
|
1229
1243
|
}
|
|
1230
1244
|
|