2022-03-24 21:24:09 -04:00
|
|
|
import { NextApiRequest, NextApiResponse } from "next"
|
2022-11-12 02:59:33 -05:00
|
|
|
import prisma from "lib/server/prisma"
|
|
|
|
import { parseQueryParam } from "@lib/server/parse-query-param"
|
2022-03-24 21:24:09 -04:00
|
|
|
|
|
|
|
const getRawFile = async (req: NextApiRequest, res: NextApiResponse) => {
|
2022-11-12 02:59:33 -05:00
|
|
|
const file = await prisma.file.findUnique({
|
|
|
|
where: {
|
|
|
|
id: parseQueryParam(req.query.id)
|
2022-03-25 17:31:10 -04:00
|
|
|
}
|
|
|
|
})
|
2022-11-12 02:59:33 -05:00
|
|
|
|
|
|
|
if (!file) {
|
|
|
|
return res.status(404).end()
|
2022-03-25 17:31:10 -04:00
|
|
|
}
|
2022-11-12 02:59:33 -05:00
|
|
|
|
|
|
|
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)
|
2022-03-24 21:24:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default getRawFile
|