@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.cjs
CHANGED
|
@@ -90,6 +90,7 @@ function sleep(ms, signal) {
|
|
|
90
90
|
);
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
+
var RETRY_SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
|
|
93
94
|
function isRetryableStatus(status) {
|
|
94
95
|
return status === 408 || status === 429 || status >= 500;
|
|
95
96
|
}
|
|
@@ -147,6 +148,9 @@ var OmniCloudClient = class {
|
|
|
147
148
|
}
|
|
148
149
|
/** Low-level request helper (retries transient failures). */
|
|
149
150
|
async request(method, path, body) {
|
|
151
|
+
if (!RETRY_SAFE_METHODS.has(method.toUpperCase())) {
|
|
152
|
+
return this.rawRequest(method, path, body);
|
|
153
|
+
}
|
|
150
154
|
return this.withRetry(async () => this.rawRequest(method, path, body));
|
|
151
155
|
}
|
|
152
156
|
/** @internal */
|
|
@@ -364,9 +368,10 @@ var FilesApi = class {
|
|
|
364
368
|
async upload(input, options = {}) {
|
|
365
369
|
const attempts = Math.max(1, (options.retry ?? 2) + 1);
|
|
366
370
|
let lastError;
|
|
371
|
+
const blob = await toBlob(input);
|
|
367
372
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
368
373
|
try {
|
|
369
|
-
return await this.uploadOnce(input, options);
|
|
374
|
+
return await this.uploadOnce(blob, input.name, options);
|
|
370
375
|
} catch (error) {
|
|
371
376
|
lastError = error;
|
|
372
377
|
if (options.signal?.aborted) throw error;
|
|
@@ -376,10 +381,9 @@ var FilesApi = class {
|
|
|
376
381
|
}
|
|
377
382
|
throw lastError;
|
|
378
383
|
}
|
|
379
|
-
async uploadOnce(
|
|
384
|
+
async uploadOnce(blob, name, options) {
|
|
380
385
|
const form = new FormData();
|
|
381
|
-
|
|
382
|
-
form.append("file", blob, input.name);
|
|
386
|
+
form.append("file", blob, name);
|
|
383
387
|
if (options.folderId) form.append("folderId", options.folderId);
|
|
384
388
|
if (typeof XMLHttpRequest === "function") {
|
|
385
389
|
return this.uploadViaXhr(form, options);
|
|
@@ -426,7 +430,7 @@ var FilesApi = class {
|
|
|
426
430
|
/** Uploads a new version of an existing file. */
|
|
427
431
|
async replace(id, input) {
|
|
428
432
|
const form = new FormData();
|
|
429
|
-
const blob =
|
|
433
|
+
const blob = await toBlob(input);
|
|
430
434
|
form.append("file", blob, input.name);
|
|
431
435
|
const { file } = await this.client.request(
|
|
432
436
|
"POST",
|
|
@@ -530,7 +534,11 @@ var FoldersApi = class {
|
|
|
530
534
|
client;
|
|
531
535
|
async list(query = {}) {
|
|
532
536
|
const { parentId, ...rest } = query;
|
|
533
|
-
const
|
|
537
|
+
const base = buildQuery(rest);
|
|
538
|
+
if (parentId === void 0)
|
|
539
|
+
return this.client.request("GET", `/api/folders${base}`);
|
|
540
|
+
const separator = base === "" ? "?" : "&";
|
|
541
|
+
const path = `/api/folders${base}${separator}parentId=${encodeURIComponent(parentId ?? "")}`;
|
|
534
542
|
return this.client.request("GET", path);
|
|
535
543
|
}
|
|
536
544
|
/** The full active folder tree (for move dialogs). */
|