feat: update file manager

This commit is contained in:
2024-04-04 06:40:16 +07:00
parent 1160b30c3d
commit 2ba5da4b73
11 changed files with 199 additions and 36 deletions
+22
View File
@@ -0,0 +1,22 @@
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 });
};
+3 -1
View File
@@ -6,6 +6,7 @@ import { download } from "./download";
import { getYtdl, ytdl } from "./ytdl";
import cache from "../../middlewares/cache";
import { getId3Tags, getId3Image } from "./id3Tags";
import { deleteFile } from "./delete";
const cacheFile = cache({ ttl: 86400 });
@@ -16,6 +17,7 @@ const route = new Hono()
.get("/ytdl/:id", getYtdl)
.get("/download/*", cacheFile, download)
.get("/id3-tags/*", cacheFile, getId3Tags)
.get("/id3-img/*", cacheFile, getId3Image);
.get("/id3-img/*", cacheFile, getId3Image)
.delete("/delete", deleteFile);
export default route;