We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent da4562d commit 970e1f4Copy full SHA for 970e1f4
server/src/storage/delete-file.ts
@@ -1,7 +1,22 @@
1
import { getFilePath } from './get-file-path';
2
import { promises } from 'fs';
3
4
-export function deleteFile(id: string): Promise<void> {
+async function fileExists(path: string): Promise<boolean> {
5
+ try {
6
+ await promises.stat(path);
7
+ return true;
8
+ } catch (e) {
9
+ return false;
10
+ }
11
+}
12
+
13
+export async function deleteFile(id: string): Promise<void> {
14
const filePath = getFilePath(id);
15
16
+ const exists = await fileExists(filePath);
17
+ if (!exists) {
18
+ return;
19
20
21
return promises.unlink(filePath);
22
}
0 commit comments