@koolbase/core 12.18.0 → 12.20.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/dist/cjs/file-controller.d.ts +39 -0
- package/dist/cjs/file-controller.js +115 -0
- package/dist/cjs/files-controller.d.ts +62 -0
- package/dist/cjs/files-controller.js +160 -0
- package/dist/cjs/files-refresh.d.ts +9 -0
- package/dist/cjs/files-refresh.js +39 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/react/index.d.ts +2 -0
- package/dist/cjs/react/index.js +5 -1
- package/dist/cjs/react/use-file.d.ts +6 -0
- package/dist/cjs/react/use-file.js +35 -0
- package/dist/cjs/react/use-files.d.ts +8 -0
- package/dist/cjs/react/use-files.js +37 -0
- package/dist/cjs/storage.js +19 -8
- package/dist/esm/file-controller.d.ts +39 -0
- package/dist/esm/file-controller.js +111 -0
- package/dist/esm/files-controller.d.ts +62 -0
- package/dist/esm/files-controller.js +155 -0
- package/dist/esm/files-refresh.d.ts +9 -0
- package/dist/esm/files-refresh.js +34 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/react/index.d.ts +2 -0
- package/dist/esm/react/index.js +2 -0
- package/dist/esm/react/use-file.d.ts +6 -0
- package/dist/esm/react/use-file.js +32 -0
- package/dist/esm/react/use-files.d.ts +8 -0
- package/dist/esm/react/use-files.js +34 -0
- package/dist/esm/storage.js +19 -8
- package/package.json +1 -1
package/dist/esm/storage.js
CHANGED
|
@@ -5,8 +5,14 @@ import { KoolbaseStorageError, koolbaseStorageErrorFromResponse, } from './stora
|
|
|
5
5
|
import { putWithProgress, runUploadTask } from './storage-transfer.js';
|
|
6
6
|
import { sendParts } from './storage-multipart.js';
|
|
7
7
|
import { KoolbaseDownloadCancelledError } from './storage-errors.js';
|
|
8
|
+
import { refreshBucketFiles } from './files-refresh.js';
|
|
8
9
|
import { KoolbaseNetworkError } from './network.js';
|
|
9
10
|
import { fileInfoFromJson, filePageFromJson, listFilesQuery, } from './storage-files.js';
|
|
11
|
+
/** An upload task whose success reloads the bucket's file lists (storage S4). */
|
|
12
|
+
function listsReload(task, bucket) {
|
|
13
|
+
task.result.then(() => { void refreshBucketFiles(bucket); }, () => { });
|
|
14
|
+
return task;
|
|
15
|
+
}
|
|
10
16
|
// --- Cloudflare image-transform URL helpers -------------------------------
|
|
11
17
|
// Module-private — callers use KoolbaseStorage.publicUrl / publicUrlForObject.
|
|
12
18
|
function clampInt(v, min, max) {
|
|
@@ -129,7 +135,7 @@ export class KoolbaseStorage {
|
|
|
129
135
|
* const { object } = await task.result;
|
|
130
136
|
*/
|
|
131
137
|
startUpload(options) {
|
|
132
|
-
return runUploadTask((task) => this.runUpload(options, task));
|
|
138
|
+
return listsReload(runUploadTask((task) => this.runUpload(options, task)), options.bucket);
|
|
133
139
|
}
|
|
134
140
|
async runUpload(options, task) {
|
|
135
141
|
task.checkCancelled();
|
|
@@ -239,14 +245,14 @@ export class KoolbaseStorage {
|
|
|
239
245
|
* await Koolbase.storage.resumeUpload({ bucket: 'video', uploadId, file }).result;
|
|
240
246
|
*/
|
|
241
247
|
resumeUpload(options) {
|
|
242
|
-
return runUploadTask(async (task) => {
|
|
248
|
+
return listsReload(runUploadTask(async (task) => {
|
|
243
249
|
const isBlob = typeof Blob !== 'undefined' && options.file instanceof Blob;
|
|
244
250
|
const blob = isBlob
|
|
245
251
|
? options.file
|
|
246
252
|
: await (await sessionFetch(options.file.uri)).blob();
|
|
247
253
|
task.setTotal(blob.size);
|
|
248
254
|
return this.runInParts(options.bucket, options, task, blob, '', options.uploadId);
|
|
249
|
-
});
|
|
255
|
+
}), options.bucket);
|
|
250
256
|
}
|
|
251
257
|
async runInParts(bucket, options, task, file, contentType, resumeId) {
|
|
252
258
|
const base = `${this.config.baseUrl}/v1/sdk/storage/uploads`;
|
|
@@ -463,7 +469,9 @@ export class KoolbaseStorage {
|
|
|
463
469
|
if (!res.ok) {
|
|
464
470
|
throw await this.error(res, op === 'move' ? 'Failed to move the file' : 'Failed to copy the file');
|
|
465
471
|
}
|
|
466
|
-
|
|
472
|
+
const moved = mapObjectFromServer(await res.json());
|
|
473
|
+
void refreshBucketFiles(o.bucket, ...(o.toBucket && o.toBucket !== o.bucket ? [o.toBucket] : []));
|
|
474
|
+
return moved;
|
|
467
475
|
}
|
|
468
476
|
/**
|
|
469
477
|
* Apply a partial metadata update to an existing object. Returns the
|
|
@@ -511,6 +519,7 @@ export class KoolbaseStorage {
|
|
|
511
519
|
throw await this.error(res, 'Failed to update metadata');
|
|
512
520
|
}
|
|
513
521
|
const raw = await res.json();
|
|
522
|
+
void refreshBucketFiles(bucket);
|
|
514
523
|
return mapObjectFromServer(raw);
|
|
515
524
|
}
|
|
516
525
|
/**
|
|
@@ -642,11 +651,11 @@ export class KoolbaseStorage {
|
|
|
642
651
|
},
|
|
643
652
|
body: JSON.stringify({ bucket, path }),
|
|
644
653
|
});
|
|
645
|
-
if (res.
|
|
654
|
+
if (res.ok) {
|
|
655
|
+
void refreshBucketFiles(bucket);
|
|
646
656
|
return;
|
|
647
|
-
if (!res.ok) {
|
|
648
|
-
throw await this.error(res, 'Failed to delete file');
|
|
649
657
|
}
|
|
658
|
+
throw await this.error(res, 'Failed to delete file');
|
|
650
659
|
}
|
|
651
660
|
/**
|
|
652
661
|
* List all versions of a file path, newest-first. Returns a flat list
|
|
@@ -703,7 +712,9 @@ export class KoolbaseStorage {
|
|
|
703
712
|
if (!res.ok) {
|
|
704
713
|
throw await this.error(res, 'Failed to restore version');
|
|
705
714
|
}
|
|
706
|
-
|
|
715
|
+
const restored = mapObjectFromServer(await res.json());
|
|
716
|
+
void refreshBucketFiles(bucket);
|
|
717
|
+
return restored;
|
|
707
718
|
}
|
|
708
719
|
/**
|
|
709
720
|
* Hard-remove a single history version — both the metadata row and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.20.0",
|
|
4
4
|
"description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|