Spaces:
Paused
Paused
Download src/utils/filesystem/deleteFileIfExists.mts from jbilcke-hf/VideoChain-API: direct link, hf CLI and curl.
- Browser
- Download file 498 Bytes
-
https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/deleteFileIfExists.mts
- Command line
-
hf download hf://spaces/jbilcke-hf/VideoChain-API@cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/deleteFileIfExists.mts
-
curl -L -o deleteFileIfExists.mts https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/deleteFileIfExists.mts
498 Bytes
| import { existsSync, promises as fs } from "node:fs" | |
| export const deleteFileIfExists = async (filePath: string) => { | |
| const safePath = filePath.trim() | |
| // just a sanity check | |
| if (safePath.includes("*") ||safePath === "/" || safePath === "~" || safePath === ".") { | |
| throw new Error(`lol, no.`) | |
| } | |
| if (existsSync(filePath)) { | |
| try { | |
| await fs.unlink(safePath) | |
| return true | |
| } catch (err) { | |
| console.log(`failed to delete file ${safePath}`) | |
| } | |
| } | |
| return false | |
| } |