파일을 삭제할 경우 서버와 클라이언트에 저장된 썸네일을 함께 삭제하도록 개선

This commit is contained in:
static
2025-07-06 17:38:04 +09:00
parent 781642fed6
commit 8975a0200d
5 changed files with 59 additions and 29 deletions

View File

@@ -34,12 +34,19 @@ export const getDirectoryInformation = async (userId: number, directoryId: Direc
};
};
const safeUnlink = async (path: string | null) => {
if (path) {
await unlink(path).catch(console.error);
}
};
export const deleteDirectory = async (userId: number, directoryId: number) => {
try {
const files = await unregisterDirectory(userId, directoryId);
return {
files: files.map(({ id, path }) => {
unlink(path); // Intended
files: files.map(({ id, path, thumbnailPath }) => {
safeUnlink(path); // Intended
safeUnlink(thumbnailPath); // Intended
return id;
}),
};