Skip to content

Commit

Permalink
Fixes issue with cid-log
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Jan 30, 2023
1 parent a4bdf96 commit d988bfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK

// Determine the correct CID of the file system to load
const dataCid = navigator.onLine ? await getDataRoot(reference, username, { maxRetries: 20 }) : null
const logIdx = dataCid ? await cidLog.indexOf(dataCid) : -1
const logIdx = dataCid ? cidLog.length() - cidLog.indexOf(dataCid) - 1 : -1

if (!navigator.onLine) {
// Offline, use local CID
Expand All @@ -67,7 +67,7 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK
} else if (logIdx > 0) {
// DNS is outdated
cid = cidLog.newest()
const idxLog = logIdx === 1 ? "1 newer local entry" : logIdx + " newer local entries"
const idxLog = logIdx === 1 ? "1 newer local entry" : (cidLog.length() - logIdx - 1).toString() + " newer local entries"
manners.log("📓 DNSLink is outdated (" + idxLog + "), using local CID:", cid.toString())

} else {
Expand Down
8 changes: 8 additions & 0 deletions src/repositories/cid-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export class Repo extends Repository<CID> {
return a.toString()
}

indexOf(item: CID): number {
return this.memoryCache.map(
c => c.toString()
).indexOf(
item.toString()
)
}

newest(): CID {
return this.memoryCache[ this.memoryCache.length - 1 ]
}
Expand Down

0 comments on commit d988bfa

Please sign in to comment.