Added approach to allow versioning of PDFs (Requires env var!)

This commit is contained in:
Joao Ramos
2024-02-05 20:01:50 +00:00
parent 8baa25c445
commit 934394b17f
2 changed files with 20 additions and 12 deletions

View File

@@ -106,18 +106,20 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
results: any;
exams: {module: Module}[];
startDate: string;
pdf?: string;
pdf: {
path: string,
version: string,
},
};
if (!data) {
res.status(400).end();
return;
}
if (data.pdf) {
if (data.pdf && data.pdf.path && data.pdf.version === process.env.PDF_VERSION) {
// if it does, return the pdf url
const fileRef = ref(storage, data.pdf);
const fileRef = ref(storage, data.pdf.path);
const url = await getDownloadURL(fileRef);
res.status(200).end(url);
return;
}
@@ -387,7 +389,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
// update the stats entries with the pdf url to prevent duplication
await updateDoc(docSnap.ref, {
pdf: refName,
pdf: {
path: refName,
version: process.env.PDF_VERSION,
},
});
const url = await getDownloadURL(fileRef);
res.status(200).end(url);
@@ -419,8 +424,8 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
return;
}
if (data.pdf) {
const fileRef = ref(storage, data.pdf);
if (data.pdf?.path) {
const fileRef = ref(storage, data.pdf.path);
const url = await getDownloadURL(fileRef);
return res.redirect(url);
}