Add AnkData store to indexedDB

This commit is contained in:
NicolasCantu 2025-02-11 09:19:31 +01:00
parent d5c5224a9f
commit 5eef7c6981

View File

@ -43,6 +43,11 @@ export class Database {
{ name: 'byStatus', keyPath: 'validation_status', options: { unique: false } }, { name: 'byStatus', keyPath: 'validation_status', options: { unique: false } },
], ],
}, },
AnkData: {
name: 'data',
options: {},
indices: [],
},
}; };
// Private constructor to prevent direct instantiation from outside // Private constructor to prevent direct instantiation from outside
@ -162,9 +167,21 @@ export class Database {
private handleAddObjectResponse = async (event: MessageEvent) => { private handleAddObjectResponse = async (event: MessageEvent) => {
const data = event.data; const data = event.data;
console.log('Received response from service worker (ADD_OBJECT):', data); console.log('Received response from service worker (ADD_OBJECT):', data);
if (data.type === 'NOTIFICATIONS') {
const service = await Services.getInstance(); const service = await Services.getInstance();
if (data.type === 'NOTIFICATIONS') {
service.setNotifications(data.data); service.setNotifications(data.data);
} else if (data.type === 'TO_DOWNLOAD') {
// Download the missing data
for (const hash in data.data) {
try {
const value = await service.fetchValueFromStorage(hash);
// Save data to db
const blob = new Blob([value], {type: "text/plain"});
await service.saveDataToDb(hash, blob);
} catch (e) {
console.error(e);
}
}
} }
}; };