Skip to content

Commit

Permalink
Switch to using static routes for archive redirects
Browse files Browse the repository at this point in the history
The dynamic route `circulars.$circularId.tsx` was conflicting with
the dynamic route `circulars.archive[.]$suffix[.].tar.ts`.
  • Loading branch information
lpsinger committed Sep 8, 2023
1 parent f9933c4 commit caac7d2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
21 changes: 0 additions & 21 deletions app/routes/circulars.archive[.]$suffix[.]tar.ts

This file was deleted.

17 changes: 17 additions & 0 deletions app/routes/circulars.archive[.]json[.]tar.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
17 changes: 17 additions & 0 deletions app/routes/circulars.archive[.]txt[.]tar.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
12 changes: 10 additions & 2 deletions app/scheduled/circulars/uploadTar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit caac7d2

Please sign in to comment.