Add AnkData store to indexedDB
This commit is contained in:
parent
d5c5224a9f
commit
5eef7c6981
@ -43,6 +43,11 @@ export class Database {
|
||||
{ name: 'byStatus', keyPath: 'validation_status', options: { unique: false } },
|
||||
],
|
||||
},
|
||||
AnkData: {
|
||||
name: 'data',
|
||||
options: {},
|
||||
indices: [],
|
||||
},
|
||||
};
|
||||
|
||||
// Private constructor to prevent direct instantiation from outside
|
||||
@ -162,9 +167,21 @@ export class Database {
|
||||
private handleAddObjectResponse = async (event: MessageEvent) => {
|
||||
const data = event.data;
|
||||
console.log('Received response from service worker (ADD_OBJECT):', data);
|
||||
const service = await Services.getInstance();
|
||||
if (data.type === 'NOTIFICATIONS') {
|
||||
const service = await Services.getInstance();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user