capacitor-background-transfer 0.0.0-stage → 0.1.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/CapacitorBackgroundTransfer.podspec +19 -0
- package/LICENSE +21 -0
- package/Package.swift +31 -0
- package/README.md +542 -2
- package/android/build.gradle +71 -0
- package/android/src/main/AndroidManifest.xml +20 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/AzureBlockUploader.java +148 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/BackgroundTransferPlugin.java +279 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Downloader.java +244 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Http.java +238 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/JobRuns.java +40 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Notifications.java +54 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Parts.java +25 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/PartsXml.java +199 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Pause.java +28 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Progress.java +13 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/PutUploader.java +47 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Runner.java +369 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/S3MultipartUploader.java +143 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Scheduler.java +144 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferException.java +65 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferJobService.java +115 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferPaths.java +129 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferRecord.java +163 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferStore.java +121 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/TransferWorker.java +85 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/UploadAdapter.java +11 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/UploadAdapters.java +89 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/UploadOptionsCheck.java +104 -0
- package/android/src/main/java/io/github/sandman92/backgroundtransfer/Uploader.java +225 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +527 -0
- package/dist/esm/definitions.d.ts +277 -0
- package/dist/esm/definitions.js +24 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/validate.d.ts +18 -0
- package/dist/esm/validate.js +113 -0
- package/dist/esm/validate.js.map +1 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +27 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +200 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +203 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/BackgroundTransferCore/Files.swift +166 -0
- package/ios/Sources/BackgroundTransferCore/PartsUpload.swift +327 -0
- package/ios/Sources/BackgroundTransferCore/PartsXML.swift +137 -0
- package/ios/Sources/BackgroundTransferCore/TransferPaths.swift +103 -0
- package/ios/Sources/BackgroundTransferCore/TransferRecord.swift +141 -0
- package/ios/Sources/BackgroundTransferCore/TransferStore.swift +69 -0
- package/ios/Sources/BackgroundTransferCore/UploadOptionsCheck.swift +90 -0
- package/ios/Sources/BackgroundTransferCore/UploadOutcome.swift +96 -0
- package/ios/Sources/BackgroundTransferCore/UploadProtocol.swift +30 -0
- package/ios/Sources/BackgroundTransferPlugin/BackgroundTransferPlugin.swift +168 -0
- package/ios/Sources/BackgroundTransferPlugin/TransferManager.swift +1074 -0
- package/package.json +96 -4
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
/** Which way a transfer moves bytes. */
|
|
3
|
+
export type TransferDirection = 'upload' | 'download';
|
|
4
|
+
/**
|
|
5
|
+
* Where a transfer is.
|
|
6
|
+
*
|
|
7
|
+
* - `queued`: waiting its turn (one transfer runs per direction), or waiting
|
|
8
|
+
* for the network on Android 14+, where the system restarts it.
|
|
9
|
+
* - `running`: bytes are moving.
|
|
10
|
+
* - `interrupted`: stopped by a network drop, the app being swiped away or
|
|
11
|
+
* the system, and won't restart by itself. Start it again with the same
|
|
12
|
+
* `id` and it carries on from where it stopped.
|
|
13
|
+
* - `finished`: every byte landed. For a download the file is at `path`.
|
|
14
|
+
* - `failed`: it can't finish as asked; `reason` says why. Its temporary
|
|
15
|
+
* files are gone.
|
|
16
|
+
* - `cancelled`: `cancel()` was called. Its temporary files are gone.
|
|
17
|
+
*/
|
|
18
|
+
export type TransferState = 'queued' | 'running' | 'interrupted' | 'finished' | 'failed' | 'cancelled';
|
|
19
|
+
/**
|
|
20
|
+
* Why a transfer stopped without finishing.
|
|
21
|
+
*
|
|
22
|
+
* - `file-missing`: the upload's file isn't there (or is a directory).
|
|
23
|
+
* - `disk-full`: no space for a download, or for the remainder copy an
|
|
24
|
+
* iPhone upload needs to resume part-way.
|
|
25
|
+
* - `session-refused`: the server refused the request (HTTP 4xx other than
|
|
26
|
+
* the two below), e.g. Firebase Storage security rules refused the upload at finalize (403), or
|
|
27
|
+
* a presigned URL or SAS token expired or lacks a permission (403). `message` names the
|
|
28
|
+
* request that was refused (a part, a block, the `PUT`, or the commit).
|
|
29
|
+
* - `session-expired`: the upload session or download URL is gone (HTTP 404
|
|
30
|
+
* or 410), e.g. an S3 multipart upload that was aborted, found out while
|
|
31
|
+
* sending a part or asking ListParts. Start a new session. (An S3 upload
|
|
32
|
+
* found gone only at the completion reports `session-closed`: it may have
|
|
33
|
+
* been completed.)
|
|
34
|
+
* - `session-closed`: the upload can't be confirmed from here. For `firebase-resumable`, the
|
|
35
|
+
* session was already closed when the upload started; that isn't proof the object was accepted
|
|
36
|
+
* (the Firebase Storage emulator closes a session whose finalize its security rules refused).
|
|
37
|
+
* For `s3-multipart` and `azure-blocks`, the request that completes the object was sent in an
|
|
38
|
+
* earlier run (or earlier in this one) and its answer never came, so it may or may not have
|
|
39
|
+
* been applied. Either way, check the object on the server, and start a new upload if it
|
|
40
|
+
* isn't there or is the wrong size.
|
|
41
|
+
* - `size-mismatch`: the bytes that landed don't add up to the size the
|
|
42
|
+
* server or file said.
|
|
43
|
+
* - `network`: the connection dropped. Used with `interrupted`.
|
|
44
|
+
* - `stopped-by-system`: the system ended the work (the app was swiped away
|
|
45
|
+
* on iPhone, the work was stopped below Android 14). Used with
|
|
46
|
+
* `interrupted`.
|
|
47
|
+
* - `cancelled`: `cancel()` was called.
|
|
48
|
+
* - `server-error`: the server kept answering 5xx.
|
|
49
|
+
* - `unknown`: anything else; `message` has the detail.
|
|
50
|
+
*/
|
|
51
|
+
export type TransferFailureReason = 'file-missing' | 'disk-full' | 'session-refused' | 'session-expired' | 'session-closed' | 'size-mismatch' | 'network' | 'stopped-by-system' | 'cancelled' | 'server-error' | 'unknown';
|
|
52
|
+
/** What Android shows while a transfer runs. Ignored on iPhone. */
|
|
53
|
+
export interface TransferNotification {
|
|
54
|
+
/** Notification channel id. Default `background-transfer`. */
|
|
55
|
+
channelId?: string;
|
|
56
|
+
/** The channel's name in system settings, used when the channel is first created. Default `Transfers`. */
|
|
57
|
+
channelName?: string;
|
|
58
|
+
/** Default `Uploading` or `Downloading`. */
|
|
59
|
+
title?: string;
|
|
60
|
+
/** Optional second line. */
|
|
61
|
+
text?: string;
|
|
62
|
+
}
|
|
63
|
+
interface TransferOptionsBase {
|
|
64
|
+
/**
|
|
65
|
+
* Your id for the transfer, unique per direction. Starting a transfer with
|
|
66
|
+
* the id of one that is `interrupted`, `failed` or `cancelled` starts it
|
|
67
|
+
* again (an upload asks the server for its offset; a download resumes from
|
|
68
|
+
* its `.part` file). Starting one that is `queued` or `running` changes
|
|
69
|
+
* nothing and returns its current record. Starting an upload with the id
|
|
70
|
+
* of a `finished` one reports `failed` (`session-closed`) for every
|
|
71
|
+
* protocol but `put`: its session is closed, so start a new session to send
|
|
72
|
+
* the file again. A `put` sends the whole file again.
|
|
73
|
+
*/
|
|
74
|
+
id: string;
|
|
75
|
+
/**
|
|
76
|
+
* Absolute path or `file://` URI of the local file: the file to send, or
|
|
77
|
+
* where the downloaded file goes.
|
|
78
|
+
*/
|
|
79
|
+
path: string;
|
|
80
|
+
/**
|
|
81
|
+
* Extra request headers sent on every request of this transfer (for an
|
|
82
|
+
* upload in parts: every part, block, query and the commit). None by
|
|
83
|
+
* default: an upload sends no `Authorization` header unless you pass one.
|
|
84
|
+
*/
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
/** Android only. */
|
|
87
|
+
notification?: TransferNotification;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The upload protocol a transfer speaks. The plugin never signs anything: you
|
|
91
|
+
* create the upload on the server and hand the plugin URLs that carry their
|
|
92
|
+
* own authorisation (a session URL, presigned URLs, a SAS URL).
|
|
93
|
+
*
|
|
94
|
+
* - `firebase-resumable`: a Firebase Storage resumable upload (the
|
|
95
|
+
* `X-Goog-Upload-*` protocol: `POST` with `X-Goog-Upload-Command` `query`,
|
|
96
|
+
* `upload` and `upload, finalize`). `url` is the session URL.
|
|
97
|
+
* - `put`: the whole file in one `PUT` to `url`, e.g. an S3 presigned `PUT`
|
|
98
|
+
* URL or an Azure blob SAS URL (pass `x-ms-blob-type: BlockBlob` in
|
|
99
|
+
* `headers` for Azure). An interrupted upload starts again from the first
|
|
100
|
+
* byte. S3 takes at most 5 GB in one `PUT`.
|
|
101
|
+
* - `s3-multipart`: an S3 (or S3-compatible) multipart upload you have
|
|
102
|
+
* created. `partUrls` are the presigned `UploadPart` URLs, part 1 first;
|
|
103
|
+
* `url` is the presigned `CompleteMultipartUpload` URL. The plugin sends the
|
|
104
|
+
* parts one at a time, keeps each `ETag`, skips the parts already stored when
|
|
105
|
+
* it resumes, then completes the upload listing every part.
|
|
106
|
+
* - `azure-blocks`: an Azure block blob. `url` is the blob's SAS URL with
|
|
107
|
+
* write permission (`sp` including `w`, or `c` and `w`). The plugin sends
|
|
108
|
+
* blocks with stable ids (`Put Block`), skips the ones in the blob's
|
|
109
|
+
* uncommitted block list when it resumes, then commits them
|
|
110
|
+
* (`Put Block List`).
|
|
111
|
+
*/
|
|
112
|
+
export type UploadProtocol = 'firebase-resumable' | 'put' | 's3-multipart' | 'azure-blocks';
|
|
113
|
+
/** The protocols this version knows. */
|
|
114
|
+
export declare const UPLOAD_PROTOCOLS: readonly UploadProtocol[];
|
|
115
|
+
/** The limits the plugin checks for `s3-multipart` and `azure-blocks`. */
|
|
116
|
+
export declare const UPLOAD_LIMITS: {
|
|
117
|
+
/** Default `partSize` and `blockSize`: 8 MiB. */
|
|
118
|
+
readonly defaultPartSize: number;
|
|
119
|
+
/** S3's smallest part, other than the last: 5 MiB. */
|
|
120
|
+
readonly s3MinPartSize: number;
|
|
121
|
+
/** S3's largest part: 5 GiB. */
|
|
122
|
+
readonly s3MaxPartSize: number;
|
|
123
|
+
/** S3's most parts in one upload. */
|
|
124
|
+
readonly s3MaxParts: 10000;
|
|
125
|
+
/** Azure's largest block: 4000 MiB. */
|
|
126
|
+
readonly azureMaxBlockSize: number;
|
|
127
|
+
/** Azure's most blocks in one blob. */
|
|
128
|
+
readonly azureMaxBlocks: 50000;
|
|
129
|
+
};
|
|
130
|
+
export interface UploadOptions extends TransferOptionsBase {
|
|
131
|
+
/**
|
|
132
|
+
* Where the upload goes, which depends on `protocol`:
|
|
133
|
+
*
|
|
134
|
+
* - `firebase-resumable`: the session URL of an upload you have already
|
|
135
|
+
* started (the `X-Goog-Upload-URL` from its `start`). The plugin asks it
|
|
136
|
+
* how many bytes it holds, sends the rest and finalizes.
|
|
137
|
+
* - `put`: the URL to `PUT` the whole file to.
|
|
138
|
+
* - `s3-multipart`: the presigned `CompleteMultipartUpload` URL (`POST`,
|
|
139
|
+
* with the upload's `uploadId`).
|
|
140
|
+
* - `azure-blocks`: the blob's SAS URL (with its `sig` parameter). The
|
|
141
|
+
* blob's properties go in `headers` as `x-ms-blob-content-type` and the
|
|
142
|
+
* other `x-ms-blob-*` headers: they are sent with the commit only.
|
|
143
|
+
*/
|
|
144
|
+
url: string;
|
|
145
|
+
/**
|
|
146
|
+
* The protocol the upload speaks. Default `firebase-resumable`. An
|
|
147
|
+
* unknown value is refused.
|
|
148
|
+
*/
|
|
149
|
+
protocol?: UploadProtocol;
|
|
150
|
+
/**
|
|
151
|
+
* `s3-multipart` only, and required there: the presigned `UploadPart` URL
|
|
152
|
+
* of every part, part 1 first. There must be exactly as many as the file
|
|
153
|
+
* needs in `partSize` parts (at most 10,000). They must stay valid until
|
|
154
|
+
* the last part is sent.
|
|
155
|
+
*/
|
|
156
|
+
partUrls?: string[];
|
|
157
|
+
/**
|
|
158
|
+
* `s3-multipart` only: the size of every part but the last, in bytes.
|
|
159
|
+
* Default 8 MiB. At least 5 MiB when there is more than one part, at most
|
|
160
|
+
* 5 GiB.
|
|
161
|
+
*/
|
|
162
|
+
partSize?: number;
|
|
163
|
+
/**
|
|
164
|
+
* `s3-multipart` only, optional: the presigned `ListParts` URL (`GET`, with
|
|
165
|
+
* the `uploadId`). When it is given, a resumed upload asks the server which
|
|
166
|
+
* parts it holds instead of trusting the plugin's own record, so a part
|
|
167
|
+
* the server lost is sent again and fresh URLs for the same upload carry on
|
|
168
|
+
* where the old ones stopped.
|
|
169
|
+
*/
|
|
170
|
+
listPartsUrl?: string;
|
|
171
|
+
/**
|
|
172
|
+
* `azure-blocks` only: the size of every block but the last, in bytes.
|
|
173
|
+
* Default 8 MiB, at most 4000 MiB, and at most 50,000 blocks.
|
|
174
|
+
*/
|
|
175
|
+
blockSize?: number;
|
|
176
|
+
}
|
|
177
|
+
export interface DownloadOptions extends TransferOptionsBase {
|
|
178
|
+
/**
|
|
179
|
+
* The URL to fetch, already resolved (a Storage download URL carries its
|
|
180
|
+
* own token). Bytes go to `<path>.part` and the file is renamed to `path`
|
|
181
|
+
* only once every byte has landed.
|
|
182
|
+
*/
|
|
183
|
+
url: string;
|
|
184
|
+
}
|
|
185
|
+
/** What the plugin knows about one transfer. */
|
|
186
|
+
export interface TransferRecord {
|
|
187
|
+
id: string;
|
|
188
|
+
direction: TransferDirection;
|
|
189
|
+
state: TransferState;
|
|
190
|
+
url: string;
|
|
191
|
+
path: string;
|
|
192
|
+
/** Uploads: the protocol the session speaks. */
|
|
193
|
+
protocol?: UploadProtocol;
|
|
194
|
+
/**
|
|
195
|
+
* Bytes the server holds (upload) or that have landed in `.part`
|
|
196
|
+
* (download). For `s3-multipart` and `azure-blocks`, the parts or blocks
|
|
197
|
+
* stored plus the bytes of the one being sent (so it goes back to the
|
|
198
|
+
* stored parts' end when a part cut off part-way is sent again); for `put`,
|
|
199
|
+
* the bytes sent so far in this attempt. Below `total` until the server has
|
|
200
|
+
* confirmed the whole object.
|
|
201
|
+
*/
|
|
202
|
+
bytes: number;
|
|
203
|
+
/** Total size, or -1 until it is known. */
|
|
204
|
+
total: number;
|
|
205
|
+
/** Set when `state` is `failed`, `cancelled` or `interrupted`. */
|
|
206
|
+
reason?: TransferFailureReason;
|
|
207
|
+
/** Detail for logs; not for showing to people. */
|
|
208
|
+
message?: string;
|
|
209
|
+
/** HTTP status of the response that stopped it, when there was one. */
|
|
210
|
+
httpStatus?: number;
|
|
211
|
+
/** Milliseconds since the epoch. */
|
|
212
|
+
updatedAt: number;
|
|
213
|
+
}
|
|
214
|
+
export interface AvailableResult {
|
|
215
|
+
available: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* How transfers run here: `job` (Android 14+ user-initiated data transfer
|
|
218
|
+
* job), `worker` (WorkManager `dataSync` foreground service below Android
|
|
219
|
+
* 14), `urlsession` (iPhone background `URLSession`) or `none` (web).
|
|
220
|
+
*/
|
|
221
|
+
mechanism: 'job' | 'worker' | 'urlsession' | 'none';
|
|
222
|
+
/**
|
|
223
|
+
* Set when the app is set up so that transfers can't run as they should, e.g. below Android 14
|
|
224
|
+
* when the manifest doesn't declare WorkManager's foreground service with the `dataSync` type
|
|
225
|
+
* (the worker then stops when the app leaves the screen). For logs, not for people.
|
|
226
|
+
*/
|
|
227
|
+
warning?: string;
|
|
228
|
+
}
|
|
229
|
+
export interface TransferEvent {
|
|
230
|
+
transfer: TransferRecord;
|
|
231
|
+
}
|
|
232
|
+
export interface BackgroundTransferPlugin {
|
|
233
|
+
/** Whether native background transfers work here. The web says no. */
|
|
234
|
+
isAvailable(): Promise<AvailableResult>;
|
|
235
|
+
/**
|
|
236
|
+
* Queue an upload to an upload you have set up on the server (see
|
|
237
|
+
* `UploadProtocol`). Refused at once if its options are missing or don't
|
|
238
|
+
* fit together (on Android and iOS also when `partUrls` doesn't match the
|
|
239
|
+
* file's size). Call it while the app
|
|
240
|
+
* is on screen: Android only lets a user-initiated job be scheduled then,
|
|
241
|
+
* and iPhone may defer tasks started from the background.
|
|
242
|
+
*/
|
|
243
|
+
upload(options: UploadOptions): Promise<TransferEvent>;
|
|
244
|
+
/** Queue a download. Same rules as `upload`. */
|
|
245
|
+
download(options: DownloadOptions): Promise<TransferEvent>;
|
|
246
|
+
/** Cancel a transfer; its temporary files are removed. Unknown ids are ignored. */
|
|
247
|
+
cancel(options: {
|
|
248
|
+
id: string;
|
|
249
|
+
direction: TransferDirection;
|
|
250
|
+
}): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Every transfer the plugin remembers, including ones that ran, finished
|
|
253
|
+
* or failed while the app was closed. Ask on launch.
|
|
254
|
+
*/
|
|
255
|
+
list(): Promise<{
|
|
256
|
+
transfers: TransferRecord[];
|
|
257
|
+
}>;
|
|
258
|
+
/**
|
|
259
|
+
* Forget finished, failed and cancelled transfers (all of them, or the
|
|
260
|
+
* given ids). Queued, running and interrupted ones are kept.
|
|
261
|
+
*/
|
|
262
|
+
forget(options?: {
|
|
263
|
+
ids?: {
|
|
264
|
+
id: string;
|
|
265
|
+
direction: TransferDirection;
|
|
266
|
+
}[];
|
|
267
|
+
}): Promise<void>;
|
|
268
|
+
/** Bytes moved. At most a few events a second per transfer. */
|
|
269
|
+
addListener(eventName: 'progress', listener: (event: TransferEvent) => void): Promise<PluginListenerHandle>;
|
|
270
|
+
/**
|
|
271
|
+
* Any change of `state` (queued, running, interrupted, finished, failed,
|
|
272
|
+
* cancelled).
|
|
273
|
+
*/
|
|
274
|
+
addListener(eventName: 'stateChange', listener: (event: TransferEvent) => void): Promise<PluginListenerHandle>;
|
|
275
|
+
removeAllListeners(): Promise<void>;
|
|
276
|
+
}
|
|
277
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The protocols this version knows. */
|
|
2
|
+
export const UPLOAD_PROTOCOLS = [
|
|
3
|
+
'firebase-resumable',
|
|
4
|
+
'put',
|
|
5
|
+
's3-multipart',
|
|
6
|
+
'azure-blocks',
|
|
7
|
+
];
|
|
8
|
+
const MIB = 1024 * 1024;
|
|
9
|
+
/** The limits the plugin checks for `s3-multipart` and `azure-blocks`. */
|
|
10
|
+
export const UPLOAD_LIMITS = {
|
|
11
|
+
/** Default `partSize` and `blockSize`: 8 MiB. */
|
|
12
|
+
defaultPartSize: 8 * MIB,
|
|
13
|
+
/** S3's smallest part, other than the last: 5 MiB. */
|
|
14
|
+
s3MinPartSize: 5 * MIB,
|
|
15
|
+
/** S3's largest part: 5 GiB. */
|
|
16
|
+
s3MaxPartSize: 5 * 1024 * MIB,
|
|
17
|
+
/** S3's most parts in one upload. */
|
|
18
|
+
s3MaxParts: 10000,
|
|
19
|
+
/** Azure's largest block: 4000 MiB. */
|
|
20
|
+
azureMaxBlockSize: 4000 * MIB,
|
|
21
|
+
/** Azure's most blocks in one blob. */
|
|
22
|
+
azureMaxBlocks: 50000,
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkIA,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAA8B;IACzD,oBAAoB;IACpB,KAAK;IACL,cAAc;IACd,cAAc;CACf,CAAC;AAEF,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAExB,0EAA0E;AAC1E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iDAAiD;IACjD,eAAe,EAAE,CAAC,GAAG,GAAG;IACxB,sDAAsD;IACtD,aAAa,EAAE,CAAC,GAAG,GAAG;IACtB,gCAAgC;IAChC,aAAa,EAAE,CAAC,GAAG,IAAI,GAAG,GAAG;IAC7B,qCAAqC;IACrC,UAAU,EAAE,KAAK;IACjB,uCAAuC;IACvC,iBAAiB,EAAE,IAAI,GAAG,GAAG;IAC7B,uCAAuC;IACvC,cAAc,EAAE,KAAK;CACb,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/** Which way a transfer moves bytes. */\nexport type TransferDirection = 'upload' | 'download';\n\n/**\n * Where a transfer is.\n *\n * - `queued`: waiting its turn (one transfer runs per direction), or waiting\n * for the network on Android 14+, where the system restarts it.\n * - `running`: bytes are moving.\n * - `interrupted`: stopped by a network drop, the app being swiped away or\n * the system, and won't restart by itself. Start it again with the same\n * `id` and it carries on from where it stopped.\n * - `finished`: every byte landed. For a download the file is at `path`.\n * - `failed`: it can't finish as asked; `reason` says why. Its temporary\n * files are gone.\n * - `cancelled`: `cancel()` was called. Its temporary files are gone.\n */\nexport type TransferState = 'queued' | 'running' | 'interrupted' | 'finished' | 'failed' | 'cancelled';\n\n/**\n * Why a transfer stopped without finishing.\n *\n * - `file-missing`: the upload's file isn't there (or is a directory).\n * - `disk-full`: no space for a download, or for the remainder copy an\n * iPhone upload needs to resume part-way.\n * - `session-refused`: the server refused the request (HTTP 4xx other than\n * the two below), e.g. Firebase Storage security rules refused the upload at finalize (403), or\n * a presigned URL or SAS token expired or lacks a permission (403). `message` names the\n * request that was refused (a part, a block, the `PUT`, or the commit).\n * - `session-expired`: the upload session or download URL is gone (HTTP 404\n * or 410), e.g. an S3 multipart upload that was aborted, found out while\n * sending a part or asking ListParts. Start a new session. (An S3 upload\n * found gone only at the completion reports `session-closed`: it may have\n * been completed.)\n * - `session-closed`: the upload can't be confirmed from here. For `firebase-resumable`, the\n * session was already closed when the upload started; that isn't proof the object was accepted\n * (the Firebase Storage emulator closes a session whose finalize its security rules refused).\n * For `s3-multipart` and `azure-blocks`, the request that completes the object was sent in an\n * earlier run (or earlier in this one) and its answer never came, so it may or may not have\n * been applied. Either way, check the object on the server, and start a new upload if it\n * isn't there or is the wrong size.\n * - `size-mismatch`: the bytes that landed don't add up to the size the\n * server or file said.\n * - `network`: the connection dropped. Used with `interrupted`.\n * - `stopped-by-system`: the system ended the work (the app was swiped away\n * on iPhone, the work was stopped below Android 14). Used with\n * `interrupted`.\n * - `cancelled`: `cancel()` was called.\n * - `server-error`: the server kept answering 5xx.\n * - `unknown`: anything else; `message` has the detail.\n */\nexport type TransferFailureReason =\n | 'file-missing'\n | 'disk-full'\n | 'session-refused'\n | 'session-expired'\n | 'session-closed'\n | 'size-mismatch'\n | 'network'\n | 'stopped-by-system'\n | 'cancelled'\n | 'server-error'\n | 'unknown';\n\n/** What Android shows while a transfer runs. Ignored on iPhone. */\nexport interface TransferNotification {\n /** Notification channel id. Default `background-transfer`. */\n channelId?: string;\n /** The channel's name in system settings, used when the channel is first created. Default `Transfers`. */\n channelName?: string;\n /** Default `Uploading` or `Downloading`. */\n title?: string;\n /** Optional second line. */\n text?: string;\n}\n\ninterface TransferOptionsBase {\n /**\n * Your id for the transfer, unique per direction. Starting a transfer with\n * the id of one that is `interrupted`, `failed` or `cancelled` starts it\n * again (an upload asks the server for its offset; a download resumes from\n * its `.part` file). Starting one that is `queued` or `running` changes\n * nothing and returns its current record. Starting an upload with the id\n * of a `finished` one reports `failed` (`session-closed`) for every\n * protocol but `put`: its session is closed, so start a new session to send\n * the file again. A `put` sends the whole file again.\n */\n id: string;\n /**\n * Absolute path or `file://` URI of the local file: the file to send, or\n * where the downloaded file goes.\n */\n path: string;\n /**\n * Extra request headers sent on every request of this transfer (for an\n * upload in parts: every part, block, query and the commit). None by\n * default: an upload sends no `Authorization` header unless you pass one.\n */\n headers?: Record<string, string>;\n /** Android only. */\n notification?: TransferNotification;\n}\n\n/**\n * The upload protocol a transfer speaks. The plugin never signs anything: you\n * create the upload on the server and hand the plugin URLs that carry their\n * own authorisation (a session URL, presigned URLs, a SAS URL).\n *\n * - `firebase-resumable`: a Firebase Storage resumable upload (the\n * `X-Goog-Upload-*` protocol: `POST` with `X-Goog-Upload-Command` `query`,\n * `upload` and `upload, finalize`). `url` is the session URL.\n * - `put`: the whole file in one `PUT` to `url`, e.g. an S3 presigned `PUT`\n * URL or an Azure blob SAS URL (pass `x-ms-blob-type: BlockBlob` in\n * `headers` for Azure). An interrupted upload starts again from the first\n * byte. S3 takes at most 5 GB in one `PUT`.\n * - `s3-multipart`: an S3 (or S3-compatible) multipart upload you have\n * created. `partUrls` are the presigned `UploadPart` URLs, part 1 first;\n * `url` is the presigned `CompleteMultipartUpload` URL. The plugin sends the\n * parts one at a time, keeps each `ETag`, skips the parts already stored when\n * it resumes, then completes the upload listing every part.\n * - `azure-blocks`: an Azure block blob. `url` is the blob's SAS URL with\n * write permission (`sp` including `w`, or `c` and `w`). The plugin sends\n * blocks with stable ids (`Put Block`), skips the ones in the blob's\n * uncommitted block list when it resumes, then commits them\n * (`Put Block List`).\n */\nexport type UploadProtocol = 'firebase-resumable' | 'put' | 's3-multipart' | 'azure-blocks';\n\n/** The protocols this version knows. */\nexport const UPLOAD_PROTOCOLS: readonly UploadProtocol[] = [\n 'firebase-resumable',\n 'put',\n 's3-multipart',\n 'azure-blocks',\n];\n\nconst MIB = 1024 * 1024;\n\n/** The limits the plugin checks for `s3-multipart` and `azure-blocks`. */\nexport const UPLOAD_LIMITS = {\n /** Default `partSize` and `blockSize`: 8 MiB. */\n defaultPartSize: 8 * MIB,\n /** S3's smallest part, other than the last: 5 MiB. */\n s3MinPartSize: 5 * MIB,\n /** S3's largest part: 5 GiB. */\n s3MaxPartSize: 5 * 1024 * MIB,\n /** S3's most parts in one upload. */\n s3MaxParts: 10000,\n /** Azure's largest block: 4000 MiB. */\n azureMaxBlockSize: 4000 * MIB,\n /** Azure's most blocks in one blob. */\n azureMaxBlocks: 50000,\n} as const;\n\nexport interface UploadOptions extends TransferOptionsBase {\n /**\n * Where the upload goes, which depends on `protocol`:\n *\n * - `firebase-resumable`: the session URL of an upload you have already\n * started (the `X-Goog-Upload-URL` from its `start`). The plugin asks it\n * how many bytes it holds, sends the rest and finalizes.\n * - `put`: the URL to `PUT` the whole file to.\n * - `s3-multipart`: the presigned `CompleteMultipartUpload` URL (`POST`,\n * with the upload's `uploadId`).\n * - `azure-blocks`: the blob's SAS URL (with its `sig` parameter). The\n * blob's properties go in `headers` as `x-ms-blob-content-type` and the\n * other `x-ms-blob-*` headers: they are sent with the commit only.\n */\n url: string;\n /**\n * The protocol the upload speaks. Default `firebase-resumable`. An\n * unknown value is refused.\n */\n protocol?: UploadProtocol;\n /**\n * `s3-multipart` only, and required there: the presigned `UploadPart` URL\n * of every part, part 1 first. There must be exactly as many as the file\n * needs in `partSize` parts (at most 10,000). They must stay valid until\n * the last part is sent.\n */\n partUrls?: string[];\n /**\n * `s3-multipart` only: the size of every part but the last, in bytes.\n * Default 8 MiB. At least 5 MiB when there is more than one part, at most\n * 5 GiB.\n */\n partSize?: number;\n /**\n * `s3-multipart` only, optional: the presigned `ListParts` URL (`GET`, with\n * the `uploadId`). When it is given, a resumed upload asks the server which\n * parts it holds instead of trusting the plugin's own record, so a part\n * the server lost is sent again and fresh URLs for the same upload carry on\n * where the old ones stopped.\n */\n listPartsUrl?: string;\n /**\n * `azure-blocks` only: the size of every block but the last, in bytes.\n * Default 8 MiB, at most 4000 MiB, and at most 50,000 blocks.\n */\n blockSize?: number;\n}\n\nexport interface DownloadOptions extends TransferOptionsBase {\n /**\n * The URL to fetch, already resolved (a Storage download URL carries its\n * own token). Bytes go to `<path>.part` and the file is renamed to `path`\n * only once every byte has landed.\n */\n url: string;\n}\n\n/** What the plugin knows about one transfer. */\nexport interface TransferRecord {\n id: string;\n direction: TransferDirection;\n state: TransferState;\n url: string;\n path: string;\n /** Uploads: the protocol the session speaks. */\n protocol?: UploadProtocol;\n /**\n * Bytes the server holds (upload) or that have landed in `.part`\n * (download). For `s3-multipart` and `azure-blocks`, the parts or blocks\n * stored plus the bytes of the one being sent (so it goes back to the\n * stored parts' end when a part cut off part-way is sent again); for `put`,\n * the bytes sent so far in this attempt. Below `total` until the server has\n * confirmed the whole object.\n */\n bytes: number;\n /** Total size, or -1 until it is known. */\n total: number;\n /** Set when `state` is `failed`, `cancelled` or `interrupted`. */\n reason?: TransferFailureReason;\n /** Detail for logs; not for showing to people. */\n message?: string;\n /** HTTP status of the response that stopped it, when there was one. */\n httpStatus?: number;\n /** Milliseconds since the epoch. */\n updatedAt: number;\n}\n\nexport interface AvailableResult {\n available: boolean;\n /**\n * How transfers run here: `job` (Android 14+ user-initiated data transfer\n * job), `worker` (WorkManager `dataSync` foreground service below Android\n * 14), `urlsession` (iPhone background `URLSession`) or `none` (web).\n */\n mechanism: 'job' | 'worker' | 'urlsession' | 'none';\n /**\n * Set when the app is set up so that transfers can't run as they should, e.g. below Android 14\n * when the manifest doesn't declare WorkManager's foreground service with the `dataSync` type\n * (the worker then stops when the app leaves the screen). For logs, not for people.\n */\n warning?: string;\n}\n\nexport interface TransferEvent {\n transfer: TransferRecord;\n}\n\nexport interface BackgroundTransferPlugin {\n /** Whether native background transfers work here. The web says no. */\n isAvailable(): Promise<AvailableResult>;\n\n /**\n * Queue an upload to an upload you have set up on the server (see\n * `UploadProtocol`). Refused at once if its options are missing or don't\n * fit together (on Android and iOS also when `partUrls` doesn't match the\n * file's size). Call it while the app\n * is on screen: Android only lets a user-initiated job be scheduled then,\n * and iPhone may defer tasks started from the background.\n */\n upload(options: UploadOptions): Promise<TransferEvent>;\n\n /** Queue a download. Same rules as `upload`. */\n download(options: DownloadOptions): Promise<TransferEvent>;\n\n /** Cancel a transfer; its temporary files are removed. Unknown ids are ignored. */\n cancel(options: { id: string; direction: TransferDirection }): Promise<void>;\n\n /**\n * Every transfer the plugin remembers, including ones that ran, finished\n * or failed while the app was closed. Ask on launch.\n */\n list(): Promise<{ transfers: TransferRecord[] }>;\n\n /**\n * Forget finished, failed and cancelled transfers (all of them, or the\n * given ids). Queued, running and interrupted ones are kept.\n */\n forget(options?: { ids?: { id: string; direction: TransferDirection }[] }): Promise<void>;\n\n /** Bytes moved. At most a few events a second per transfer. */\n addListener(eventName: 'progress', listener: (event: TransferEvent) => void): Promise<PluginListenerHandle>;\n\n /**\n * Any change of `state` (queued, running, interrupted, finished, failed,\n * cancelled).\n */\n addListener(eventName: 'stateChange', listener: (event: TransferEvent) => void): Promise<PluginListenerHandle>;\n\n removeAllListeners(): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BackgroundTransferPlugin } from './definitions';
|
|
2
|
+
/**
|
|
3
|
+
* The plugin, with `upload` and `download` options checked (and `file://`
|
|
4
|
+
* URIs turned into paths) before they reach the native side.
|
|
5
|
+
*/
|
|
6
|
+
declare const BackgroundTransfer: BackgroundTransferPlugin;
|
|
7
|
+
export declare function wrap(plugin: BackgroundTransferPlugin): BackgroundTransferPlugin;
|
|
8
|
+
export * from './definitions';
|
|
9
|
+
export { checkTransferOptions, checkUploadOptions, toPlainPath } from './validate';
|
|
10
|
+
export { BackgroundTransfer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
import { checkTransferOptions, checkUploadOptions } from './validate';
|
|
3
|
+
const Native = registerPlugin('BackgroundTransfer', {
|
|
4
|
+
web: () => import('./web').then((m) => new m.BackgroundTransferWeb()),
|
|
5
|
+
});
|
|
6
|
+
/**
|
|
7
|
+
* The plugin, with `upload` and `download` options checked (and `file://`
|
|
8
|
+
* URIs turned into paths) before they reach the native side.
|
|
9
|
+
*/
|
|
10
|
+
const BackgroundTransfer = wrap(Native);
|
|
11
|
+
export function wrap(plugin) {
|
|
12
|
+
return {
|
|
13
|
+
isAvailable: () => plugin.isAvailable(),
|
|
14
|
+
upload: async (options) => plugin.upload(checkUploadOptions(options)),
|
|
15
|
+
download: async (options) => plugin.download(checkTransferOptions(options)),
|
|
16
|
+
cancel: (options) => plugin.cancel(options),
|
|
17
|
+
list: () => plugin.list(),
|
|
18
|
+
forget: (options) => plugin.forget(options),
|
|
19
|
+
addListener: ((eventName, listener) => plugin.addListener(eventName, listener)),
|
|
20
|
+
removeAllListeners: () => plugin.removeAllListeners(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export * from './definitions';
|
|
24
|
+
export { checkTransferOptions, checkUploadOptions, toPlainPath } from './validate';
|
|
25
|
+
export { BackgroundTransfer };
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,MAAM,GAAG,cAAc,CAA2B,oBAAoB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;CACtE,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,kBAAkB,GAA6B,IAAI,CAAC,MAAM,CAAC,CAAC;AAElE,MAAM,UAAU,IAAI,CAAC,MAAgC;IACnD,OAAO;QACL,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE;QACvC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACrE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3E,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC3C,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE;QACzB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC3C,WAAW,EAAE,CAAC,CAAC,SAAqC,EAAE,QAAe,EAAE,EAAE,CACvE,MAAM,CAAC,WAAW,CAAC,SAAuB,EAAE,QAAQ,CAAC,CAA4C;QACnG,kBAAkB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,EAAE;KACtD,CAAC;AACJ,CAAC;AAED,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { BackgroundTransferPlugin } from './definitions';\nimport { checkTransferOptions, checkUploadOptions } from './validate';\n\nconst Native = registerPlugin<BackgroundTransferPlugin>('BackgroundTransfer', {\n web: () => import('./web').then((m) => new m.BackgroundTransferWeb()),\n});\n\n/**\n * The plugin, with `upload` and `download` options checked (and `file://`\n * URIs turned into paths) before they reach the native side.\n */\nconst BackgroundTransfer: BackgroundTransferPlugin = wrap(Native);\n\nexport function wrap(plugin: BackgroundTransferPlugin): BackgroundTransferPlugin {\n return {\n isAvailable: () => plugin.isAvailable(),\n upload: async (options) => plugin.upload(checkUploadOptions(options)),\n download: async (options) => plugin.download(checkTransferOptions(options)),\n cancel: (options) => plugin.cancel(options),\n list: () => plugin.list(),\n forget: (options) => plugin.forget(options),\n addListener: ((eventName: 'progress' | 'stateChange', listener: never) =>\n plugin.addListener(eventName as 'progress', listener)) as BackgroundTransferPlugin['addListener'],\n removeAllListeners: () => plugin.removeAllListeners(),\n };\n}\n\nexport * from './definitions';\nexport { checkTransferOptions, checkUploadOptions, toPlainPath } from './validate';\nexport { BackgroundTransfer };\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DownloadOptions, UploadOptions } from './definitions';
|
|
2
|
+
/**
|
|
3
|
+
* Checks a transfer's options before they cross to the native side, so both
|
|
4
|
+
* platforms refuse the same mistakes with the same words. Returns the
|
|
5
|
+
* options with `path` as a plain absolute path. The native sides repeat these
|
|
6
|
+
* checks (a script can call the plugin directly), and also confine `path` to
|
|
7
|
+
* the app's own directories, which only they know.
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkTransferOptions<T extends UploadOptions | DownloadOptions>(options: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Checks an upload's options as `checkTransferOptions` does, its `protocol`
|
|
12
|
+
* (`firebase-resumable` when omitted, refused when unknown) and the options
|
|
13
|
+
* that go with it. The native sides check the same things, and also that
|
|
14
|
+
* `partUrls` fits the file's size, which only they can read.
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkUploadOptions(options: UploadOptions): UploadOptions;
|
|
17
|
+
/** `file:///a/b%20c.mp4` → `/a/b c.mp4`; absolute paths pass through. */
|
|
18
|
+
export declare function toPlainPath(path: unknown): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { UPLOAD_LIMITS, UPLOAD_PROTOCOLS } from './definitions';
|
|
2
|
+
const HTTP_URL = /^https?:\/\/[^/]+/i;
|
|
3
|
+
// A line break or any other control character in a header name or value.
|
|
4
|
+
// eslint-disable-next-line no-control-regex
|
|
5
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
6
|
+
/**
|
|
7
|
+
* Checks a transfer's options before they cross to the native side, so both
|
|
8
|
+
* platforms refuse the same mistakes with the same words. Returns the
|
|
9
|
+
* options with `path` as a plain absolute path. The native sides repeat these
|
|
10
|
+
* checks (a script can call the plugin directly), and also confine `path` to
|
|
11
|
+
* the app's own directories, which only they know.
|
|
12
|
+
*/
|
|
13
|
+
export function checkTransferOptions(options) {
|
|
14
|
+
if (!options || typeof options !== 'object')
|
|
15
|
+
throw new Error('options are required');
|
|
16
|
+
const { id, url, path, headers } = options;
|
|
17
|
+
if (typeof id !== 'string' || id.trim() === '')
|
|
18
|
+
throw new Error('id is required');
|
|
19
|
+
if (typeof url !== 'string' || !HTTP_URL.test(url))
|
|
20
|
+
throw new Error('url must be an http or https URL');
|
|
21
|
+
const plain = toPlainPath(path);
|
|
22
|
+
if (headers !== undefined) {
|
|
23
|
+
if (headers === null || typeof headers !== 'object' || Array.isArray(headers)) {
|
|
24
|
+
throw new Error('headers must be an object of strings');
|
|
25
|
+
}
|
|
26
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
27
|
+
if (typeof value !== 'string')
|
|
28
|
+
throw new Error(`header ${name} must be a string`);
|
|
29
|
+
if (name === '' || CONTROL.test(name) || CONTROL.test(value))
|
|
30
|
+
throw new Error(`header ${name} must be one line`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Object.assign(Object.assign({}, options), { path: plain });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks an upload's options as `checkTransferOptions` does, its `protocol`
|
|
37
|
+
* (`firebase-resumable` when omitted, refused when unknown) and the options
|
|
38
|
+
* that go with it. The native sides check the same things, and also that
|
|
39
|
+
* `partUrls` fits the file's size, which only they can read.
|
|
40
|
+
*/
|
|
41
|
+
export function checkUploadOptions(options) {
|
|
42
|
+
var _a;
|
|
43
|
+
const checked = checkTransferOptions(options);
|
|
44
|
+
const protocol = (_a = checked.protocol) !== null && _a !== void 0 ? _a : 'firebase-resumable';
|
|
45
|
+
if (!UPLOAD_PROTOCOLS.includes(protocol)) {
|
|
46
|
+
throw new Error(`protocol must be one of ${UPLOAD_PROTOCOLS.join(', ')}`);
|
|
47
|
+
}
|
|
48
|
+
const { partUrls, partSize, listPartsUrl, blockSize } = checked;
|
|
49
|
+
if (protocol !== 's3-multipart' && (partUrls !== undefined || partSize !== undefined || listPartsUrl !== undefined)) {
|
|
50
|
+
throw new Error('partUrls, partSize and listPartsUrl are only for s3-multipart');
|
|
51
|
+
}
|
|
52
|
+
if (protocol !== 'azure-blocks' && blockSize !== undefined) {
|
|
53
|
+
throw new Error('blockSize is only for azure-blocks');
|
|
54
|
+
}
|
|
55
|
+
if (protocol === 's3-multipart') {
|
|
56
|
+
if (!Array.isArray(partUrls) || partUrls.length === 0)
|
|
57
|
+
throw new Error('partUrls is required for s3-multipart');
|
|
58
|
+
if (partUrls.length > UPLOAD_LIMITS.s3MaxParts) {
|
|
59
|
+
throw new Error(`partUrls holds more than ${UPLOAD_LIMITS.s3MaxParts} parts`);
|
|
60
|
+
}
|
|
61
|
+
if (!partUrls.every((u) => typeof u === 'string' && HTTP_URL.test(u))) {
|
|
62
|
+
throw new Error('partUrls must be http or https URLs');
|
|
63
|
+
}
|
|
64
|
+
const size = partSize !== null && partSize !== void 0 ? partSize : UPLOAD_LIMITS.defaultPartSize;
|
|
65
|
+
if (!Number.isSafeInteger(size) || size < 1 || size > UPLOAD_LIMITS.s3MaxPartSize) {
|
|
66
|
+
throw new Error('partSize must be a whole number of bytes up to 5 GiB');
|
|
67
|
+
}
|
|
68
|
+
if (partUrls.length > 1 && size < UPLOAD_LIMITS.s3MinPartSize) {
|
|
69
|
+
throw new Error('partSize must be at least 5 MiB when there is more than one part');
|
|
70
|
+
}
|
|
71
|
+
if (listPartsUrl !== undefined && (typeof listPartsUrl !== 'string' || !HTTP_URL.test(listPartsUrl))) {
|
|
72
|
+
throw new Error('listPartsUrl must be an http or https URL');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (protocol === 'azure-blocks') {
|
|
76
|
+
if (!isSasUrl(checked.url))
|
|
77
|
+
throw new Error('url must be a blob SAS URL (with a sig parameter)');
|
|
78
|
+
const size = blockSize !== null && blockSize !== void 0 ? blockSize : UPLOAD_LIMITS.defaultPartSize;
|
|
79
|
+
if (!Number.isSafeInteger(size) || size < 1 || size > UPLOAD_LIMITS.azureMaxBlockSize) {
|
|
80
|
+
throw new Error('blockSize must be a whole number of bytes up to 4000 MiB');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return Object.assign(Object.assign({}, checked), { protocol });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A blob URL with a SAS token: a non-empty `sig` parameter, and no `comp` (the plugin adds its
|
|
87
|
+
* own). Parameter names are compared as written, as the native sides do.
|
|
88
|
+
*/
|
|
89
|
+
function isSasUrl(url) {
|
|
90
|
+
const query = url.split('#')[0].split('?')[1];
|
|
91
|
+
if (!query)
|
|
92
|
+
return false;
|
|
93
|
+
const params = query.split('&');
|
|
94
|
+
const names = params.map((p) => p.split('=')[0]);
|
|
95
|
+
return params.some((p) => p.startsWith('sig=') && p.length > 'sig='.length) && !names.includes('comp');
|
|
96
|
+
}
|
|
97
|
+
/** `file:///a/b%20c.mp4` → `/a/b c.mp4`; absolute paths pass through. */
|
|
98
|
+
export function toPlainPath(path) {
|
|
99
|
+
if (typeof path !== 'string' || path === '')
|
|
100
|
+
throw new Error('path is required');
|
|
101
|
+
let plain = path;
|
|
102
|
+
if (plain.startsWith('file://')) {
|
|
103
|
+
plain = decodeURIComponent(plain.slice('file://'.length));
|
|
104
|
+
}
|
|
105
|
+
if (!plain.startsWith('/'))
|
|
106
|
+
throw new Error('path must be absolute or a file:// URI');
|
|
107
|
+
if (plain.endsWith('/'))
|
|
108
|
+
throw new Error('path must name a file');
|
|
109
|
+
if (plain.split('/').includes('..'))
|
|
110
|
+
throw new Error('path must not contain ..');
|
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,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACtF,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAClE,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IACjF,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { DownloadOptions, UploadOptions } from './definitions';\nimport { UPLOAD_LIMITS, UPLOAD_PROTOCOLS } from './definitions';\n\nconst HTTP_URL = /^https?:\\/\\/[^/]+/i;\n// A line break or any other control character in a header name or value.\n// eslint-disable-next-line no-control-regex\nconst CONTROL = /[\\u0000-\\u001f\\u007f]/;\n\n/**\n * Checks a transfer's options before they cross to the native side, so both\n * platforms refuse the same mistakes with the same words. Returns the\n * options with `path` as a plain absolute path. The native sides repeat these\n * checks (a script can call the plugin directly), and also confine `path` to\n * the app's own directories, which only they know.\n */\nexport function checkTransferOptions<T extends UploadOptions | DownloadOptions>(options: T): T {\n if (!options || typeof options !== 'object') throw new Error('options are required');\n const { id, url, path, headers } = options;\n if (typeof id !== 'string' || id.trim() === '') throw new Error('id is required');\n if (typeof url !== 'string' || !HTTP_URL.test(url)) throw new Error('url must be an http or https URL');\n const plain = toPlainPath(path);\n if (headers !== undefined) {\n if (headers === null || typeof headers !== 'object' || Array.isArray(headers)) {\n throw new Error('headers must be an object of strings');\n }\n for (const [name, value] of Object.entries(headers)) {\n if (typeof value !== 'string') throw new Error(`header ${name} must be a string`);\n if (name === '' || CONTROL.test(name) || CONTROL.test(value)) throw new Error(`header ${name} must be one line`);\n }\n }\n return { ...options, path: plain };\n}\n\n/**\n * Checks an upload's options as `checkTransferOptions` does, its `protocol`\n * (`firebase-resumable` when omitted, refused when unknown) and the options\n * that go with it. The native sides check the same things, and also that\n * `partUrls` fits the file's size, which only they can read.\n */\nexport function checkUploadOptions(options: UploadOptions): UploadOptions {\n const checked = checkTransferOptions(options);\n const protocol = checked.protocol ?? 'firebase-resumable';\n if (!UPLOAD_PROTOCOLS.includes(protocol)) {\n throw new Error(`protocol must be one of ${UPLOAD_PROTOCOLS.join(', ')}`);\n }\n const { partUrls, partSize, listPartsUrl, blockSize } = checked;\n if (protocol !== 's3-multipart' && (partUrls !== undefined || partSize !== undefined || listPartsUrl !== undefined)) {\n throw new Error('partUrls, partSize and listPartsUrl are only for s3-multipart');\n }\n if (protocol !== 'azure-blocks' && blockSize !== undefined) {\n throw new Error('blockSize is only for azure-blocks');\n }\n if (protocol === 's3-multipart') {\n if (!Array.isArray(partUrls) || partUrls.length === 0) throw new Error('partUrls is required for s3-multipart');\n if (partUrls.length > UPLOAD_LIMITS.s3MaxParts) {\n throw new Error(`partUrls holds more than ${UPLOAD_LIMITS.s3MaxParts} parts`);\n }\n if (!partUrls.every((u) => typeof u === 'string' && HTTP_URL.test(u))) {\n throw new Error('partUrls must be http or https URLs');\n }\n const size = partSize ?? UPLOAD_LIMITS.defaultPartSize;\n if (!Number.isSafeInteger(size) || size < 1 || size > UPLOAD_LIMITS.s3MaxPartSize) {\n throw new Error('partSize must be a whole number of bytes up to 5 GiB');\n }\n if (partUrls.length > 1 && size < UPLOAD_LIMITS.s3MinPartSize) {\n throw new Error('partSize must be at least 5 MiB when there is more than one part');\n }\n if (listPartsUrl !== undefined && (typeof listPartsUrl !== 'string' || !HTTP_URL.test(listPartsUrl))) {\n throw new Error('listPartsUrl must be an http or https URL');\n }\n }\n if (protocol === 'azure-blocks') {\n if (!isSasUrl(checked.url)) throw new Error('url must be a blob SAS URL (with a sig parameter)');\n const size = blockSize ?? UPLOAD_LIMITS.defaultPartSize;\n if (!Number.isSafeInteger(size) || size < 1 || size > UPLOAD_LIMITS.azureMaxBlockSize) {\n throw new Error('blockSize must be a whole number of bytes up to 4000 MiB');\n }\n }\n return { ...checked, protocol };\n}\n\n/**\n * A blob URL with a SAS token: a non-empty `sig` parameter, and no `comp` (the plugin adds its\n * own). Parameter names are compared as written, as the native sides do.\n */\nfunction isSasUrl(url: string): boolean {\n const query = url.split('#')[0].split('?')[1];\n if (!query) return false;\n const params = query.split('&');\n const names = params.map((p) => p.split('=')[0]);\n return params.some((p) => p.startsWith('sig=') && p.length > 'sig='.length) && !names.includes('comp');\n}\n\n/** `file:///a/b%20c.mp4` → `/a/b c.mp4`; absolute paths pass through. */\nexport function toPlainPath(path: unknown): string {\n if (typeof path !== 'string' || path === '') throw new Error('path is required');\n let plain = path;\n if (plain.startsWith('file://')) {\n plain = decodeURIComponent(plain.slice('file://'.length));\n }\n if (!plain.startsWith('/')) throw new Error('path must be absolute or a file:// URI');\n if (plain.endsWith('/')) throw new Error('path must name a file');\n if (plain.split('/').includes('..')) throw new Error('path must not contain ..');\n return plain;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { AvailableResult, BackgroundTransferPlugin, TransferEvent, TransferRecord } from './definitions';
|
|
3
|
+
/**
|
|
4
|
+
* The web has no background transfers: it says so, and every transfer call
|
|
5
|
+
* is refused with Capacitor's `UNAVAILABLE` code, so the app keeps its
|
|
6
|
+
* in-app path there.
|
|
7
|
+
*/
|
|
8
|
+
export declare class BackgroundTransferWeb extends WebPlugin implements BackgroundTransferPlugin {
|
|
9
|
+
isAvailable(): Promise<AvailableResult>;
|
|
10
|
+
upload(): Promise<TransferEvent>;
|
|
11
|
+
download(): Promise<TransferEvent>;
|
|
12
|
+
cancel(): Promise<void>;
|
|
13
|
+
list(): Promise<{
|
|
14
|
+
transfers: TransferRecord[];
|
|
15
|
+
}>;
|
|
16
|
+
forget(): Promise<void>;
|
|
17
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
/**
|
|
3
|
+
* The web has no background transfers: it says so, and every transfer call
|
|
4
|
+
* is refused with Capacitor's `UNAVAILABLE` code, so the app keeps its
|
|
5
|
+
* in-app path there.
|
|
6
|
+
*/
|
|
7
|
+
export class BackgroundTransferWeb extends WebPlugin {
|
|
8
|
+
async isAvailable() {
|
|
9
|
+
return { available: false, mechanism: 'none' };
|
|
10
|
+
}
|
|
11
|
+
async upload() {
|
|
12
|
+
throw this.unavailable('Background transfers are not available on the web.');
|
|
13
|
+
}
|
|
14
|
+
async download() {
|
|
15
|
+
throw this.unavailable('Background transfers are not available on the web.');
|
|
16
|
+
}
|
|
17
|
+
async cancel() {
|
|
18
|
+
throw this.unavailable('Background transfers are not available on the web.');
|
|
19
|
+
}
|
|
20
|
+
async list() {
|
|
21
|
+
return { transfers: [] };
|
|
22
|
+
}
|
|
23
|
+
async forget() {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,WAAW;QACf,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO;IACT,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { AvailableResult, BackgroundTransferPlugin, TransferEvent, TransferRecord } from './definitions';\n\n/**\n * The web has no background transfers: it says so, and every transfer call\n * is refused with Capacitor's `UNAVAILABLE` code, so the app keeps its\n * in-app path there.\n */\nexport class BackgroundTransferWeb extends WebPlugin implements BackgroundTransferPlugin {\n async isAvailable(): Promise<AvailableResult> {\n return { available: false, mechanism: 'none' };\n }\n\n async upload(): Promise<TransferEvent> {\n throw this.unavailable('Background transfers are not available on the web.');\n }\n\n async download(): Promise<TransferEvent> {\n throw this.unavailable('Background transfers are not available on the web.');\n }\n\n async cancel(): Promise<void> {\n throw this.unavailable('Background transfers are not available on the web.');\n }\n\n async list(): Promise<{ transfers: TransferRecord[] }> {\n return { transfers: [] };\n }\n\n async forget(): Promise<void> {\n return;\n }\n}\n"]}
|