summary refs log tree commit diff
path: root/src/routes/attachments.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/routes/attachments.ts22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/routes/attachments.ts b/src/routes/attachments.ts

index f477d1b2..3bbced31 100644 --- a/src/routes/attachments.ts +++ b/src/routes/attachments.ts
@@ -1,21 +1,13 @@ import { Router } from "express"; -import multer from "multer"; import { Config, Snowflake } from "@fosscord/server-util"; import { storage } from "../util/Storage"; import FileType from "file-type"; import { HTTPError } from "lambert-server"; +import { multer } from "../Server"; -const multer_ = multer({ - storage: multer.memoryStorage(), - limits: { - fields: 0, - files: 1, - fileSize: 1024 * 1024 * 100, // 100 mb - }, -}); const router = Router(); -router.post("/:channel_id", multer_.single("file"), async (req, res) => { +router.post("/:channel_id", multer.single("file"), async (req, res) => { const { buffer, mimetype, size, originalname, fieldname } = req.file; const { channel_id } = req.params; const filename = originalname.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, ""); @@ -31,7 +23,7 @@ router.post("/:channel_id", multer_.single("file"), async (req, res) => { content_type: mimetype, filename: filename, size, - url: `${endpoint}/attachments/${channel_id}/${id}/${filename}`, + url: `${endpoint}/${path}`, }; return res.json(file); @@ -42,9 +34,9 @@ router.get("/:channel_id/:id/:filename", async (req, res) => { const file = await storage.get(`attachments/${channel_id}/${id}/${filename}`); if (!file) throw new HTTPError("File not found"); - const result = await FileType.fromBuffer(file); + const type = await FileType.fromBuffer(file); - res.set("Content-Type", result?.mime); + res.set("Content-Type", type?.mime); return res.send(file); }); @@ -53,9 +45,9 @@ router.delete("/:channel_id/:id/:filename", async (req, res) => { const { channel_id, id, filename } = req.params; const path = `attachments/${channel_id}/${id}/${filename}`; - storage.delete(path); + await storage.delete(path); - return res.send({ success: true, message: "attachment deleted" }); + return res.send({ success: true }); }); export default router;