CoastalCommitsPastes/client/pages/api/file/html/[id].ts

25 lines
629 B
TypeScript
Raw Normal View History

import { NextApiRequest, NextApiResponse } from "next"
2022-11-12 03:58:21 -05:00
import prisma from "@lib/server/prisma"
import { parseQueryParam } from "@lib/server/parse-query-param"
const getRawFile = async (req: NextApiRequest, res: NextApiResponse) => {
const file = await prisma.file.findUnique({
where: {
id: parseQueryParam(req.query.id)
}
})
console.log("file", file, "id", req.query.id)
if (!file) {
return res.status(404).end()
}
res.setHeader("Content-Type", "text/plain")
res.setHeader("Cache-Control", "public, max-age=4800")
console.log(file.html)
return res.status(200).write(file.html)
}
export default getRawFile