From f8965637974544d6b53bfc78892e8e38378ae954 Mon Sep 17 00:00:00 2001 From: Soazic Guillaume Bourdat Date: Mon, 26 Jan 2026 10:57:59 +0100 Subject: [PATCH] feat: add get all ids on HAL see: #515 --- api/src/core/adapters/hal/HalAPI/index.ts | 19 +++++++++++++++++++ api/src/core/usecases/importFromSource.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/src/core/adapters/hal/HalAPI/index.ts b/api/src/core/adapters/hal/HalAPI/index.ts index 12ee993f0..29bc340eb 100644 --- a/api/src/core/adapters/hal/HalAPI/index.ts +++ b/api/src/core/adapters/hal/HalAPI/index.ts @@ -8,6 +8,8 @@ import { HAL } from "./types/HAL"; const HAL_API_TIMEOUT = 60000; +type HALID = Pick; + export type HALAPIGateway = { software: { getById: (halDocid: string) => Promise; @@ -15,6 +17,7 @@ export type HALAPIGateway = { queryString?: string | undefined; SWHFilter?: boolean | undefined; }) => Promise; + getAllIds: (params: { queryString?: string | undefined; SWHFilter?: boolean | undefined }) => Promise; getCodemetaByUrl: (urlSoftwareDoc: string) => Promise; }; domain: { @@ -115,6 +118,22 @@ export const makeHalAPIGateway = (source?: Source): HALAPIGateway => { const json = await getHalApiRequest(url); return json?.response?.docs ?? []; }, + getAllIds: async (params: { queryString?: string; SWHFilter?: boolean }) => { + const { queryString, SWHFilter } = params; + let url = `https://api.archives-ouvertes.fr/search/?fq=docType_s:SOFTWARE&rows=10000&fl:docid`; + + if (queryString) { + url = url + `&q=${encodeURIComponent(queryString)}`; + } + + // Filter only software who have an swhidId to filter clean data on https://hal.science, TODO remove and set it as an option to be generic + if (SWHFilter) { + url = url + `&fq=swhidId_s:["" TO *]`; + } + + const json = await getHalApiRequest(url); + return json?.response?.docs ?? []; + }, getCodemetaByUrl: (urlSoftwareDoc: string) => { const url = `${urlSoftwareDoc}/codemeta`; return getHalRequest(url); diff --git a/api/src/core/usecases/importFromSource.ts b/api/src/core/usecases/importFromSource.ts index 794cabe51..76b713fd5 100644 --- a/api/src/core/usecases/importFromSource.ts +++ b/api/src/core/usecases/importFromSource.ts @@ -63,7 +63,7 @@ const resolveAllIdsAccordingToSource = async (source: Source): Promise switch (source.kind) { case "HAL": const halAPIGateway = makeHalAPIGateway(source); - return (await halAPIGateway.software.getAll({ SWHFilter: true })).map(doc => doc.docid); + return (await halAPIGateway.software.getAllIds({ SWHFilter: true })).map(doc => doc.docid); case "Zenodo": const zenodoAPI = makeZenodoApi(source); return (await zenodoAPI.records.getAllSoftware()).hits.hits.map(item => item.id.toString());