b7640e9be4
CI / changes (push) Has been cancelled
CI / Build (push) Has been cancelled
Deploy Docs / build (push) Has been cancelled
Docker Build and Test / Build and Test Docker Image (push) Has been cancelled
Docker Publish (release, main, dry-run) / Pre-publish Tests (push) Has been cancelled
CI / Frontend — svelte-check, ESLint, Stylelint, Prettier (push) Has been cancelled
CI / Message-bus spec — AsyncAPI + TypeScript DTO drift (push) Has been cancelled
CI / Migration ordering (new migrations postdate target branch) (push) Has been cancelled
CI / Rustfmt (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Wasm — fmt + clippy (push) Has been cancelled
CI / Wasm — release tests (push) Has been cancelled
CI / Plugins — fixtures + runtime tests (push) Has been cancelled
CI / Server Unit and Functionnal Tests (push) Has been cancelled
CI / Security Audit (push) Has been cancelled
CI / API, WebDAV & OIDC tests (push) Has been cancelled
CI / Bundled-assets binary — embed + SPA-serve integration (push) Has been cancelled
CI / WebDAV RFC 4918 — litmus (59/59) (push) Has been cancelled
CI / CalDAV + CardDAV — python-caldav (push) Has been cancelled
CI / Frontend end-to-end tests (via Playwright) (push) Has been cancelled
Deploy Docs / deploy (push) Has been cancelled
Docker Publish (release, main, dry-run) / Build & Push Multi-Arch (push) Has been cancelled
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
/**
|
|
* Batch operations (/api/batch/*). Used for multi-item copy — move and delete
|
|
* already have per-item endpoints the files view loops over, but copy only
|
|
* exists as a batch endpoint on the backend.
|
|
*/
|
|
import { apiFetch } from '$lib/api/client';
|
|
import { getCsrfHeaders } from '$lib/api/csrf';
|
|
|
|
const JSON_HEADERS = { 'Content-Type': 'application/json' };
|
|
|
|
async function post(url: string, body: unknown): Promise<void> {
|
|
const res = await apiFetch(url, {
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
headers: { ...JSON_HEADERS, ...getCsrfHeaders() },
|
|
body: JSON.stringify(body)
|
|
});
|
|
if (!res.ok) {
|
|
const e = (await res.json().catch(() => ({}))) as { error?: string; message?: string };
|
|
throw new Error(e.error || e.message || `${url} failed: ${res.status}`);
|
|
}
|
|
}
|
|
|
|
export function copyFiles(fileIds: string[], targetFolderId: string | null): Promise<void> {
|
|
if (fileIds.length === 0) return Promise.resolve();
|
|
return post('/api/batch/files/copy', { file_ids: fileIds, target_folder_id: targetFolderId });
|
|
}
|
|
|
|
export function copyFolders(folderIds: string[], targetFolderId: string | null): Promise<void> {
|
|
if (folderIds.length === 0) return Promise.resolve();
|
|
return post('/api/batch/folders/copy', {
|
|
folder_ids: folderIds,
|
|
target_folder_id: targetFolderId
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Stream a multi-item selection as a server-built zip (`POST /api/batch/download`
|
|
* — folders included, unlike the legacy per-item loop). The caller names and
|
|
* saves the returned blob.
|
|
*/
|
|
export async function downloadBatch(fileIds: string[], folderIds: string[]): Promise<Blob> {
|
|
const res = await apiFetch('/api/batch/download', {
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
headers: { ...JSON_HEADERS, ...getCsrfHeaders() },
|
|
body: JSON.stringify({ file_ids: fileIds, folder_ids: folderIds })
|
|
});
|
|
if (!res.ok) {
|
|
const e = (await res.json().catch(() => ({}))) as { error?: string; message?: string };
|
|
throw new Error(e.error || e.message || `batch download failed: ${res.status}`);
|
|
}
|
|
return res.blob();
|
|
}
|