Skip to content

Commit

Permalink
fix: decode keys from file database
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Nov 22, 2024
1 parent e3e2b90 commit 6d7290a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions data/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,31 @@ db.version(3).stores({
wallet: "privateKey",
});

async function decodeKeys() {
return db.transaction('rw', db.files, async () => {
const files = await db.files.toArray();

for (const file of files) {
const decodedId = decodeURIComponent(file.path);

// Check if the decoded key already exists to avoid overwriting
const existingItem = await db.files.get(decodedId);
if (!existingItem) {
// Add new item with decoded key
await db.files.put({ ...file, path: decodedId });
}
}
});
}

db.open().then(() => {
console.log('Database opened successfully');
return decodeKeys();
}).then(() => {
console.log('Database initialisation complete');
}).catch((err) => {
console.error('Failed to open db: ' + (err.stack || err));
});

export type { File as FileContent, Workspace, Wallet };
export { db };

0 comments on commit 6d7290a

Please sign in to comment.