-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Redirects Redirect old Open Vault `/catalog` IDs to their corresponding AAPB guid with https://github.com/WGBH-MLA/organ ```[tasklist] - [x] ~~/exhibits~~ - [x] ~~/collections~~ - [x] /catalog - [x] WGBH-MLA/organ#5 ``` Closes #61
- Loading branch information
Showing
6 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useRouteError } from '@remix-run/react' | ||
import { redirectDocument } from '@remix-run/node' | ||
|
||
export const loader = async ({ params }) => { | ||
let guid = await resolveCatalog(params.catalogId) | ||
console.log(`Redirecting old OV id: ${params.catalogId} to AAPB guid: ${guid}`) | ||
|
||
return redirectDocument(`https://americanarchive.org/catalog/${guid}`) | ||
} | ||
|
||
export async function resolveCatalog(id) { | ||
if (!id.startsWith('A_') && !id.startsWith('V_')) { | ||
throw new Response(`Invalid Open Vault Catalog ID: ${id}`, { | ||
status: 400, | ||
statusText: 'Open Vault Catalog IDs start with "A_" or "V_"', | ||
}) | ||
} | ||
console.log('checking OV id', id) | ||
|
||
// Check Organ for a matching OV catalog ID | ||
const guid = await fetch(`${process.env.ORGAN_URL}/ov/get/${id}`).then( | ||
res => { | ||
if (res.status === 404) { | ||
throw new Response(`Catalog ID not found: ${id}`, { | ||
status: 404, | ||
statusText: 'No matching GUID found for Open Vault Catalog ID', | ||
}) | ||
} | ||
if (res.status !== 200) { | ||
throw new Response(`Error fetching catalog ID`, { | ||
status: res.status, | ||
statusText: res.statusText, | ||
}) | ||
} | ||
return res.json() | ||
} | ||
) | ||
.catch(err => { | ||
if (err instanceof Response) throw err | ||
throw new Response(`Error fetching catalog ID`, { | ||
status: 500, | ||
statusText: 'An error occured while resolving this old Open Vault catalog ID. Please try again later.', | ||
}) | ||
}) | ||
console.log('Resolved guid!', guid) | ||
// It's an older code, sir, but it checks out. I was about to redirect them. | ||
return guid.guid | ||
} | ||
|
||
export const ErrorBoundary = () => { | ||
const error = useRouteError() | ||
console.log('cat error', error) | ||
return ( | ||
<div className="page-body-container"> | ||
{error.status === 404 ? ( | ||
<h1>Not found</h1> | ||
) : ( | ||
<h1>{error.status} Error</h1> | ||
)} | ||
<h3>{error.data}</h3> | ||
<div>{error.statusText}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters