-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move data collect from client to server
- Loading branch information
Showing
10 changed files
with
243 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
VITE_API=/api | ||
VITE_APP_NAME="Works finder" | ||
VITE_BSO_MAX_SIZE=10000 | ||
VITE_BSO_DATASETS_INDEX="bso3-datacite-20230413" | ||
VITE_BSO_PUBLICATIONS_INDEX="bso-publications" | ||
VITE_DESCRIPTION="Retrieve the scholarly works of your institution" | ||
VITE_GIT_REPOSITORY_URL="https://github.com/dataesr/works-finder/" | ||
VITE_HEADER_TAG="dev" | ||
VITE_HEADER_TAG=dev | ||
VITE_HEADER_TAG_COLOR="green-emeraude" | ||
VITE_MINISTER_NAME="Minisère de l'enseignement supérieur et de la recherche" | ||
VITE_OPENALEX_PER_PAGE=200 | ||
VITE_OPENALEX_SIZE=10000 | ||
VITE_VERSION=$npm_package_version |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
VITE_BSO_MAX_SIZE=0 | ||
VITE_HEADER_TAG="staging" | ||
VITE_HEADER_TAG=staging |
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import express from 'express'; | ||
|
||
import openalexRouter from './routes/openalex'; | ||
import bsoRouter from './routes/bso'; | ||
import bsoRouter from './routes/bso.routes'; | ||
import openalexRouter from './routes/openalex.routes'; | ||
import worksRouter from './routes/works.routes'; | ||
|
||
const router = new express.Router(); | ||
|
||
router.use(openalexRouter); | ||
router.use(bsoRouter); | ||
router.use(openalexRouter); | ||
router.use(worksRouter); | ||
|
||
export default router; |
File renamed without changes.
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,56 @@ | ||
import express from 'express'; | ||
|
||
import { | ||
getBsoCount, | ||
getBsoWorks, | ||
getOpenAlexPublications, | ||
mergePublications, | ||
} from '../utils'; | ||
|
||
const router = new express.Router(); | ||
|
||
router.route('/works') | ||
.get(async (req, res) => { | ||
try { | ||
const options = req?.query ?? {}; | ||
if (!options?.affiliations) { | ||
res.status(400).json({ message: 'You must provide at least one affiliation.' }); | ||
} else { | ||
const data = { datasets: [], publications: [], total: {} }; | ||
const publications = await Promise.all([ | ||
getBsoWorks({ options, index: process.env.VITE_BSO_PUBLICATIONS_INDEX }), | ||
getOpenAlexPublications(options), | ||
]); | ||
publications.forEach((publication) => { | ||
data.publications = [...data.publications, ...publication.results]; | ||
data.total[publication.datasource] = publication.total; | ||
}); | ||
const dataset = await getBsoWorks({ options, index: process.env.VITE_BSO_DATASETS_INDEX }); | ||
data.datasets = [...data.datasets, ...dataset.results]; | ||
data.total.dataset = dataset.total; | ||
if ((Number(data.total.bso) === 0) || (Number(data.total.bso) === Number(process.env.VITE_BSO_MAX_SIZE))) { | ||
const { count } = await getBsoCount(options); | ||
data.total.bso = count; | ||
} | ||
// Deduplicate publications by DOI or by hal_id | ||
data.total.all = data.publications.length; | ||
const deduplicatedPublications = {}; | ||
data.publications.forEach((publication) => { | ||
const id = publication?.doi ?? publication?.primary_location?.landing_page_url?.split('/')?.pop() ?? publication.id; | ||
if (!Object.keys(deduplicatedPublications).includes(id)) { | ||
deduplicatedPublications[id] = publication; | ||
} else { | ||
deduplicatedPublications[id] = mergePublications(deduplicatedPublications[id], publication); | ||
} | ||
}); | ||
data.publications = Object.values(deduplicatedPublications); | ||
data.total.deduplicated = Object.values(deduplicatedPublications).length; | ||
res.status(200).json(data); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
res.status(500).json({ message: 'Internal Server Error.' }); | ||
} | ||
}); | ||
|
||
export default router; |
Oops, something went wrong.