mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
캐시 삭제 구현
This commit is contained in:
@@ -18,31 +18,32 @@ const getFileHandle = async (path: string, create = true) => {
|
||||
|
||||
try {
|
||||
let directoryHandle: FileSystemDirectoryHandle = rootHandle;
|
||||
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
if (!part) continue;
|
||||
directoryHandle = await directoryHandle.getDirectoryHandle(part, { create });
|
||||
}
|
||||
|
||||
return directoryHandle.getFileHandle(parts[parts.length - 1]!, { create });
|
||||
const filename = parts[parts.length - 1]!;
|
||||
const fileHandle = await directoryHandle.getFileHandle(filename, { create });
|
||||
return { parentHandle: directoryHandle, filename, fileHandle };
|
||||
} catch (e) {
|
||||
if (e instanceof DOMException && e.name === "NotFoundError") {
|
||||
return null;
|
||||
return {};
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
export const readFileFromOpfs = async (path: string) => {
|
||||
const fileHandle = await getFileHandle(path, false);
|
||||
export const readFile = async (path: string) => {
|
||||
const { fileHandle } = await getFileHandle(path, false);
|
||||
if (!fileHandle) return null;
|
||||
|
||||
const file = await fileHandle.getFile();
|
||||
return await file.arrayBuffer();
|
||||
};
|
||||
|
||||
export const writeFileToOpfs = async (path: string, data: ArrayBuffer) => {
|
||||
const fileHandle = await getFileHandle(path);
|
||||
export const writeFile = async (path: string, data: ArrayBuffer) => {
|
||||
const { fileHandle } = await getFileHandle(path);
|
||||
const writable = await fileHandle!.createWritable();
|
||||
|
||||
try {
|
||||
@@ -51,3 +52,10 @@ export const writeFileToOpfs = async (path: string, data: ArrayBuffer) => {
|
||||
await writable.close();
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteFile = async (path: string) => {
|
||||
const { parentHandle, filename } = await getFileHandle(path, false);
|
||||
if (!parentHandle) return;
|
||||
|
||||
await parentHandle.removeEntry(filename);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user