fix: realign sqlite path and stabilize client data
This commit is contained in:
@@ -76,43 +76,3 @@ export const importDrawings = async (
|
||||
|
||||
return { success: successCount, failed: failCount, errors };
|
||||
};
|
||||
|
||||
export const importLibrary = async (file: File) => {
|
||||
try {
|
||||
const text = await file.text();
|
||||
const data = JSON.parse(text);
|
||||
|
||||
let newItems = [];
|
||||
if (data.libraryItems) {
|
||||
newItems = data.libraryItems;
|
||||
} else if (Array.isArray(data)) {
|
||||
newItems = data;
|
||||
} else {
|
||||
throw new Error("Invalid library file format");
|
||||
}
|
||||
|
||||
// Fetch existing
|
||||
const existingRes = await fetch(`${API_URL}/library`);
|
||||
let existingItems = [];
|
||||
if (existingRes.ok) {
|
||||
const existingData = await existingRes.json();
|
||||
existingItems = existingData.libraryItems || [];
|
||||
}
|
||||
|
||||
// Merge (simple concat)
|
||||
const mergedItems = [...existingItems, ...newItems];
|
||||
|
||||
// Save
|
||||
const saveRes = await fetch(`${API_URL}/library`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ libraryItems: mergedItems }),
|
||||
});
|
||||
|
||||
if (!saveRes.ok) throw new Error("Failed to save library");
|
||||
return { success: true, count: newItems.length };
|
||||
} catch (err: any) {
|
||||
console.error("Library import failed:", err);
|
||||
return { success: false, error: err.message };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user