1- import createClient from 'openapi-fetch' ;
2- import { obsidianFetch } from 'src/utils/Utils' ;
1+ import { requestUrl } from 'obsidian' ;
32import type MediaDbPlugin from '../../main' ;
43import { GameModel } from '../../models/GameModel' ;
54import type { MediaTypeModel } from '../../models/MediaTypeModel' ;
65import { MovieModel } from '../../models/MovieModel' ;
76import { SeriesModel } from '../../models/SeriesModel' ;
87import { MediaType } from '../../utils/MediaType' ;
98import { APIModel } from '../APIModel' ;
10- import type { paths } from '../schemas/OMDb' ;
9+
10+ interface ErrorResponse {
11+ Response : 'False' ;
12+ Error : string ;
13+ }
1114
1215type SearchResponse =
1316 | {
@@ -21,10 +24,7 @@ type SearchResponse =
2124 Type : string ;
2225 } [ ] ;
2326 }
24- | {
25- Response : 'False' ;
26- Error : string ;
27- } ;
27+ | ErrorResponse ;
2828
2929type IdResponse =
3030 | {
@@ -53,10 +53,7 @@ type IdResponse =
5353 Production : string ;
5454 Website : string ;
5555 }
56- | {
57- Response : 'False' ;
58- Error : string ;
59- } ;
56+ | ErrorResponse ;
6057
6158export class OMDbAPI extends APIModel {
6259 plugin : MediaDbPlugin ;
@@ -84,26 +81,19 @@ export class OMDbAPI extends APIModel {
8481 throw new Error ( `MDB | API key for ${ this . apiName } missing.` ) ;
8582 }
8683
87- const client = createClient < paths > ( { baseUrl : 'https://www.omdbapi.com/' } ) ;
88-
89- const response = await client . GET ( '/?s' , {
90- params : {
91- query : {
92- s : title ,
93- apikey : this . plugin . settings . OMDbKey ,
94- } ,
95- } ,
96- fetch : obsidianFetch ,
84+ const response = await requestUrl ( {
85+ url : `https://www.omdbapi.com/?s=${ encodeURIComponent ( title ) } &apikey=${ this . plugin . settings . OMDbKey } ` ,
86+ method : 'GET' ,
9787 } ) ;
9888
99- if ( response . response . status === 401 ) {
89+ if ( response . status === 401 ) {
10090 throw Error ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
10191 }
102- if ( response . response . status !== 200 ) {
103- throw Error ( `MDB | Received status code ${ response . response . status } from ${ this . apiName } .` ) ;
92+ if ( response . status !== 200 ) {
93+ throw Error ( `MDB | Received status code ${ response . status } from ${ this . apiName } .` ) ;
10494 }
10595
106- const data = response . data as SearchResponse | undefined ;
96+ const data = response . json as SearchResponse | undefined ;
10797
10898 if ( ! data ) {
10999 throw Error ( `MDB | No data received from ${ this . apiName } .` ) ;
@@ -175,26 +165,19 @@ export class OMDbAPI extends APIModel {
175165 throw Error ( `MDB | API key for ${ this . apiName } missing.` ) ;
176166 }
177167
178- const client = createClient < paths > ( { baseUrl : 'https://www.omdbapi.com/' } ) ;
179-
180- const response = await client . GET ( '/?i' , {
181- params : {
182- query : {
183- i : id ,
184- apikey : this . plugin . settings . OMDbKey ,
185- } ,
186- } ,
187- fetch : obsidianFetch ,
168+ const response = await requestUrl ( {
169+ url : `https://www.omdbapi.com/?i=${ encodeURIComponent ( id ) } &apikey=${ this . plugin . settings . OMDbKey } ` ,
170+ method : 'GET' ,
188171 } ) ;
189172
190- if ( response . response . status === 401 ) {
173+ if ( response . status === 401 ) {
191174 throw Error ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
192175 }
193- if ( response . response . status !== 200 ) {
194- throw Error ( `MDB | Received status code ${ response . response . status } from ${ this . apiName } .` ) ;
176+ if ( response . status !== 200 ) {
177+ throw Error ( `MDB | Received status code ${ response . status } from ${ this . apiName } .` ) ;
195178 }
196179
197- const result = response . data as IdResponse | undefined ;
180+ const result = response . json as IdResponse | undefined ;
198181
199182 if ( ! result ) {
200183 throw Error ( `MDB | No data received from ${ this . apiName } .` ) ;
0 commit comments