diff --git a/app/components/rfd/MoreDropdown.tsx b/app/components/rfd/MoreDropdown.tsx index e6bbe5c..11f846f 100644 --- a/app/components/rfd/MoreDropdown.tsx +++ b/app/components/rfd/MoreDropdown.tsx @@ -48,6 +48,10 @@ const MoreDropdown = () => { )} + + Download PDF + + View PDF diff --git a/app/routes/rfd.$slug.pdf.download.tsx b/app/routes/rfd.$slug.pdf.download.tsx new file mode 100644 index 0000000..e84dd58 --- /dev/null +++ b/app/routes/rfd.$slug.pdf.download.tsx @@ -0,0 +1,31 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright Oxide Computer Company + */ + +import { redirect, type LoaderFunction } from 'react-router' + +import { authenticate } from '~/services/auth.server' +import { fetchRfdPdf } from '~/services/rfd.server' +import { parseRfdNum } from '~/utils/parseRfdNum' + +export const loader: LoaderFunction = async ({ request, params: { slug } }) => { + const num = parseRfdNum(slug) + if (!num) throw new Response('Not Found', { status: 404 }) + + const user = await authenticate(request) + const rfd = await fetchRfdPdf(num, user) + + if (!rfd || rfd.content.length === 0) throw new Response('Not Found', { status: 404 }) + + const pdf = rfd.content[0] + + if (pdf.source === 'google') { + throw redirect(`https://drive.google.com/uc?export=download&id=${pdf.externalId}`) + } + + throw redirect(pdf.link) +}