web: add uuid() function with fallback if randomUUID is missing

This commit is contained in:
jj
2025-06-11 14:18:04 +00:00
parent eb90843fc9
commit a06baa41c1
4 changed files with 27 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import { AbstractStorage } from "./storage";
import { uuid } from "$lib/util";
export class MemoryStorage extends AbstractStorage {
#chunkSize: number;
@@ -48,7 +49,7 @@ export class MemoryStorage extends AbstractStorage {
}
}
return new File(outputView, crypto.randomUUID());
return new File(outputView, uuid());
}
#expand(size: number) {

View File

@@ -1,4 +1,5 @@
import { AbstractStorage } from "./storage";
import { uuid } from "$lib/util";
const COBALT_PROCESSING_DIR = "cobalt-processing-data";
@@ -19,7 +20,7 @@ export class OPFSStorage extends AbstractStorage {
static async init() {
const root = await navigator.storage.getDirectory();
const cobaltDir = await root.getDirectoryHandle(COBALT_PROCESSING_DIR, { create: true });
const handle = await cobaltDir.getFileHandle(crypto.randomUUID(), { create: true });
const handle = await cobaltDir.getFileHandle(uuid(), { create: true });
const reader = await handle.createSyncAccessHandle();
return new this(cobaltDir, handle, reader);