mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-17 07:28:46 +00:00
파일을 삭제할 경우 서버와 클라이언트에 저장된 썸네일을 함께 삭제하도록 개선
This commit is contained in:
@@ -45,10 +45,17 @@ export const getFileInformation = async (userId: number, fileId: number) => {
|
||||
};
|
||||
};
|
||||
|
||||
const safeUnlink = async (path: string | null) => {
|
||||
if (path) {
|
||||
await unlink(path).catch(console.error);
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteFile = async (userId: number, fileId: number) => {
|
||||
try {
|
||||
const { path } = await unregisterFile(userId, fileId);
|
||||
unlink(path); // Intended
|
||||
const { path, thumbnailPath } = await unregisterFile(userId, fileId);
|
||||
safeUnlink(path); // Intended
|
||||
safeUnlink(thumbnailPath); // Intended
|
||||
} catch (e) {
|
||||
if (e instanceof IntegrityError && e.message === "File not found") {
|
||||
error(404, "Invalid file id");
|
||||
@@ -126,9 +133,7 @@ export const uploadFileThumbnail = async (
|
||||
await pipeline(encContentStream, createWriteStream(path, { flags: "wx", mode: 0o600 }));
|
||||
|
||||
const oldPath = await updateFileThumbnail(userId, fileId, dekVersion, path, encContentIv);
|
||||
if (oldPath) {
|
||||
safeUnlink(oldPath); // Intended
|
||||
}
|
||||
safeUnlink(oldPath); // Intended
|
||||
} catch (e) {
|
||||
await safeUnlink(path);
|
||||
|
||||
@@ -157,10 +162,6 @@ export const scanMissingFileThumbnails = async (userId: number) => {
|
||||
return { files: fileIds };
|
||||
};
|
||||
|
||||
const safeUnlink = async (path: string) => {
|
||||
await unlink(path).catch(console.error);
|
||||
};
|
||||
|
||||
export const uploadFile = async (
|
||||
params: Omit<NewFile, "path" | "encContentHash">,
|
||||
encContentStream: Readable,
|
||||
|
||||
Reference in New Issue
Block a user