@vol-a/client 0.0.0-stage → 1.2.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/LICENSE +21 -0
- package/README.md +284 -2
- package/dist/access-tokens.d.ts +21 -0
- package/dist/access-tokens.d.ts.map +1 -0
- package/dist/access-tokens.js +34 -0
- package/dist/access-tokens.js.map +1 -0
- package/dist/body.d.ts +40 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +112 -0
- package/dist/body.js.map +1 -0
- package/dist/client.d.ts +185 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +311 -0
- package/dist/client.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +52 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +93 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +144 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +239 -0
- package/dist/files.js.map +1 -0
- package/dist/folders.d.ts +35 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +62 -0
- package/dist/folders.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/keyrings.d.ts +44 -0
- package/dist/keyrings.d.ts.map +1 -0
- package/dist/keyrings.js +111 -0
- package/dist/keyrings.js.map +1 -0
- package/dist/management.d.ts +47 -0
- package/dist/management.d.ts.map +1 -0
- package/dist/management.js +65 -0
- package/dist/management.js.map +1 -0
- package/dist/shares.d.ts +87 -0
- package/dist/shares.d.ts.map +1 -0
- package/dist/shares.js +144 -0
- package/dist/shares.js.map +1 -0
- package/dist/uploads.d.ts +112 -0
- package/dist/uploads.d.ts.map +1 -0
- package/dist/uploads.js +290 -0
- package/dist/uploads.js.map +1 -0
- package/package.json +48 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type ByteSource } from "./body.js";
|
|
2
|
+
import type { CallOptions, VolaClient } from "./client.js";
|
|
3
|
+
import type { UploadPlacement } from "./files.js";
|
|
4
|
+
/** Default chunk of a resumable upload: 8 MiB. */
|
|
5
|
+
export declare const DEFAULT_CHUNK_SIZE: number;
|
|
6
|
+
/**
|
|
7
|
+
* Where a resumable upload remembers which server-side upload a source belongs to, so a
|
|
8
|
+
* second call with the same source continues it: `localStorage` in a browser, memory in
|
|
9
|
+
* Node, or anything with these three methods (a file, a database).
|
|
10
|
+
*/
|
|
11
|
+
export interface FingerprintStore {
|
|
12
|
+
get(key: string): Promise<string | null | undefined> | string | null | undefined;
|
|
13
|
+
set(key: string, value: string): Promise<void> | void;
|
|
14
|
+
remove(key: string): Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
export declare class MemoryFingerprintStore implements FingerprintStore {
|
|
17
|
+
private readonly map;
|
|
18
|
+
get(key: string): string | null;
|
|
19
|
+
set(key: string, value: string): void;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
}
|
|
22
|
+
/** A `FingerprintStore` over `localStorage` (or any `Storage`). */
|
|
23
|
+
export declare function storageFingerprintStore(storage: Storage): FingerprintStore;
|
|
24
|
+
/** `localStorage` in a browser that has one, the process-wide memory store otherwise. */
|
|
25
|
+
export declare function defaultFingerprintStore(): FingerprintStore;
|
|
26
|
+
export interface UploadProgress {
|
|
27
|
+
/** Bytes the server has (plaintext bytes, also for an encrypted upload). */
|
|
28
|
+
uploaded: number;
|
|
29
|
+
total: number;
|
|
30
|
+
uploadId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ResumableOptions extends UploadPlacement, CallOptions {
|
|
33
|
+
/** Upsert under a slug once complete. */
|
|
34
|
+
slug?: string | undefined;
|
|
35
|
+
/** Bytes per `PATCH`. Default 8 MiB. */
|
|
36
|
+
chunkSize?: number | undefined;
|
|
37
|
+
onProgress?: ((progress: UploadProgress) => void) | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The key the upload is remembered under in the `store`, so a later call with the same
|
|
40
|
+
* source resumes it. Default: derived from the base URL, the instance, the name, the size
|
|
41
|
+
* (and a `File`'s `lastModified`). `false`: never remember, never resume.
|
|
42
|
+
*/
|
|
43
|
+
fingerprint?: string | false | undefined;
|
|
44
|
+
/** Where fingerprints live. Default: `localStorage` in a browser, memory in Node. */
|
|
45
|
+
store?: FingerprintStore | undefined;
|
|
46
|
+
}
|
|
47
|
+
export interface ResumableCreate extends UploadPlacement, CallOptions {
|
|
48
|
+
/** The total size, in bytes (the server does not support a deferred length). */
|
|
49
|
+
length: number;
|
|
50
|
+
filename: string;
|
|
51
|
+
slug?: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
export interface UploadState {
|
|
54
|
+
uploadId: string;
|
|
55
|
+
/** Bytes the server has. */
|
|
56
|
+
offset: number;
|
|
57
|
+
length: number;
|
|
58
|
+
/** The `vola_file` id: of the completed file, or — for an encrypted upload — of the file it will become. */
|
|
59
|
+
fileId: string | null;
|
|
60
|
+
/** When the server drops an unfinished upload. */
|
|
61
|
+
expiresAt: string | null;
|
|
62
|
+
/** The upload's metadata as the server keeps it (`instance_type`, `filename`, …); `HEAD` only. */
|
|
63
|
+
metadata: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
export interface ResumableResult {
|
|
66
|
+
fileId: string;
|
|
67
|
+
uploadId: string;
|
|
68
|
+
}
|
|
69
|
+
export interface UploadProtocol {
|
|
70
|
+
version: string;
|
|
71
|
+
extensions: string[];
|
|
72
|
+
/** `Tus-Max-Size`: the server's upload limit, in bytes. */
|
|
73
|
+
maxSize: number | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resumable uploads (`/uploads`, tus 1.0 core + creation/termination/expiration, which the
|
|
77
|
+
* server implements natively). `resumable()` is the whole flow; `create`, `status`, `append`
|
|
78
|
+
* and `abort` are its steps, for a client that drives them itself.
|
|
79
|
+
*/
|
|
80
|
+
export declare class UploadsApi {
|
|
81
|
+
private readonly client;
|
|
82
|
+
constructor(client: VolaClient);
|
|
83
|
+
/** `OPTIONS /uploads`: the protocol version, the extensions, the size limit. No key needed. */
|
|
84
|
+
protocol(options?: CallOptions): Promise<UploadProtocol>;
|
|
85
|
+
/** `POST /uploads`: creates the upload (`201`); the id comes from `Location`. */
|
|
86
|
+
create(type: string, id: string, input: ResumableCreate): Promise<UploadState>;
|
|
87
|
+
/** `HEAD /uploads/:id`: where the upload stands. `404 upload_not_found` / `410` throw. */
|
|
88
|
+
status(uploadId: string, options?: CallOptions): Promise<UploadState>;
|
|
89
|
+
/**
|
|
90
|
+
* `PATCH /uploads/:id`: `chunk` from `offset` on. Resolves with the new offset and, when the
|
|
91
|
+
* upload is complete, the file id. A `keyring` upload needs the unlock token and a `caller`
|
|
92
|
+
* upload the content key on EVERY call (each one unwraps the file key).
|
|
93
|
+
*/
|
|
94
|
+
append(uploadId: string, chunk: Blob | Uint8Array, offset: number, options?: CallOptions): Promise<{
|
|
95
|
+
offset: number;
|
|
96
|
+
fileId: string | null;
|
|
97
|
+
}>;
|
|
98
|
+
/** `DELETE /uploads/:id`: drops the upload and its partial bytes. */
|
|
99
|
+
abort(uploadId: string, options?: CallOptions): Promise<void>;
|
|
100
|
+
/** The default fingerprint of a source. */
|
|
101
|
+
fingerprintOf(type: string, id: string, source: ByteSource, filename: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* The whole resumable flow: remembers the upload under its fingerprint, `HEAD`s a remembered
|
|
104
|
+
* one for its offset (a vanished one is forgotten and started again), creates a new one
|
|
105
|
+
* otherwise, `PATCH`es `chunkSize` bytes at a time from the offset on, reports progress, and
|
|
106
|
+
* resolves with the file id. An abort (`signal`) or a network failure mid-`PATCH` rejects
|
|
107
|
+
* and keeps the fingerprint: the next call with the same source continues where the server
|
|
108
|
+
* stands. A `409` (the server's offset moved) re-reads the offset and goes on.
|
|
109
|
+
*/
|
|
110
|
+
resumable(type: string, id: string, source: ByteSource, options?: ResumableOptions): Promise<ResumableResult>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=uploads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../src/uploads.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,UAAU,EAAmD,MAAM,WAAW,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAAkB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACjF,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA6B;IACjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAG/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAGrC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG1B;AAED,mEAAmE;AACnE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAM1E;AAID,yFAAyF;AACzF,wBAAgB,uBAAuB,IAAI,gBAAgB,CAS1D;AAED,MAAM,WAAW,cAAc;IAC7B,4EAA4E;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AX_SIZE_HEADER, TUS_PATCH_CONTENT_TYPE, TUS_RESUMABLE_HEADER, TUS_VERSION, TUS_VERSION_HEADER, UPLOAD_EXPIRES_HEADER, UPLOAD_LENGTH_HEADER, UPLOAD_META_KEYS, UPLOAD_METADATA_HEADER, UPLOAD_OFFSET_HEADER, VOLA_FILE_ID_HEADER, } from "@vol-a/core";
|
|
2
|
+
import { isStreamSource, nameOf, sizeOf, sliceOf, typeOf } from "./body.js";
|
|
3
|
+
import { isBrowser } from "./env.js";
|
|
4
|
+
import { VolaError } from "./errors.js";
|
|
5
|
+
/** Default chunk of a resumable upload: 8 MiB. */
|
|
6
|
+
export const DEFAULT_CHUNK_SIZE = 8 * 1024 * 1024;
|
|
7
|
+
export class MemoryFingerprintStore {
|
|
8
|
+
map = new Map();
|
|
9
|
+
get(key) {
|
|
10
|
+
return this.map.get(key) ?? null;
|
|
11
|
+
}
|
|
12
|
+
set(key, value) {
|
|
13
|
+
this.map.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
remove(key) {
|
|
16
|
+
this.map.delete(key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** A `FingerprintStore` over `localStorage` (or any `Storage`). */
|
|
20
|
+
export function storageFingerprintStore(storage) {
|
|
21
|
+
return {
|
|
22
|
+
get: (key) => storage.getItem(key),
|
|
23
|
+
set: (key, value) => storage.setItem(key, value),
|
|
24
|
+
remove: (key) => storage.removeItem(key),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const memoryStore = new MemoryFingerprintStore();
|
|
28
|
+
/** `localStorage` in a browser that has one, the process-wide memory store otherwise. */
|
|
29
|
+
export function defaultFingerprintStore() {
|
|
30
|
+
if (isBrowser() && typeof localStorage !== "undefined") {
|
|
31
|
+
try {
|
|
32
|
+
return storageFingerprintStore(localStorage);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// a page that forbids storage
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return memoryStore;
|
|
39
|
+
}
|
|
40
|
+
/** Thrown by `resumable()` for a source that cannot be sliced (a stream): the upload would not be resumable. */
|
|
41
|
+
function notSliceable() {
|
|
42
|
+
return new VolaError({
|
|
43
|
+
status: 0,
|
|
44
|
+
code: "bad_request",
|
|
45
|
+
message: "resumable upload: the source must be a Blob/File, a Uint8Array/Buffer or an ArrayBuffer (something that can be sized and sliced); for a stream use files.upload()",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const tus = { [TUS_RESUMABLE_HEADER]: TUS_VERSION };
|
|
49
|
+
function header(response, name) {
|
|
50
|
+
return response.headers.get(name);
|
|
51
|
+
}
|
|
52
|
+
function offsetOf(response) {
|
|
53
|
+
const raw = header(response, UPLOAD_OFFSET_HEADER);
|
|
54
|
+
if (raw === null || !/^\d+$/.test(raw)) {
|
|
55
|
+
throw new VolaError({
|
|
56
|
+
status: response.status,
|
|
57
|
+
code: "invalid_response",
|
|
58
|
+
message: `${UPLOAD_OFFSET_HEADER}: the server did not say where the upload stands`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return Number(raw);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resumable uploads (`/uploads`, tus 1.0 core + creation/termination/expiration, which the
|
|
65
|
+
* server implements natively). `resumable()` is the whole flow; `create`, `status`, `append`
|
|
66
|
+
* and `abort` are its steps, for a client that drives them itself.
|
|
67
|
+
*/
|
|
68
|
+
export class UploadsApi {
|
|
69
|
+
client;
|
|
70
|
+
constructor(client) {
|
|
71
|
+
this.client = client;
|
|
72
|
+
}
|
|
73
|
+
/** `OPTIONS /uploads`: the protocol version, the extensions, the size limit. No key needed. */
|
|
74
|
+
async protocol(options = {}) {
|
|
75
|
+
const response = await this.client.request("/uploads", {
|
|
76
|
+
method: "OPTIONS",
|
|
77
|
+
anonymous: true,
|
|
78
|
+
signal: options.signal,
|
|
79
|
+
});
|
|
80
|
+
const max = header(response, TUS_MAX_SIZE_HEADER);
|
|
81
|
+
return {
|
|
82
|
+
version: header(response, TUS_VERSION_HEADER) ?? TUS_VERSION,
|
|
83
|
+
extensions: (header(response, TUS_EXTENSION_HEADER) ?? "").split(",").filter(Boolean),
|
|
84
|
+
maxSize: max !== null && /^\d+$/.test(max) ? Number(max) : null,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** `POST /uploads`: creates the upload (`201`); the id comes from `Location`. */
|
|
88
|
+
async create(type, id, input) {
|
|
89
|
+
const K = UPLOAD_META_KEYS;
|
|
90
|
+
const metadata = encodeTusMetadata({
|
|
91
|
+
[K.instanceType]: type,
|
|
92
|
+
[K.instanceId]: id,
|
|
93
|
+
[K.filename]: input.filename,
|
|
94
|
+
[K.folderPath]: input.folderPath,
|
|
95
|
+
[K.parentId]: input.parentId,
|
|
96
|
+
[K.slug]: input.slug,
|
|
97
|
+
[K.contentType]: input.contentType,
|
|
98
|
+
[K.metadata]: input.metadata === undefined ? undefined : JSON.stringify(input.metadata),
|
|
99
|
+
[K.encryption]: input.encryption,
|
|
100
|
+
});
|
|
101
|
+
if (input.folderId !== undefined) {
|
|
102
|
+
throw new VolaError({
|
|
103
|
+
status: 0,
|
|
104
|
+
code: "bad_request",
|
|
105
|
+
message: "resumable upload: the folder is named by folderPath (folderId is not part of the tus metadata)",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const response = await this.client.request("/uploads", {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: {
|
|
111
|
+
...tus,
|
|
112
|
+
[UPLOAD_LENGTH_HEADER]: String(input.length),
|
|
113
|
+
[UPLOAD_METADATA_HEADER]: metadata,
|
|
114
|
+
[ENCRYPTION_HEADER]: input.encryption,
|
|
115
|
+
},
|
|
116
|
+
signal: input.signal,
|
|
117
|
+
unlock: input.unlock,
|
|
118
|
+
contentKey: input.contentKey,
|
|
119
|
+
});
|
|
120
|
+
const location = header(response, "location");
|
|
121
|
+
const uploadId = location?.split("/").pop();
|
|
122
|
+
if (!uploadId) {
|
|
123
|
+
throw new VolaError({
|
|
124
|
+
status: response.status,
|
|
125
|
+
code: "invalid_response",
|
|
126
|
+
message: "POST /uploads: no Location header",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
await response.body?.cancel().catch(() => undefined);
|
|
130
|
+
return {
|
|
131
|
+
uploadId,
|
|
132
|
+
offset: offsetOf(response),
|
|
133
|
+
length: input.length,
|
|
134
|
+
fileId: header(response, VOLA_FILE_ID_HEADER),
|
|
135
|
+
expiresAt: header(response, UPLOAD_EXPIRES_HEADER),
|
|
136
|
+
metadata: {},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** `HEAD /uploads/:id`: where the upload stands. `404 upload_not_found` / `410` throw. */
|
|
140
|
+
async status(uploadId, options = {}) {
|
|
141
|
+
const response = await this.client.request(`/uploads/${encodeURIComponent(uploadId)}`, {
|
|
142
|
+
method: "HEAD",
|
|
143
|
+
headers: tus,
|
|
144
|
+
...options,
|
|
145
|
+
});
|
|
146
|
+
const length = header(response, UPLOAD_LENGTH_HEADER);
|
|
147
|
+
return {
|
|
148
|
+
uploadId,
|
|
149
|
+
offset: offsetOf(response),
|
|
150
|
+
length: length !== null && /^\d+$/.test(length) ? Number(length) : 0,
|
|
151
|
+
fileId: header(response, VOLA_FILE_ID_HEADER),
|
|
152
|
+
expiresAt: header(response, UPLOAD_EXPIRES_HEADER),
|
|
153
|
+
metadata: decodeTusMetadata(header(response, UPLOAD_METADATA_HEADER)) ?? {},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* `PATCH /uploads/:id`: `chunk` from `offset` on. Resolves with the new offset and, when the
|
|
158
|
+
* upload is complete, the file id. A `keyring` upload needs the unlock token and a `caller`
|
|
159
|
+
* upload the content key on EVERY call (each one unwraps the file key).
|
|
160
|
+
*/
|
|
161
|
+
async append(uploadId, chunk, offset, options = {}) {
|
|
162
|
+
const response = await this.client.request(`/uploads/${encodeURIComponent(uploadId)}`, {
|
|
163
|
+
method: "PATCH",
|
|
164
|
+
headers: {
|
|
165
|
+
...tus,
|
|
166
|
+
"content-type": TUS_PATCH_CONTENT_TYPE,
|
|
167
|
+
[UPLOAD_OFFSET_HEADER]: String(offset),
|
|
168
|
+
},
|
|
169
|
+
body: chunk instanceof Uint8Array ? chunk.slice() : chunk,
|
|
170
|
+
...options,
|
|
171
|
+
});
|
|
172
|
+
await response.body?.cancel().catch(() => undefined);
|
|
173
|
+
return { offset: offsetOf(response), fileId: header(response, VOLA_FILE_ID_HEADER) };
|
|
174
|
+
}
|
|
175
|
+
/** `DELETE /uploads/:id`: drops the upload and its partial bytes. */
|
|
176
|
+
async abort(uploadId, options = {}) {
|
|
177
|
+
const response = await this.client.request(`/uploads/${encodeURIComponent(uploadId)}`, {
|
|
178
|
+
method: "DELETE",
|
|
179
|
+
headers: tus,
|
|
180
|
+
...options,
|
|
181
|
+
});
|
|
182
|
+
await response.body?.cancel().catch(() => undefined);
|
|
183
|
+
}
|
|
184
|
+
/** The default fingerprint of a source. */
|
|
185
|
+
fingerprintOf(type, id, source, filename) {
|
|
186
|
+
const modified = typeof Blob !== "undefined" && source instanceof Blob && "lastModified" in source
|
|
187
|
+
? String(source.lastModified)
|
|
188
|
+
: "";
|
|
189
|
+
return `vola-upload:${this.client.baseUrl}:${type}/${id}:${filename}:${sizeOf(source)}:${modified}`;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The whole resumable flow: remembers the upload under its fingerprint, `HEAD`s a remembered
|
|
193
|
+
* one for its offset (a vanished one is forgotten and started again), creates a new one
|
|
194
|
+
* otherwise, `PATCH`es `chunkSize` bytes at a time from the offset on, reports progress, and
|
|
195
|
+
* resolves with the file id. An abort (`signal`) or a network failure mid-`PATCH` rejects
|
|
196
|
+
* and keeps the fingerprint: the next call with the same source continues where the server
|
|
197
|
+
* stands. A `409` (the server's offset moved) re-reads the offset and goes on.
|
|
198
|
+
*/
|
|
199
|
+
async resumable(type, id, source, options = {}) {
|
|
200
|
+
if (isStreamSource(source))
|
|
201
|
+
throw notSliceable();
|
|
202
|
+
const filename = options.filename ?? nameOf(source);
|
|
203
|
+
if (!filename) {
|
|
204
|
+
throw new VolaError({
|
|
205
|
+
status: 0,
|
|
206
|
+
code: "bad_request",
|
|
207
|
+
message: "resumable upload: filename is required when the source is not a File",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const total = sizeOf(source);
|
|
211
|
+
const chunkSize = Math.max(1, options.chunkSize ?? DEFAULT_CHUNK_SIZE);
|
|
212
|
+
const store = options.fingerprint === false ? null : (options.store ?? defaultFingerprintStore());
|
|
213
|
+
const key = options.fingerprint === false
|
|
214
|
+
? null
|
|
215
|
+
: (options.fingerprint ?? this.fingerprintOf(type, id, source, filename));
|
|
216
|
+
const call = {
|
|
217
|
+
signal: options.signal,
|
|
218
|
+
unlock: options.unlock,
|
|
219
|
+
contentKey: options.contentKey,
|
|
220
|
+
};
|
|
221
|
+
let state = null;
|
|
222
|
+
if (store && key) {
|
|
223
|
+
const remembered = await store.get(key);
|
|
224
|
+
if (remembered) {
|
|
225
|
+
try {
|
|
226
|
+
state = await this.status(remembered, call);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (!(error instanceof VolaError) || (error.status !== 404 && error.status !== 410)) {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
await store.remove(key);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!state) {
|
|
237
|
+
state = await this.create(type, id, {
|
|
238
|
+
length: total,
|
|
239
|
+
filename,
|
|
240
|
+
contentType: options.contentType ?? typeOf(source),
|
|
241
|
+
folderPath: options.folderPath,
|
|
242
|
+
parentId: options.parentId,
|
|
243
|
+
slug: options.slug,
|
|
244
|
+
metadata: options.metadata,
|
|
245
|
+
encryption: options.encryption,
|
|
246
|
+
...call,
|
|
247
|
+
});
|
|
248
|
+
if (store && key)
|
|
249
|
+
await store.set(key, state.uploadId);
|
|
250
|
+
}
|
|
251
|
+
let offset = state.offset;
|
|
252
|
+
let fileId = state.fileId;
|
|
253
|
+
let conflicts = 0;
|
|
254
|
+
options.onProgress?.({ uploaded: offset, total, uploadId: state.uploadId });
|
|
255
|
+
while (offset < total || (total === 0 && fileId === null)) {
|
|
256
|
+
const end = Math.min(offset + chunkSize, total);
|
|
257
|
+
try {
|
|
258
|
+
const result = await this.append(state.uploadId, sliceOf(source, offset, end), offset, call);
|
|
259
|
+
offset = result.offset;
|
|
260
|
+
fileId = result.fileId ?? fileId;
|
|
261
|
+
conflicts = 0;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (error instanceof VolaError && error.status === 409 && conflicts++ < 3) {
|
|
265
|
+
offset = (await this.status(state.uploadId, call)).offset;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
options.onProgress?.({ uploaded: offset, total, uploadId: state.uploadId });
|
|
271
|
+
if (total === 0)
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
if (offset >= total && fileId === null) {
|
|
275
|
+
// The last PATCH answered without the id (a proxy dropped the header): ask.
|
|
276
|
+
fileId = (await this.status(state.uploadId, call)).fileId;
|
|
277
|
+
}
|
|
278
|
+
if (fileId === null) {
|
|
279
|
+
throw new VolaError({
|
|
280
|
+
status: 0,
|
|
281
|
+
code: "invalid_response",
|
|
282
|
+
message: "resumable upload: complete, but the server did not name the file",
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
if (store && key)
|
|
286
|
+
await store.remove(key);
|
|
287
|
+
return { fileId, uploadId: state.uploadId };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=uploads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.js","sourceRoot":"","sources":["../src/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,oBAA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CAAC;gBAAE,MAAM;QACzB,CAAC;QACD,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACvC,4EAA4E;YAC5E,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5D,CAAC;QACD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,MAAM,IAAI,SAAS,CAAC;gBAClB,MAAM,EAAE,CAAC;gBACT,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,kEAAkE;aAC5E,CAAC,CAAC;QACL,CAAC;QACD,IAAI,KAAK,IAAI,GAAG;YAAE,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC9C,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vol-a/client",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "JSVola client SDK: a fetch-based, dependency-light client for the @vol-a/server API — files, folders, resumable uploads, shares, keyrings, stats — for Node 24+ and browsers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/digital-cube/jsvola.git",
|
|
9
|
+
"directory": "packages/client"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/digital-cube/jsvola#readme",
|
|
12
|
+
"bugs": "https://github.com/digital-cube/jsvola/issues",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"@vol-a/source": "./src/index.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@jsudc/core": "0.3.0",
|
|
30
|
+
"@vol-a/core": "1.2.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"vola",
|
|
37
|
+
"jsvola",
|
|
38
|
+
"file-storage",
|
|
39
|
+
"upload",
|
|
40
|
+
"resumable",
|
|
41
|
+
"tus",
|
|
42
|
+
"client",
|
|
43
|
+
"sdk"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.build.json",
|
|
47
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:cov": "vitest run --coverage"
|
|
50
|
+
}
|
|
6
51
|
}
|