@webx-ui/module-admin 0.19.0 → 0.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.
@@ -0,0 +1,79 @@
1
+ import { Ref } from 'vue';
2
+ import { AdminContext } from './admin';
3
+ /**
4
+ * Large files a piece at a time, through the panel's own four requests (§4 of the video spec):
5
+ *
6
+ * POST uploads { name, size, type, fingerprint, purpose } → { id, offset, size, chunk_size }
7
+ * HEAD uploads/{id} → Upload-Offset
8
+ * PATCH uploads/{id} a piece, Upload-Offset: n → 204, Upload-Offset: n + length
9
+ * DELETE uploads/{id}
10
+ *
11
+ * The server holds the offset and the client follows it: a 409 names where the file really
12
+ * ends, a HEAD asks after a dropped connection, and the same file chosen again after a reload
13
+ * finds its session by the fingerprint. What the server cannot know is the web server's own
14
+ * limit, so a 413 halves the piece — down to 256 KB — and the smaller piece stays for the rest
15
+ * of the file.
16
+ */
17
+ export type ChunkedUploadState = 'idle' | 'uploading' | 'paused' | 'offline' | 'done' | 'failed';
18
+ /** An upload that did not finish, as remembered in this browser for the next visit. */
19
+ export interface UnfinishedUpload {
20
+ fingerprint: string;
21
+ purpose: string;
22
+ name: string;
23
+ size: number;
24
+ offset: number;
25
+ /** Milliseconds since the epoch, of the last piece that landed. */
26
+ updatedAt: number;
27
+ }
28
+ export interface ChunkedUploadOptions {
29
+ /** The panel to talk to; `useAdmin()` when left out. */
30
+ admin?: Pick<AdminContext, 'http' | 'apiPath'>;
31
+ /** Where unfinished uploads are remembered; `localStorage` when left out, `null` for nowhere. */
32
+ storage?: Storage | null;
33
+ /** How many times a piece lost to the network is sent again before the upload fails. */
34
+ retries?: number;
35
+ /** The wait before the first of those, doubled for each after it. */
36
+ retryDelay?: number;
37
+ }
38
+ export interface ChunkedUpload {
39
+ readonly state: Readonly<Ref<ChunkedUploadState>>;
40
+ /** 0 to 1. */
41
+ readonly progress: Readonly<Ref<number>>;
42
+ /** Bytes the server has. */
43
+ readonly uploaded: Readonly<Ref<number>>;
44
+ readonly total: Readonly<Ref<number>>;
45
+ /** Bytes a second, over the last few seconds; 0 until there is something to measure. */
46
+ readonly speed: Readonly<Ref<number>>;
47
+ /** Seconds left at that speed, or null while there is no speed to go by. */
48
+ readonly remaining: Readonly<Ref<number | null>>;
49
+ /** The session's id, which is what the module the file was for claims it by. */
50
+ readonly id: Readonly<Ref<string | null>>;
51
+ readonly error: Readonly<Ref<Error | null>>;
52
+ /**
53
+ * Send a file. Resolves with the session's id once the whole of it is on the server, with
54
+ * null when it is cancelled; rejects when it fails. A pause does neither — the same promise
55
+ * resolves once the upload is resumed and finished.
56
+ */
57
+ start(file: File, purpose: string): Promise<string | null>;
58
+ pause(): void;
59
+ /** Carry on after a pause, going offline or a failure; the promise of the upload. */
60
+ resume(): Promise<string | null>;
61
+ /** Stop and throw away what the server has. */
62
+ cancel(): Promise<void>;
63
+ }
64
+ /** The smallest piece the client falls back to on a 413 (the server never advises less). */
65
+ export declare const MIN_CHUNK: number;
66
+ /**
67
+ * What identifies a file without reading it: the same name, size and date of change is taken
68
+ * for the same file. Cheap on purpose — hashing gigabytes to find out where to resume would take
69
+ * longer than a good part of the upload.
70
+ */
71
+ export declare function uploadFingerprint(file: Pick<File, 'name' | 'size' | 'lastModified'>): string;
72
+ /**
73
+ * The uploads this browser started and did not finish — what a panel offers to continue after a
74
+ * reload ("choose the same file"). Empty wherever storage is refused.
75
+ */
76
+ export declare function unfinishedUploads(purpose?: string, storage?: Storage | null): UnfinishedUpload[];
77
+ /** Stop offering to continue an upload — the person chose not to. */
78
+ export declare function forgetUnfinishedUpload(fingerprint: string, purpose: string, storage?: Storage | null): void;
79
+ export declare function useChunkedUpload(options?: ChunkedUploadOptions): ChunkedUpload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webx-ui/module-admin",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "The frame a WebX UI admin panel runs in: bootstrap, the shell, the HTTP client and the module registry that pairs with webx-ui/module-admin on the server.",
5
5
  "license": "MIT",
6
6
  "type": "module",