Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for fetching specific DocMap by manuscript ID #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/fetch-and-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,36 @@ import { exit } from 'process';
import { DocMap } from './docmap';
import { parsePreprintDocMap } from './docmap-parser';

fetch('https://data-hub-api--stg.elifesciences.org/enhanced-preprints/docmaps/v1/index')
.then((data) => data.json())
.then((data) => {
data.docmaps.forEach((docMapStruct: DocMap) => {
const docMapEditableStruct = JSON.parse(JSON.stringify(docMapStruct));
// You can make edits here
const input = process.argv[2] || '';

const docMapJson = JSON.stringify(docMapEditableStruct);
const parsedDocMap = parsePreprintDocMap(docMapJson);
console.log(JSON.stringify(docMapEditableStruct, undefined, ' '));
console.log(JSON.stringify(parsedDocMap, undefined, ' '));
exit(1);
const msid = (input.match(/^[0-9]+$/)) ? input : null;
const docmapUrl = `https://data-hub-api--stg.elifesciences.org/enhanced-preprints/docmaps/v2/${msid ? `by-publisher/elife/get-by-manuscript-id?manuscript_id=${msid}` : 'index'}`;

const processDocmap = (docMapStruct: DocMap) => {
const docMapEditableStruct = JSON.parse(JSON.stringify(docMapStruct));
// You can make edits here

const docMapJson = JSON.stringify(docMapEditableStruct);
const parsedDocMap = parsePreprintDocMap(docMapJson);
console.log(JSON.stringify(docMapEditableStruct, undefined, ' '));
console.log(JSON.stringify(parsedDocMap, undefined, ' '));
};

if (msid || input.length === 0) {
fetch(docmapUrl)
.then((data) => data.json())
.then((data) => {
if (msid) {
processDocmap(data);
exit(1);
}

data.docmaps.forEach((docMapStruct: DocMap) => {
processDocmap(docMapStruct);
exit(1);
});
});
});
} else {
processDocmap(JSON.parse(input));
exit(1);
}