feat: added delete link functionality
This commit is contained in:
@@ -33,12 +33,16 @@ export default async function (req: NextApiRequest, res: NextApiResponse) {
|
||||
const decryptedPath = AES.decrypt(encryptedPath, AES_SECRET).toString(enc);
|
||||
|
||||
const filePath = path.join(process.cwd(), decryptedPath);
|
||||
const file = fs.readFileSync(filePath);
|
||||
const file = fs.existsSync(filePath)
|
||||
? fs.readFileSync(filePath)
|
||||
: "File not found, it's possible that the file you're looking for either doesn't exist or hasn't been created yet.";
|
||||
|
||||
if (filePath.endsWith(".pdf"))
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
if (!fs.existsSync(filePath))
|
||||
res.setHeader("Content-Type", "text/plain").status(404);
|
||||
else if (filePath.endsWith(".pdf"))
|
||||
res.setHeader("Content-Type", "application/pdf").status(200);
|
||||
else if (filePath.endsWith(".png"))
|
||||
res.setHeader("Content-Type", "image/png").status(200);
|
||||
|
||||
if (filePath.endsWith(".png")) res.setHeader("Content-Type", "image/png");
|
||||
|
||||
return res.status(200).send(file);
|
||||
return res.send(file);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import getLinks from "@/lib/api/controllers/links/getLinks";
|
||||
import postLink from "@/lib/api/controllers/links/postLink";
|
||||
import deleteLink from "@/lib/api/controllers/links/deleteLink";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
@@ -19,5 +20,6 @@ export default async function (
|
||||
}
|
||||
|
||||
if (req.method === "GET") return await getLinks(req, res, session);
|
||||
if (req.method === "POST") return await postLink(req, res, session);
|
||||
else if (req.method === "POST") return await postLink(req, res, session);
|
||||
else if (req.method === "DELETE") return await deleteLink(req, res, session);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user