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 } },
|
{ 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);
|
||||||
|
const service = await Services.getInstance();
|
||||||
if (data.type === 'NOTIFICATIONS') {
|
if (data.type === 'NOTIFICATIONS') {
|
||||||
const service = await Services.getInstance();
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user