Skip to content

Commit

Permalink
Merge pull request #11184 from wellcomecollection/bd-identification
Browse files Browse the repository at this point in the history
Use new workType to identify BD works
  • Loading branch information
rcantin-w authored Sep 19, 2024
2 parents b8e4db2 + 558fe0d commit c50044d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
5 changes: 3 additions & 2 deletions content/webapp/components/ExpandedImage/ExpandedImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ const ExpandedImage: FunctionComponent<Props> = ({
imageUrl: string
) => {
const imageLocationBase = imageUrl.replace('/info.json', '');
const iiifManifest =
await fetchIIIFPresentationManifest(manifestLocation);
const iiifManifest = await fetchIIIFPresentationManifest({
location: manifestLocation,
});
const transformedManifest =
iiifManifest && transformManifest(iiifManifest);
const { firstCollectionManifestLocation, canvases } = {
Expand Down
2 changes: 1 addition & 1 deletion content/webapp/pages/works/[workId]/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const getServerSideProps: GetServerSideProps<
const manifestLocation = getDigitalLocationOfType(work, 'iiif-presentation');
const iiifManifest =
manifestLocation &&
(await fetchIIIFPresentationManifest(manifestLocation.url));
(await fetchIIIFPresentationManifest({ location: manifestLocation.url }));
const transformedManifest = iiifManifest && transformManifest(iiifManifest);

return {
Expand Down
6 changes: 5 additions & 1 deletion content/webapp/pages/works/[workId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,13 @@ export const getServerSideProps: GetServerSideProps<
work,
'iiif-presentation'
);

const iiifManifest =
iiifPresentationLocation &&
(await fetchIIIFPresentationManifest(iiifPresentationLocation.url));
(await fetchIIIFPresentationManifest({
location: iiifPresentationLocation.url,
workTypeId: work.workType?.id,
}));

const transformedManifest = iiifManifest && transformManifest(iiifManifest);

Expand Down
10 changes: 6 additions & 4 deletions content/webapp/pages/works/[workId]/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ export const getServerSideProps: GetServerSideProps<
);
const iiifManifest =
iiifPresentationLocation &&
(await fetchIIIFPresentationManifest(iiifPresentationLocation.url));
(await fetchIIIFPresentationManifest({
location: iiifPresentationLocation.url,
}));

const transformedManifest = iiifManifest && transformManifest(iiifManifest);

Expand All @@ -418,9 +420,9 @@ export const getServerSideProps: GetServerSideProps<
if (isCollectionManifest) {
const selectedCollectionManifestLocation = manifests?.[manifestIndex]?.id;
const selectedCollectionManifest = selectedCollectionManifestLocation
? await fetchIIIFPresentationManifest(
selectedCollectionManifestLocation
)
? await fetchIIIFPresentationManifest({
location: selectedCollectionManifestLocation,
})
: undefined;
const firstChildTransformedManifest =
selectedCollectionManifest &&
Expand Down
26 changes: 16 additions & 10 deletions content/webapp/services/iiif/fetch/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Manifest } from '@iiif/presentation-3';

async function getIIIFManifest(url: string): Promise<Manifest | undefined> {
async function getIIIFManifest(
url: string,
workTypeId?: string
): Promise<Manifest | undefined> {
try {
const resp = await fetch(url);

if (resp.status === 404) {
const bnumber = url.match(/b[0-9]{7}[0-9x]/)?.[0];

// We have to add this condition because of a known issue with BD works and Archivemetica
// We have to add this condition because of a known issue with BD works and Archivematica
// We don't want the error to be sent if it's part of the known issue.
// https://github.com/wellcomecollection/wellcomecollection.org/issues/10907
// TODO: Check in once in a while to see if it's been fixed. There is not ticket to link to currently for that piece of work.

// TEMP FIX: If location doesn't contain a B number, we assume that it is a Born Digital work.
// This works for now but won't in the future as more BD works come in
// TODO: Change how it's done once https://github.com/wellcomecollection/catalogue-pipeline/issues/2659 is through.
if (bnumber) {
// This workType ID identifies Born Digital works ("Archives - Digital")
// https://github.com/wellcomecollection/catalogue-pipeline/issues/2659
if (workTypeId !== 'hdig') {
const dashboardUrl = `https://iiif.wellcomecollection.org/dash/Manifestation/${bnumber}`;

console.error(
Expand All @@ -37,14 +39,18 @@ async function getIIIFManifest(url: string): Promise<Manifest | undefined> {
}
}

export async function fetchIIIFPresentationManifest(
location: string
): Promise<Manifest | undefined> {
export async function fetchIIIFPresentationManifest({
location,
workTypeId,
}: {
location: string;
workTypeId?: string;
}): Promise<Manifest | undefined> {
// TODO once we're using v3 everywhere,
// we'll want the catalogue API to return v3, then we can stop doing the following
const v3Location = location.replace('/v2/', '/v3/');

const iiifManifest = await getIIIFManifest(v3Location);
const iiifManifest = await getIIIFManifest(v3Location, workTypeId);

return iiifManifest;
}

0 comments on commit c50044d

Please sign in to comment.