fix: realign sqlite path and stabilize client data

This commit is contained in:
Zimeng Xiong
2025-11-22 16:26:28 -08:00
parent 5225332fed
commit d31feda405
13 changed files with 89 additions and 76 deletions
-40
View File
@@ -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 };
}
};