mirror of
https://github.com/khairul169/home-lab.git
synced 2025-04-29 00:59:36 +07:00
23 lines
551 B
TypeScript
23 lines
551 B
TypeScript
import type { Context } from "hono";
|
|
import { z } from "zod";
|
|
import { getFilePath } from "./utils";
|
|
import fs from "fs";
|
|
import { HTTPException } from "hono/http-exception";
|
|
|
|
const schema = z.object({
|
|
path: z.string().min(1),
|
|
});
|
|
|
|
export const deleteFile = async (c: Context) => {
|
|
const data = schema.parse(await c.req.json());
|
|
const { path } = getFilePath(data.path);
|
|
|
|
if (!fs.existsSync(path)) {
|
|
throw new HTTPException(404, { message: "File not found!" });
|
|
}
|
|
|
|
await fs.promises.unlink(path);
|
|
|
|
return c.json({ result: true });
|
|
};
|