Open
Description
This is my file db.ts
:
import { EntityDB } from "@babycommando/entity-db";
let db: EntityDB | null = null;
// Initialize function to be called when needed
const initDB = async () => {
if (!db) {
db = new EntityDB({
vectorPath: "spotter-db",
model: "Xenova/all-MiniLM-L6-v2",
});
}
return db;
};
const ensureDB = async () => {
const database = await initDB();
if (!database) {
throw new Error("[SpotterDB] Database not initialized");
}
return database;
};
export const storage = {
async savePage(url: string, content?: string): Promise<string> {
const db = await ensureDB();
const json_obj = {
text: "check",
url,
timestamp: new Date().toISOString(),
};
console.log("[SpotterDB] Saving page:", json_obj);
if (!db){
console.error("[SpotterDB] DB NOT init()");
}
const key = await db.insert(json_obj);
console.log("[SpotterDB] Page saved successfully");
return key;
}
},
I'm constantly getting this error:
Error: Error inserting data: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
The reason I have a complicated initialization is because the normal one was also giving the same error. So I wanted to ensure that my db is initialized before I do an insert. (to keep my bases covered)
But whenever I do storage.savePage(url, content)
, iget the error :(
Metadata
Metadata
Assignees
Labels
No labels