@@ -3,6 +3,7 @@ import type MediaDbPlugin from '../../main';
33import type { MediaTypeModel } from '../../models/MediaTypeModel' ;
44import { MediaType } from '../../utils/MediaType' ;
55import { APIModel } from '../APIModel' ;
6+ import { requestUrl } from 'obsidian' ;
67
78export class OpenLibraryAPI extends APIModel {
89 plugin : MediaDbPlugin ;
@@ -53,14 +54,24 @@ export class OpenLibraryAPI extends APIModel {
5354 console . log ( `MDB | api "${ this . apiName } " queried by ID` ) ;
5455
5556 const searchUrl = `https://openlibrary.org/search.json?q=${ encodeURIComponent ( id ) } &fields=key,title,author_name,number_of_pages_median,first_publish_year,isbn,ratings_score,first_sentence,title_suggest,rating*,cover_edition_key` ;
56- const fetchData = await fetch ( searchUrl ) ;
57+ const fetchData = await requestUrl ( {
58+ url : searchUrl ,
59+ } ) ;
60+ const descriptionUrl = `https://openlibrary.org/${ encodeURIComponent ( id ) } .json` ;
61+ const fetchDescription = await requestUrl ( {
62+ url : descriptionUrl ,
63+ } ) ;
5764 // console.debug(fetchData);
5865
5966 if ( fetchData . status !== 200 ) {
6067 throw Error ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
6168 }
69+ if ( fetchDescription . status !== 200 ) {
70+ throw Error ( `MDB | Received status code ${ fetchDescription . status } from ${ this . apiName } .` ) ;
71+ }
6272
63- const data = await fetchData . json ( ) ;
73+ const data = await fetchData . json ;
74+ const resultdesc = await fetchDescription . json ;
6475 // console.debug(data);
6576 const result = data . docs [ 0 ] ;
6677
@@ -75,7 +86,7 @@ export class OpenLibraryAPI extends APIModel {
7586 englishTitle : result . title_english ?? result . title ,
7687
7788 author : result . author_name ?? 'unknown' ,
78- plot : result . description ?? 'unknown' ,
89+ plot : resultdesc . description ?. value ?? 'unknown' ,
7990 pages : result . number_of_pages_median ?? 'unknown' ,
8091 onlineRating : Number . parseFloat ( Number ( result . ratings_average ?? 0 ) . toFixed ( 2 ) ) ,
8192 image : `https://covers.openlibrary.org/b/OLID/` + result . cover_edition_key + `-L.jpg` ,
0 commit comments