2022-03-24 21:24:09 -04:00
|
|
|
import { NextApiRequest, NextApiResponse } from "next"
|
2022-11-12 19:06:23 -05:00
|
|
|
import { prisma } from "@lib/server/prisma"
|
2022-11-12 02:59:33 -05:00
|
|
|
import { parseQueryParam } from "@lib/server/parse-query-param"
|
2022-11-12 20:11:05 -05:00
|
|
|
import { withMethods } from "@lib/api-middleware/with-methods"
|
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")
|
2022-11-12 19:06:23 -05:00
|
|
|
res.status(200).write(file.html)
|
|
|
|
res.end()
|
|
|
|
}
|
2022-11-12 20:11:05 -05:00
|
|
|
|
|
|
|
export default withMethods(["GET"], getRawFile)
|