directus-template-cli 0.5.0-beta.14 → 0.5.0-beta.16
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/dist/lib/extract/extract-assets.js +11 -5
- package/dist/lib/sdk.js +7 -6
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,6 @@ const sdk_1 = require("@directus/sdk");
|
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
7
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
9
|
-
const promises_1 = require("node:stream/promises");
|
|
10
9
|
const constants_1 = require("../constants");
|
|
11
10
|
const sdk_2 = require("../sdk");
|
|
12
11
|
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
@@ -14,11 +13,18 @@ async function getAssetList() {
|
|
|
14
13
|
return sdk_2.api.client.request((0, sdk_1.readFiles)({ limit: -1 }));
|
|
15
14
|
}
|
|
16
15
|
async function downloadFile(file, dir) {
|
|
17
|
-
const response = await sdk_2.api.client.request((
|
|
16
|
+
const response = await sdk_2.api.client.request(() => ({
|
|
17
|
+
method: 'GET',
|
|
18
|
+
path: `/assets/${file.id}`,
|
|
19
|
+
}));
|
|
18
20
|
const fullPath = node_path_1.default.join(dir, 'assets', file.filename_disk);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (typeof response === 'string') {
|
|
22
|
+
node_fs_1.default.writeFileSync(fullPath, response);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const data = await response.arrayBuffer();
|
|
26
|
+
node_fs_1.default.writeFileSync(fullPath, Buffer.from(data));
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
async function downloadAllFiles(dir) {
|
|
24
30
|
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Downloading assets'));
|
package/dist/lib/sdk.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.api = exports.DirectusError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const sdk_1 = require("@directus/sdk");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
6
7
|
const bottleneck_1 = tslib_1.__importDefault(require("bottleneck"));
|
|
7
8
|
class DirectusError extends Error {
|
|
8
9
|
constructor(response) {
|
|
@@ -57,12 +58,12 @@ class Api {
|
|
|
57
58
|
const statusCode = error.status;
|
|
58
59
|
if (statusCode === 429) {
|
|
59
60
|
const delay = retryAfter ? Number.parseInt(retryAfter, 10) * 1000 : 60000;
|
|
60
|
-
|
|
61
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Rate limited. Retrying after ${delay}ms`);
|
|
61
62
|
return delay;
|
|
62
63
|
}
|
|
63
64
|
if (statusCode === 503) {
|
|
64
65
|
const delay = retryAfter ? Number.parseInt(retryAfter, 10) * 1000 : 5000;
|
|
65
|
-
|
|
66
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Server under pressure. Retrying after ${delay}ms`);
|
|
66
67
|
return delay;
|
|
67
68
|
}
|
|
68
69
|
if (statusCode === 400) {
|
|
@@ -72,17 +73,17 @@ class Api {
|
|
|
72
73
|
// For other errors, use exponential backoff, but only if we haven't exceeded retryCount
|
|
73
74
|
if (jobInfo.retryCount < 3) {
|
|
74
75
|
const delay = Math.min(1000 * 2 ** jobInfo.retryCount, 30000);
|
|
75
|
-
|
|
76
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Request failed. Retrying after ${delay}ms`);
|
|
76
77
|
return delay;
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Max retries reached, not retrying further`);
|
|
79
80
|
});
|
|
80
81
|
this.limiter.on('retry', (error, jobInfo) => {
|
|
81
|
-
|
|
82
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Retrying job (attempt ${jobInfo.retryCount + 1})`);
|
|
82
83
|
});
|
|
83
84
|
this.limiter.on('depleted', empty => {
|
|
84
85
|
if (empty) {
|
|
85
|
-
|
|
86
|
+
core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Rate limit quota depleted. Requests will be queued.`);
|
|
86
87
|
}
|
|
87
88
|
});
|
|
88
89
|
}
|
package/oclif.manifest.json
CHANGED