@@ -3,6 +3,7 @@ import type MediaDbPlugin from '../../main';
3
3
import type { MediaTypeModel } from '../../models/MediaTypeModel' ;
4
4
import { MediaType } from '../../utils/MediaType' ;
5
5
import { APIModel } from '../APIModel' ;
6
+ import { requestUrl } from 'obsidian' ;
6
7
7
8
export class OpenLibraryAPI extends APIModel {
8
9
plugin : MediaDbPlugin ;
@@ -53,14 +54,24 @@ export class OpenLibraryAPI extends APIModel {
53
54
console . log ( `MDB | api "${ this . apiName } " queried by ID` ) ;
54
55
55
56
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
+ } ) ;
57
64
// console.debug(fetchData);
58
65
59
66
if ( fetchData . status !== 200 ) {
60
67
throw Error ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
61
68
}
69
+ if ( fetchDescription . status !== 200 ) {
70
+ throw Error ( `MDB | Received status code ${ fetchDescription . status } from ${ this . apiName } .` ) ;
71
+ }
62
72
63
- const data = await fetchData . json ( ) ;
73
+ const data = await fetchData . json ;
74
+ const resultdesc = await fetchDescription . json ;
64
75
// console.debug(data);
65
76
const result = data . docs [ 0 ] ;
66
77
@@ -75,7 +86,7 @@ export class OpenLibraryAPI extends APIModel {
75
86
englishTitle : result . title_english ?? result . title ,
76
87
77
88
author : result . author_name ?? 'unknown' ,
78
- plot : result . description ?? 'unknown' ,
89
+ plot : resultdesc . description ?. value ?? 'unknown' ,
79
90
pages : result . number_of_pages_median ?? 'unknown' ,
80
91
onlineRating : Number . parseFloat ( Number ( result . ratings_average ?? 0 ) . toFixed ( 2 ) ) ,
81
92
image : `https://covers.openlibrary.org/b/OLID/` + result . cover_edition_key + `-L.jpg` ,
0 commit comments