-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import affiliated structures of developers (#209)
add affiliated structures on developers resolve #125
- Loading branch information
1 parent
ad810e3
commit 1132753
Showing
8 changed files
with
213 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { HalFetchError, HalStructure } from "./type"; | ||
|
||
export const getHalStructureByAcronym = async (structureAcronym: string): Promise<HalStructure | undefined> => { | ||
const url = `http://api.archives-ouvertes.fr/ref/structure/?fl=*&q=acronym_s:"${encodeURIComponent( | ||
structureAcronym | ||
)}"`; | ||
|
||
const res = await fetch(url, { | ||
signal: AbortSignal.timeout(10000) | ||
}).catch(err => { | ||
console.error(err); | ||
throw new HalFetchError(undefined); | ||
}); | ||
|
||
if (res.status === 429) { | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
return getHalStructureByAcronym(structureAcronym); | ||
} | ||
|
||
if (res.status === 404) { | ||
throw new HalFetchError(res.status); | ||
} | ||
|
||
const json = await res.json(); | ||
|
||
if (json.error) { | ||
throw new HalFetchError(json.error); | ||
} | ||
|
||
// What do to when multiple for one acronym while in code meta only reference to acronym => LIDILEM, EPFL | ||
return json.response.docs?.[0]; // json.response.numFound === 1 ? : undefined; | ||
}; | ||
|
||
export const getHalStructureById = async (docid: number): Promise<HalStructure | undefined> => { | ||
const url = `http://api.archives-ouvertes.fr/ref/structure/?fl=*&q=docid:${docid}`; | ||
|
||
const res = await fetch(url, { | ||
signal: AbortSignal.timeout(10000) | ||
}).catch(err => { | ||
console.error(err); | ||
throw new HalFetchError(undefined); | ||
}); | ||
|
||
if (res.status === 429) { | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
return getHalStructureById(docid); | ||
} | ||
|
||
if (res.status === 404) { | ||
throw new HalFetchError(res.status); | ||
} | ||
|
||
const json = await res.json(); | ||
|
||
if (json.error) { | ||
throw new HalFetchError(json.error); | ||
} | ||
|
||
return json.response.numFound === 1 ? json.response.docs?.[0] : undefined; | ||
}; |
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
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