core: fix data is not iterable error on backup restore

This commit is contained in:
Abdullah Atta
2023-12-26 08:32:31 +05:00
committed by Abdullah Atta
parent 930fadeae4
commit c759350b4c

View File

@@ -298,10 +298,19 @@ export default class Backup {
if ("compressed" in backup && typeof decryptedData === "string")
decryptedData = await this.db.compressor().decompress(decryptedData);
await this.migrateData(
const data =
typeof decryptedData === "string"
? (JSON.parse(decryptedData) as BackupDataItem[])
: Object.values(decryptedData),
? (JSON.parse(decryptedData) as unknown)
: Object.values(decryptedData);
if (!data) throw new Error("No data found.");
await this.migrateData(
Array.isArray(data)
? (data as BackupDataItem[])
: typeof data === "object"
? Object.values(data)
: [],
backup.version
);
}
@@ -333,6 +342,7 @@ export default class Backup {
}
private async migrateData(data: BackupDataItem[], version: number) {
console.log(data);
await this.db.transaction(async () => {
for (let item of data) {
// we do not want to restore deleted items