diff options
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/lib/transfers.js | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/web/src/lib/transfers.js b/src/web/src/lib/transfers.js index 7fa58fc3..361926ae 100644 --- a/src/web/src/lib/transfers.js +++ b/src/web/src/lib/transfers.js @@ -20,6 +20,42 @@ export const download = ({ username, files = [] }) => { ); }; +/** + * Enqueues a batch of downloads. + * @param {object} params + * @param {string} params.username - The user to download from. + * @param {{ filename: string, size: number }[]} [params.files] - Files to enqueue. + * @param {string} [params.id] - Optional batch GUID. Generated server-side if omitted. + * @param {string} [params.searchId] - Optional GUID of an associated search. + * @param {{ destination?: string, externalId?: string }} [params.options] - `destination`: path relative to the configured download directory; `externalId`: optional external identifier for the batch. + * @returns {Promise} Resolves with the axios response. + * - 201: all files enqueued successfully + * - 200: batch created, but every file failed to enqueue — check `response.data.failures` + * - 207: partial — some enqueued, some failed — check `response.data.failures` + * @throws On error responses: + * - 400: validation failure (username/files required; duplicate filenames; id or searchId not a valid GUID) + * - 403: forbidden — running as relay agent + * - 404: user is offline + * - 409: a batch with the supplied id already exists + * - 429: a concurrent enqueue request is already in progress + * - 500: unexpected server error + */ +export const enqueueBatch = ({ + username, + files = [], + id, + searchId, + options = { destination: undefined, externalId: undefined }, +}) => { + return api.post('/transfers/downloads/batches', { + files, + id, + options, + searchId, + username, + }); +}; + export const cancel = ({ direction, username, id, remove = false }) => { return api.delete( `/transfers/${direction}s/${encodeURIComponent(username)}/${encodeURIComponent(id)}?remove=${remove}`, @@ -30,23 +66,26 @@ export const clearCompleted = ({ direction }) => { return api.delete(`/transfers/${direction}s/all/completed`); }; -// 'Requested' -// 'Queued, Remotely' -// 'Queued, Locally' -// 'Initializing' -// 'InProgress' -// 'Completed, Succeeded' -// 'Completed, Cancelled' -// 'Completed, TimedOut' -// 'Completed, Errored' -// 'Completed, Rejected' - export const getPlaceInQueue = ({ username, id }) => { return api.get( `/transfers/downloads/${encodeURIComponent(username)}/${encodeURIComponent(id)}/position`, ); }; +/* + states: + + 'Requested' + 'Queued, Remotely' + 'Queued, Locally' + 'Initializing' + 'InProgress' + 'Completed, Succeeded' + 'Completed, Cancelled' + 'Completed, TimedOut' + 'Completed, Errored' + 'Completed, Rejected' +*/ export const isStateRetryable = (state) => state.includes('Completed') && state !== 'Completed, Succeeded'; |
