Skip to content

Commit

Permalink
fix nanopub retrieval to make it work with the new w3id.org URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 1, 2023
1 parent f2ff806 commit d32a445
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions nanopub-display/src/nanopub-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,22 @@ export class NanopubDisplay extends LitElement {
super.connectedCallback()

// const np = new Nanopub({url: this.url})
const np = await Nanopub.fetch(this.url)
console.log(np.display())
// const np = await Nanopub.fetch(this.url)
// console.log(np.display())

if (!this.url && !this.rdf) {
this.error = `⚠️ No nanopublication has been provided, use the "url" or "rdf"
attribute to provide the URL, or RDF in the TRiG format, of the nanopublication.`
}

if (!this.error && this.url && !this.rdf) {
if (this.url.startsWith('https://purl.org/np/') && !this.url.endsWith('.trig')) {
this.url = this.url + '.trig'
}
// if (this.url.startsWith('https://purl.org/np/') && !this.url.endsWith('.trig')) {
// this.url = this.url.replace('https://purl.org/np/', 'https://w3id.org/np/') // + '.trig'
// }
try {
const response = await fetch(this.url)
const response = await fetch(this.url, {
headers: {Accept: 'application/trig'}
})
this.rdf = await response.text()
} catch (error) {
this.error = `⚠️ Issue fetching the nanopublication RDF at ${this.url}. ${error}`
Expand Down
4 changes: 2 additions & 2 deletions nanopub-utils/src/lib/nanopub-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface NpStatus {
* Get update status for a nanopub URI in one of the APIs
*/
export const getUpdateStatus = async (npUri: string): Promise<NpStatus> => {
if (npUri.startsWith('https://purl.org/np/')) {
if (npUri.startsWith('https://')) {
// Quick fix as the URIs use http in the triplestore, but users might use the https version of the URI
npUri = npUri.replace('https://purl.org/np/', 'http://purl.org/np/')
npUri = npUri.replace('https://', 'http://')
}
const shuffledApiUrls = [...grlcNpApiUrls].sort(() => 0.5 - Math.random())
return getUpdateStatusX(npUri, shuffledApiUrls)
Expand Down

0 comments on commit d32a445

Please sign in to comment.