mirror of
https://gitlab.com/Alamantus/Readlebee.git
synced 2025-07-06 16:14:19 +02:00
Update Inventaire bookData class to include source
This commit is contained in:
parent
5ab6d36314
commit
3600dd3d09
1 changed files with 14 additions and 8 deletions
|
@ -9,6 +9,10 @@ class Inventaire {
|
||||||
return 'https://inventaire.io';
|
return 'https://inventaire.io';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getLink(uri) {
|
||||||
|
return `${Inventaire.url}/entity/${uri}`;
|
||||||
|
}
|
||||||
|
|
||||||
static handleQuickEntity(entityObject) {
|
static handleQuickEntity(entityObject) {
|
||||||
return {
|
return {
|
||||||
name: (
|
name: (
|
||||||
|
@ -21,9 +25,10 @@ class Inventaire {
|
||||||
? entityObject.description
|
? entityObject.description
|
||||||
: null
|
: null
|
||||||
),
|
),
|
||||||
|
source: 'inventaire',
|
||||||
link: (
|
link: (
|
||||||
typeof entityObject.uri !== 'undefined'
|
typeof entityObject.uri !== 'undefined'
|
||||||
? `${this.url}/entity/${entityObject.uri}`
|
? `${Inventaire.url}/entity/${entityObject.uri}`
|
||||||
: null
|
: null
|
||||||
),
|
),
|
||||||
uri: (
|
uri: (
|
||||||
|
@ -36,7 +41,7 @@ class Inventaire {
|
||||||
? entityObject.image.map(imageId => {
|
? entityObject.image.map(imageId => {
|
||||||
return {
|
return {
|
||||||
uri: imageId.toString(),
|
uri: imageId.toString(),
|
||||||
url: `${this.url}/img/entities/${imageId}`,
|
url: `${Inventaire.url}/img/entities/${imageId}`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
: []
|
: []
|
||||||
|
@ -67,9 +72,10 @@ class Inventaire {
|
||||||
: null
|
: null
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
source: 'inventaire',
|
||||||
link: (
|
link: (
|
||||||
typeof entityObject.uri !== 'undefined'
|
typeof entityObject.uri !== 'undefined'
|
||||||
? `${this.url}/entity/${entityObject.uri}`
|
? `${Inventaire.url}/entity/${entityObject.uri}`
|
||||||
: null
|
: null
|
||||||
),
|
),
|
||||||
uri: (
|
uri: (
|
||||||
|
@ -82,7 +88,7 @@ class Inventaire {
|
||||||
|
|
||||||
async getBookData(uri) {
|
async getBookData(uri) {
|
||||||
if (uri) {
|
if (uri) {
|
||||||
const request = fetch(`${this.url}/api/entities?action=by-uris&uris=${encodeURIComponent(uri)}`)
|
const request = fetch(`${Inventaire.url}/api/entities?action=by-uris&uris=${encodeURIComponent(uri)}`)
|
||||||
request.catch(exception => {
|
request.catch(exception => {
|
||||||
console.error(exception);
|
console.error(exception);
|
||||||
return {
|
return {
|
||||||
|
@ -103,7 +109,7 @@ class Inventaire {
|
||||||
|
|
||||||
if (typeof bookData.entities !== 'undefined' && typeof bookData.entities[uri] !== 'undefined') {
|
if (typeof bookData.entities !== 'undefined' && typeof bookData.entities[uri] !== 'undefined') {
|
||||||
const bookData = Inventaire.handleEntity(bookData.entities[uri], this.lang);
|
const bookData = Inventaire.handleEntity(bookData.entities[uri], this.lang);
|
||||||
bookData['covers'] = await this.getCovers();
|
bookData['covers'] = await this.getCovers(bookData.uri);
|
||||||
|
|
||||||
return bookData;
|
return bookData;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +126,7 @@ class Inventaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: property `wdt:P629` is a given entity (uri)'s list of editions (ISBNs).
|
// Note: property `wdt:P629` is a given entity (uri)'s list of editions (ISBNs).
|
||||||
const editionsRequest = fetch(`${this.url}/api/entities?action=reverse-claims&uri=${encodeURIComponent(uri)}&property=wdt:P629`)
|
const editionsRequest = fetch(`${Inventaire.url}/api/entities?action=reverse-claims&uri=${encodeURIComponent(uri)}&property=wdt:P629`)
|
||||||
editionsRequest.catch(exception => {
|
editionsRequest.catch(exception => {
|
||||||
console.error(exception);
|
console.error(exception);
|
||||||
return {
|
return {
|
||||||
|
@ -145,7 +151,7 @@ class Inventaire {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isbnsRequest = fetch(`${this.url}/api/entities?action=by-uris&uris=${encodeURIComponent(editionURIs)}`);
|
const isbnsRequest = fetch(`${Inventaire.url}/api/entities?action=by-uris&uris=${encodeURIComponent(editionURIs)}`);
|
||||||
isbnsRequest.catch(exception => {
|
isbnsRequest.catch(exception => {
|
||||||
console.error(exception);
|
console.error(exception);
|
||||||
return {
|
return {
|
||||||
|
@ -175,7 +181,7 @@ class Inventaire {
|
||||||
const entity = responseJSON.entities[key];
|
const entity = responseJSON.entities[key];
|
||||||
return {
|
return {
|
||||||
uri: entity.uri,
|
uri: entity.uri,
|
||||||
url: typeof entity.claims['invp:P2'] !== 'undefined' ? `${this.url}/img/entities/${entity.claims['invp:P2'][0]}` : null,
|
url: typeof entity.claims['invp:P2'] !== 'undefined' ? `${Inventaire.url}/img/entities/${entity.claims['invp:P2'][0]}` : null,
|
||||||
publishDate: typeof entity.claims['wdt:P577'] !== 'undefined' ? entity.claims['wdt:P577'][0] : null,
|
publishDate: typeof entity.claims['wdt:P577'] !== 'undefined' ? entity.claims['wdt:P577'][0] : null,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue