Fix indexeddb file system readdir to use a range

This commit is contained in:
Misode
2024-11-26 18:04:11 +01:00
parent 46ed105c34
commit 6badc9f06f
7 changed files with 20 additions and 19 deletions

View File

@@ -311,8 +311,7 @@ export class IndexedDbFileSystem implements core.ExternalFileSystem {
return new Promise((res, rej) => {
const transaction = db.transaction(IndexedDbFileSystem.storeName, 'readonly')
const store = transaction.objectStore(IndexedDbFileSystem.storeName)
// TODO: specify range
const request = store.openCursor()
const request = store.openCursor(IDBKeyRange.bound(location, location + '\uffff'))
const result: { name: string, isDirectory(): boolean, isFile(): boolean, isSymbolicLink(): boolean }[] = []
request.onsuccess = () => {
if (request.result) {

View File

@@ -14,7 +14,7 @@ import siteConfig from '../Config.js'
import { computeIfAbsent, genPath } from '../Utils.js'
import type { VersionMeta } from './DataFetcher.js'
import { fetchBlockStates, fetchRegistries, fetchVanillaMcdoc, fetchVersions, getVersionChecksum } from './DataFetcher.js'
import { IndexedDbFileSystem, MixedFileSystem } from './FileSystem.js'
import { IndexedDbFileSystem } from './FileSystem.js'
import type { VersionId } from './Versions.js'
export const CACHE_URI = 'file:///cache/'
@@ -52,7 +52,7 @@ interface ClientDocument {
}
export class SpyglassClient {
public static readonly FS = new MixedFileSystem(new IndexedDbFileSystem(), [])
public static readonly FS = new IndexedDbFileSystem()
public readonly fs = SpyglassClient.FS
public readonly externals: core.Externals = {
...BrowserExternals,
@@ -108,7 +108,7 @@ export class SpyglassService {
await Promise.all(this.treeWatchers.map(async ({ prefix, handler }) => {
const entries = await client.fs.readdir(prefix)
handler(entries.flatMap(e => {
return e.isFile() && e.name.startsWith(prefix) ? [e.name.slice(prefix.length)] : []
return e.isFile() ? [e.name.slice(prefix.length)] : []
}))
}))
})