feat: add getCachedStorageLocations method

This commit is contained in:
Derrick Hammer 2023-11-17 04:56:57 -05:00
parent 3ad41c75c1
commit 86522e1ffe
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 34 additions and 0 deletions

View File

@ -85,6 +85,40 @@ export class S5Node {
await this.services.p2p.stop();
}
async getCachedStorageLocations(
hash: Multihash,
types: number[],
): Promise<Map<NodeId, StorageLocation>> {
const locations = new Map<NodeId, StorageLocation>();
const map = await this.readStorageLocationsFromDB(hash); // Assuming this method exists and returns a Map or similar structure
if (map.size === 0) {
return new Map();
}
const ts = Math.floor(Date.now() / 1000);
types.forEach((type) => {
if (!map.has(type)) return;
map.get(type)!.forEach((value, key) => {
if (value[3] >= ts) {
const storageLocation = new StorageLocation(
type,
value[1].map((v: string) => v), // Assuming value[1] is an array of strings
value[3],
);
// Assuming providerMessage is a property of StorageLocation
storageLocation.providerMessage = value[4];
locations.set(key, storageLocation);
}
});
});
return locations;
}
async readStorageLocationsFromDB(
hash: Multihash,
): Promise<Map<number, Map<NodeId, Map<number, any>>>> {