web/storage: robuster er opfs availability check
Some checks are pending
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Run tests / check lockfile correctness (push) Waiting to run
Run tests / web sanity check (push) Waiting to run
Run tests / api sanity check (push) Waiting to run

This commit is contained in:
jj 2025-06-11 14:23:28 +00:00
parent a06baa41c1
commit 81c8daf852
No known key found for this signature in database

View File

@ -42,16 +42,29 @@ export class OPFSStorage extends AbstractStorage {
}
static async #computeIsAvailable() {
let tempFile = uuid(), ok = true;
if (typeof navigator === 'undefined')
return false;
if ('storage' in navigator && 'getDirectory' in navigator.storage) {
try {
await navigator.storage.getDirectory();
return true;
const root = await navigator.storage.getDirectory();
const handle = await root.getFileHandle(tempFile, { create: true });
const syncAccess = await handle.createSyncAccessHandle();
syncAccess.close();
} catch {
return false;
ok = false;
}
try {
const root = await navigator.storage.getDirectory();
await root.removeEntry(tempFile, { recursive: true });
} catch {
ok = false;
}
return ok;
}
return false;