@lacrous/omnicloud 0.2.17 → 0.2.19
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/index.cjs +14 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/server/index.js +4 -2
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ function sleep(ms, signal) {
|
|
|
27
27
|
);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
var RETRY_SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
|
|
30
31
|
function isRetryableStatus(status) {
|
|
31
32
|
return status === 408 || status === 429 || status >= 500;
|
|
32
33
|
}
|
|
@@ -84,6 +85,9 @@ var OmniCloudClient = class {
|
|
|
84
85
|
}
|
|
85
86
|
/** Low-level request helper (retries transient failures). */
|
|
86
87
|
async request(method, path, body) {
|
|
88
|
+
if (!RETRY_SAFE_METHODS.has(method.toUpperCase())) {
|
|
89
|
+
return this.rawRequest(method, path, body);
|
|
90
|
+
}
|
|
87
91
|
return this.withRetry(async () => this.rawRequest(method, path, body));
|
|
88
92
|
}
|
|
89
93
|
/** @internal */
|
|
@@ -301,9 +305,10 @@ var FilesApi = class {
|
|
|
301
305
|
async upload(input, options = {}) {
|
|
302
306
|
const attempts = Math.max(1, (options.retry ?? 2) + 1);
|
|
303
307
|
let lastError;
|
|
308
|
+
const blob = await toBlob(input);
|
|
304
309
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
305
310
|
try {
|
|
306
|
-
return await this.uploadOnce(input, options);
|
|
311
|
+
return await this.uploadOnce(blob, input.name, options);
|
|
307
312
|
} catch (error) {
|
|
308
313
|
lastError = error;
|
|
309
314
|
if (options.signal?.aborted) throw error;
|
|
@@ -313,10 +318,9 @@ var FilesApi = class {
|
|
|
313
318
|
}
|
|
314
319
|
throw lastError;
|
|
315
320
|
}
|
|
316
|
-
async uploadOnce(
|
|
321
|
+
async uploadOnce(blob, name, options) {
|
|
317
322
|
const form = new FormData();
|
|
318
|
-
|
|
319
|
-
form.append("file", blob, input.name);
|
|
323
|
+
form.append("file", blob, name);
|
|
320
324
|
if (options.folderId) form.append("folderId", options.folderId);
|
|
321
325
|
if (typeof XMLHttpRequest === "function") {
|
|
322
326
|
return this.uploadViaXhr(form, options);
|
|
@@ -363,7 +367,7 @@ var FilesApi = class {
|
|
|
363
367
|
/** Uploads a new version of an existing file. */
|
|
364
368
|
async replace(id, input) {
|
|
365
369
|
const form = new FormData();
|
|
366
|
-
const blob =
|
|
370
|
+
const blob = await toBlob(input);
|
|
367
371
|
form.append("file", blob, input.name);
|
|
368
372
|
const { file } = await this.client.request(
|
|
369
373
|
"POST",
|
|
@@ -467,7 +471,11 @@ var FoldersApi = class {
|
|
|
467
471
|
client;
|
|
468
472
|
async list(query = {}) {
|
|
469
473
|
const { parentId, ...rest } = query;
|
|
470
|
-
const
|
|
474
|
+
const base = buildQuery(rest);
|
|
475
|
+
if (parentId === void 0)
|
|
476
|
+
return this.client.request("GET", `/api/folders${base}`);
|
|
477
|
+
const separator = base === "" ? "?" : "&";
|
|
478
|
+
const path = `/api/folders${base}${separator}parentId=${encodeURIComponent(parentId ?? "")}`;
|
|
471
479
|
return this.client.request("GET", path);
|
|
472
480
|
}
|
|
473
481
|
/** The full active folder tree (for move dialogs). */
|