-
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.
Implements the OAI-PMH protocol at the '/oai' endpoint.
The endpoint supports both 'GET' and 'POST' requests according to the specification.
- Loading branch information
Showing
15 changed files
with
2,151 additions
and
6 deletions.
There are no files selected for viewing
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
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,63 @@ | ||
const { processRequest } = require("./middleware"); | ||
const { baseUrl } = require("../helpers"); | ||
const { | ||
getRecord, | ||
identify, | ||
listIdentifiers, | ||
listMetadataFormats, | ||
listRecords, | ||
} = require("./oai/verbs"); | ||
const { invalidOaiRequest } = require("./oai/xml-transformer"); | ||
|
||
const allowedVerbs = [ | ||
"GetRecord", | ||
"Identify", | ||
"ListIdentifiers", | ||
"ListMetadataFormats", | ||
"ListRecords", | ||
"ListSets", | ||
]; | ||
|
||
/** | ||
* A function to support the OAI-PMH harvesting specfication | ||
*/ | ||
exports.handler = async (event) => { | ||
event = processRequest(event); | ||
const url = `${baseUrl(event)}oai`; | ||
let verb, identifier, metadataPrefix, resumptionToken; | ||
if (event.requestContext.http.method === "GET") { | ||
verb = event.queryStringParameters?.verb; | ||
identifier = event.queryStringParameters?.identifier; | ||
metadataPrefix = event.queryStringParameters?.metadataPrefix; | ||
resumptionToken = event.queryStringParameters?.resumptionToken; | ||
} else { | ||
const body = new URLSearchParams(event.body); | ||
verb = body.get("verb"); | ||
identifier = body.get("identifier"); | ||
metadataPrefix = body.get("metadataPrefix"); | ||
resumptionToken = body.get("resumptionToken"); | ||
} | ||
|
||
if (!verb) return invalidOaiRequest("badArgument", "Missing required verb"); | ||
|
||
switch (verb) { | ||
case "GetRecord": | ||
return await getRecord(url, identifier, metadataPrefix); | ||
case "Identify": | ||
return await identify(url); | ||
case "ListIdentifiers": | ||
return await listIdentifiers(url, event, metadataPrefix, resumptionToken); | ||
case "ListMetadataFormats": | ||
return await listMetadataFormats(url); | ||
case "ListRecords": | ||
return await listRecords(url, event, metadataPrefix, resumptionToken); | ||
case "ListSets": | ||
return invalidOaiRequest( | ||
"noSetHierarchy", | ||
"This repository does not support Sets", | ||
401 | ||
); | ||
default: | ||
return invalidOaiRequest("badVerb", "Illegal OAI verb"); | ||
} | ||
}; |
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,56 @@ | ||
const { search } = require("../../api/opensearch"); | ||
const { | ||
extractRequestedModels, | ||
modelsToTargets, | ||
} = require("../../api/request/models"); | ||
const fs = require("fs"); | ||
|
||
async function earliestRecordCreateDate() { | ||
const body = { | ||
size: 1, | ||
_source: "create_date", | ||
query: { | ||
bool: { | ||
must: [ | ||
{ term: { api_model: "Work" } }, | ||
{ term: { published: true } }, | ||
{ term: { visibility: "Public" } }, | ||
], | ||
}, | ||
}, | ||
sort: [{ create_date: "desc" }], | ||
}; | ||
const esResponse = await search( | ||
modelsToTargets(extractRequestedModels()), | ||
JSON.stringify(body) | ||
); | ||
const responseBody = JSON.parse(esResponse.body); | ||
return responseBody?.hits?.hits[0]?._source?.create_date; | ||
} | ||
|
||
async function oaiSearch() { | ||
const body = { | ||
size: 5000, | ||
query: { | ||
bool: { | ||
must: [ | ||
{ term: { api_model: "Work" } }, | ||
{ term: { published: true } }, | ||
{ term: { visibility: "Public" } }, | ||
], | ||
}, | ||
}, | ||
sort: [{ create_date: "desc" }], | ||
}; | ||
const esResponse = await search( | ||
modelsToTargets(extractRequestedModels()), | ||
JSON.stringify(body), | ||
{ scroll: "2m" } | ||
); | ||
return { | ||
...esResponse, | ||
expiration: new Date(new Date().getTime() + 2 * 60000).toISOString(), | ||
}; | ||
} | ||
|
||
module.exports = { earliestRecordCreateDate, oaiSearch }; |
Oops, something went wrong.