mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 12:20:20 +01:00
25 lines
672 B
TypeScript
25 lines
672 B
TypeScript
import { get, set } from "idb-keyval";
|
|
import { join } from "path";
|
|
import { FS_HANDLES } from "utils/constants";
|
|
|
|
export const getFileSystemHandles = async (): Promise<
|
|
Record<string, FileSystemDirectoryHandle>
|
|
> => (await get(FS_HANDLES)) ?? {};
|
|
|
|
export const addFileSystemHandle = async (
|
|
directory: string,
|
|
handle: FileSystemDirectoryHandle
|
|
): Promise<void> =>
|
|
set(FS_HANDLES, {
|
|
...(await getFileSystemHandles()),
|
|
[join(directory, handle.name)]: handle,
|
|
});
|
|
|
|
export const removeFileSystemHandle = async (
|
|
directory: string
|
|
): Promise<void> => {
|
|
const { [directory]: _, ...handles } = await getFileSystemHandles();
|
|
|
|
set(FS_HANDLES, handles);
|
|
};
|