From caac7d29292166ddda01a4fcbd36bf4fa6e8d053 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Fri, 8 Sep 2023 10:56:01 -0400 Subject: [PATCH] Switch to using static routes for archive redirects The dynamic route `circulars.$circularId.tsx` was conflicting with the dynamic route `circulars.archive[.]$suffix[.].tar.ts`. --- .../circulars.archive[.]$suffix[.]tar.ts | 21 ------------------- app/routes/circulars.archive[.]json[.]tar.ts | 17 +++++++++++++++ app/routes/circulars.archive[.]txt[.]tar.ts | 17 +++++++++++++++ app/scheduled/circulars/uploadTar.ts | 12 +++++++++-- 4 files changed, 44 insertions(+), 23 deletions(-) delete mode 100644 app/routes/circulars.archive[.]$suffix[.]tar.ts create mode 100644 app/routes/circulars.archive[.]json[.]tar.ts create mode 100644 app/routes/circulars.archive[.]txt[.]tar.ts diff --git a/app/routes/circulars.archive[.]$suffix[.]tar.ts b/app/routes/circulars.archive[.]$suffix[.]tar.ts deleted file mode 100644 index aa8e90b6d..000000000 --- a/app/routes/circulars.archive[.]$suffix[.]tar.ts +++ /dev/null @@ -1,21 +0,0 @@ -/*! - * Copyright © 2023 United States Government as represented by the - * Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * SPDX-License-Identifier: Apache-2.0 - */ -import { type LoaderArgs, redirect } from '@remix-run/node' -import invariant from 'tiny-invariant' - -import { region, staticBucket } from '~/lib/env.server' -import { getBucketKey } from '~/scheduled/circulars/uploadTar' - -function getBucketUrl(region: string, bucket: string, key: string) { - return `https://s3.${region}.amazonaws.com/${bucket}/${key}` -} - -export async function loader({ params: { suffix } }: LoaderArgs) { - invariant(suffix) - return redirect(getBucketUrl(region, staticBucket, getBucketKey(suffix))) -} diff --git a/app/routes/circulars.archive[.]json[.]tar.ts b/app/routes/circulars.archive[.]json[.]tar.ts new file mode 100644 index 000000000..984b6404b --- /dev/null +++ b/app/routes/circulars.archive[.]json[.]tar.ts @@ -0,0 +1,17 @@ +/*! + * Copyright © 2023 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +import { redirect } from '@remix-run/node' + +import { publicStaticShortTermCacheControlHeaders } from '~/lib/headers.server' +import { getArchiveURL } from '~/scheduled/circulars/uploadTar' + +export function loader() { + return redirect(getArchiveURL('json'), { + headers: publicStaticShortTermCacheControlHeaders, + }) +} diff --git a/app/routes/circulars.archive[.]txt[.]tar.ts b/app/routes/circulars.archive[.]txt[.]tar.ts new file mode 100644 index 000000000..5afd2a26d --- /dev/null +++ b/app/routes/circulars.archive[.]txt[.]tar.ts @@ -0,0 +1,17 @@ +/*! + * Copyright © 2023 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +import { redirect } from '@remix-run/node' + +import { publicStaticShortTermCacheControlHeaders } from '~/lib/headers.server' +import { getArchiveURL } from '~/scheduled/circulars/uploadTar' + +export function loader() { + return redirect(getArchiveURL('txt'), { + headers: publicStaticShortTermCacheControlHeaders, + }) +} diff --git a/app/scheduled/circulars/uploadTar.ts b/app/scheduled/circulars/uploadTar.ts index fbee5a4a3..1d070c14d 100644 --- a/app/scheduled/circulars/uploadTar.ts +++ b/app/scheduled/circulars/uploadTar.ts @@ -13,7 +13,7 @@ import type { Pack } from 'tar-stream' import { pack as tarPack } from 'tar-stream' import type { CircularAction } from './circularAction' -import { staticBucket as Bucket } from '~/lib/env.server' +import { staticBucket as Bucket, region } from '~/lib/env.server' import type { Circular } from '~/routes/circulars/circulars.lib' import { formatCircularJson, @@ -22,10 +22,18 @@ import { const s3 = new S3Client({}) -export function getBucketKey(suffix: string) { +function getBucketKey(suffix: string) { return `circulars/archive.${suffix}.tar` } +function getBucketUrl(region: string, bucket: string, key: string) { + return `https://s3.${region}.amazonaws.com/${bucket}/${key}` +} + +export function getArchiveURL(suffix: string) { + return getBucketUrl(region, Bucket, getBucketKey(suffix)) +} + function createUploadAction( suffix: string, formatter: (circular: Circular) => string