@zuzjs/flare 0.2.26 → 0.2.28
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/README.md +92 -0
- package/dist/{index-CnmBBd-u.d.cts → index-BDbL-6Rr.d.cts} +2 -2
- package/dist/{index-DPlKzY-d.d.ts → index-DvHbnHDV.d.ts} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +79 -3
- package/dist/react.d.ts +79 -3
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -473,6 +473,98 @@ export function RoomMessages({ roomId }: { roomId: string }) {
|
|
|
473
473
|
}
|
|
474
474
|
```
|
|
475
475
|
|
|
476
|
+
#### React Storage Queue Hook (Start/Pause)
|
|
477
|
+
|
|
478
|
+
```tsx
|
|
479
|
+
import { useMemo } from 'react';
|
|
480
|
+
import { connectApp } from '@zuzjs/flare';
|
|
481
|
+
import { useStorage, Status } from '@zuzjs/flare/react';
|
|
482
|
+
|
|
483
|
+
const app = connectApp({
|
|
484
|
+
endpoint: 'http://localhost:8080',
|
|
485
|
+
appId: 'my-app',
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
export function StorageUploader() {
|
|
489
|
+
const storage = useMemo(() => app.storage(), []);
|
|
490
|
+
|
|
491
|
+
const upload = useStorage(storage, {
|
|
492
|
+
onItemComplete: (item, result) => {
|
|
493
|
+
console.log('uploaded', item.objectKey, result.url);
|
|
494
|
+
},
|
|
495
|
+
onItemError: (item, err) => {
|
|
496
|
+
console.error('upload failed', item.objectKey, err.message);
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const onSelect = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
501
|
+
const files = Array.from(event.target.files ?? []);
|
|
502
|
+
if (!files.length) return;
|
|
503
|
+
|
|
504
|
+
upload.addToQueue(
|
|
505
|
+
files.map((file) => ({
|
|
506
|
+
file,
|
|
507
|
+
bucket: 'attachments',
|
|
508
|
+
key: `uploads/${Date.now()}-${file.name}`,
|
|
509
|
+
contentType: file.type || 'application/octet-stream',
|
|
510
|
+
access: 'public',
|
|
511
|
+
})),
|
|
512
|
+
);
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
return (
|
|
516
|
+
<div>
|
|
517
|
+
<input type='file' multiple onChange={onSelect} />
|
|
518
|
+
|
|
519
|
+
<div style={{ display: 'flex', gap: 8, marginTop: 12 }}>
|
|
520
|
+
<button onClick={() => void upload.start()} disabled={!upload.hasPending || upload.running}>
|
|
521
|
+
Start
|
|
522
|
+
</button>
|
|
523
|
+
<button onClick={upload.pause} disabled={!upload.running}>
|
|
524
|
+
Pause
|
|
525
|
+
</button>
|
|
526
|
+
</div>
|
|
527
|
+
|
|
528
|
+
<ul>
|
|
529
|
+
{upload.que.map((item) => (
|
|
530
|
+
<li key={item.id}>
|
|
531
|
+
{item.objectKey} - {item.progress}% - {Status[item.status]}
|
|
532
|
+
</li>
|
|
533
|
+
))}
|
|
534
|
+
</ul>
|
|
535
|
+
</div>
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
`addToQueue(...)` auto-starts uploads by default.
|
|
541
|
+
|
|
542
|
+
Manual mode example (only upload when `start()` is clicked):
|
|
543
|
+
|
|
544
|
+
```tsx
|
|
545
|
+
const upload = useStorage(storage, {
|
|
546
|
+
autoStartOnAdd: false,
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
upload.addToQueue([
|
|
550
|
+
{
|
|
551
|
+
file,
|
|
552
|
+
bucket: 'attachments',
|
|
553
|
+
key: `uploads/${Date.now()}-${file.name}`,
|
|
554
|
+
},
|
|
555
|
+
]);
|
|
556
|
+
|
|
557
|
+
await upload.start();
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Notes:
|
|
561
|
+
|
|
562
|
+
- Queue items expose `item.objectKey` (not `item.key`) to avoid React prop-name conflicts.
|
|
563
|
+
- `addToQueue(...)` input still uses `key` because it maps directly to `putObject({ key })`.
|
|
564
|
+
- `addToQueue(...)` starts processing immediately unless `autoStartOnAdd: false` or the queue is paused.
|
|
565
|
+
- `pause()` stops scheduling new uploads; it does not cancel an already in-flight request.
|
|
566
|
+
- Call `start()` again to continue with remaining queued items.
|
|
567
|
+
|
|
476
568
|
#### Next.js Example (Client Component)
|
|
477
569
|
|
|
478
570
|
```tsx
|
|
@@ -490,8 +490,8 @@ declare class FlareBase<TPresetMap extends QueryPresetMap = {}> {
|
|
|
490
490
|
onError(callback: ErrorListener): () => void;
|
|
491
491
|
collection<T = any>(name: string): CollectionQuery<T, TPresetMap>;
|
|
492
492
|
/**
|
|
493
|
-
* Generates a
|
|
494
|
-
* UUID v4 without dashes, first
|
|
493
|
+
* Generates a 24-character hex document ID (Mongo ObjectId compatible format).
|
|
494
|
+
* UUID v4 without dashes, first 24 chars.
|
|
495
495
|
*
|
|
496
496
|
* ```ts
|
|
497
497
|
* const id = db.generateFlareId();
|
|
@@ -490,8 +490,8 @@ declare class FlareBase<TPresetMap extends QueryPresetMap = {}> {
|
|
|
490
490
|
onError(callback: ErrorListener): () => void;
|
|
491
491
|
collection<T = any>(name: string): CollectionQuery<T, TPresetMap>;
|
|
492
492
|
/**
|
|
493
|
-
* Generates a
|
|
494
|
-
* UUID v4 without dashes, first
|
|
493
|
+
* Generates a 24-character hex document ID (Mongo ObjectId compatible format).
|
|
494
|
+
* UUID v4 without dashes, first 24 chars.
|
|
495
495
|
*
|
|
496
496
|
* ```ts
|
|
497
497
|
* const id = db.generateFlareId();
|