task(F1-frontend): library export/import buttons in block library tree
This commit is contained in:
@@ -812,3 +812,33 @@ export async function deleteGuest(token: string, id: string): Promise<void> {
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to delete guest: ${res.status}`);
|
||||
}
|
||||
|
||||
// ─── Library Paket Export/Import (Task F1) ─────────────
|
||||
export interface WcadlibPackage {
|
||||
format: 'wcadlib';
|
||||
version: number;
|
||||
exported_at?: string;
|
||||
folders: Array<{ id: string; name: string; parent_id: string | null }>;
|
||||
blocks: Array<{ name: string; folder_id: string | null; block_data: string; svg_data: string | null }>;
|
||||
}
|
||||
|
||||
export async function exportLibrary(token: string): Promise<unknown> {
|
||||
const res = await fetch(`${API_BASE}/api/global-blocks/export`, {
|
||||
headers: authHeaders(token),
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to export library: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function importLibrary(token: string, pkg: { format: string; version?: number; folders?: Array<{ id: string; name: string; parent_id: string | null }>; blocks: Array<{ name: string; folder_id: string | null; block_data: string; svg_data: string | null }> }): Promise<{ imported_blocks: number; imported_folders: number }> {
|
||||
const res = await fetch(`${API_BASE}/api/global-blocks/import`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders(token),
|
||||
body: JSON.stringify(pkg),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.text();
|
||||
throw new Error(`Failed to import library: ${res.status} ${err}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user