Get the storage urls from diffs

This commit is contained in:
Sosthene 2025-09-08 15:56:14 +02:00
parent 63ee4ce719
commit e8c2d1a05a

View File

@ -668,9 +668,16 @@ export default class Services {
for (const hash of apiReturn.push_to_storage) {
const blob = await this.getBlobFromDb(hash);
if (blob) {
await this.saveDataToStorage(hash, blob, null);
// Get the storages from the diff data
const diff = await this.getDiffByValueFromDb(hash);
if (diff) {
const storages = diff.storages;
await this.saveDataToStorage(hash, storages, blob, null);
} else {
console.error('Failed to get diff from db for hash', hash);
}
} else {
console.error('Failed to get data from db');
console.error('Failed to get data from db for hash', hash);
}
}
}
@ -1030,9 +1037,7 @@ export default class Services {
}
}
public async saveDataToStorage(hash: string, data: Blob, ttl: number | null) {
const storages = [STORAGEURL];
public async saveDataToStorage(hash: string, storages: string[], data: Blob, ttl: number | null) {
try {
await storeData(storages, hash, data, ttl);
} catch (e) {
@ -1052,6 +1057,12 @@ export default class Services {
return await testData(storages, hash);
}
public async getDiffByValueFromDb(hash: string): Promise<UserDiff | null> {
const db = await Database.getInstance();
const diff = await db.getObject('diffs', hash);
return diff;
}
public async saveDiffsToDb(diffs: UserDiff[]) {
const db = await Database.getInstance();
try {