mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
web/storage: robuster er opfs availability check
Some checks are pending
Some checks are pending
This commit is contained in:
parent
a06baa41c1
commit
81c8daf852
@ -42,16 +42,29 @@ export class OPFSStorage extends AbstractStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async #computeIsAvailable() {
|
static async #computeIsAvailable() {
|
||||||
|
let tempFile = uuid(), ok = true;
|
||||||
|
|
||||||
if (typeof navigator === 'undefined')
|
if (typeof navigator === 'undefined')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ('storage' in navigator && 'getDirectory' in navigator.storage) {
|
if ('storage' in navigator && 'getDirectory' in navigator.storage) {
|
||||||
try {
|
try {
|
||||||
await navigator.storage.getDirectory();
|
const root = await navigator.storage.getDirectory();
|
||||||
return true;
|
const handle = await root.getFileHandle(tempFile, { create: true });
|
||||||
|
const syncAccess = await handle.createSyncAccessHandle();
|
||||||
|
syncAccess.close();
|
||||||
} catch {
|
} 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;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user