This commit is contained in:
oitsjustjose 2021-06-21 22:49:11 -05:00
commit 658a783f6a
8 changed files with 29 additions and 24 deletions

View file

@ -37,18 +37,15 @@ const storage = multer.diskStorage({
},
});
const uploader = multer({
storage,
// limits: { fileSize: 17825792 },
}).single("file");
// Image Uploader
const uploader = multer({ storage }).single("file");
// File Uploader
app.put("/api/file", uploader, putFileHandler);
app.get("/f/:slug", getFileHandler);
// Pastebin
// Codebin
app.put("/api/paste", putTxtHandler);
app.get("/p/:slug", getTxtHandler);
// URL Shortener -- LAST for a reason.
app.get("/c/:slug", getTxtHandler);
// URL Shortener
app.put("/api/url", putUrlHandler);
app.get("/:slug", getUrlHandler);
app.get("/api/:slug", getUrlHandler);
export default app;

View file

@ -3,17 +3,13 @@ import URLs from "../../db/url.schema";
export default async (req: Request, res: Response) => {
try {
const url = await URLs.findById(req.params.slug);
if (url) {
res.redirect(url.url);
const obj = await URLs.findById(req.params.slug);
if (obj) {
res.status(200).send(obj.url);
} else {
res.status(404).send();
}
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
return res.status(500).send({ error: ex });
}
};