big changes; we have a good TS config now
This commit is contained in:
parent
cbbaf54b33
commit
4497991344
54 changed files with 750 additions and 671 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { APIModel } from '../APIModel';
|
||||
import { Notice } from 'obsidian';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MovieModel } from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import { SeriesModel } from '../../models/SeriesModel';
|
||||
import type MediaDbPlugin from '../../main';
|
||||
import { GameModel } from '../../models/GameModel';
|
||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MovieModel } from '../../models/MovieModel';
|
||||
import { SeriesModel } from '../../models/SeriesModel';
|
||||
import { MediaType } from '../../utils/MediaType';
|
||||
import { APIModel } from '../APIModel';
|
||||
|
||||
export class OMDbAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -30,9 +30,7 @@ export class OMDbAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
if (!this.plugin.settings.OMDbKey) {
|
||||
console.error(new Error(`MDB | API key for ${this.apiName} missing.`));
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
return [];
|
||||
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
}
|
||||
|
||||
const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
|
|
@ -76,7 +74,7 @@ export class OMDbAPI extends APIModel {
|
|||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as MovieModel),
|
||||
}),
|
||||
);
|
||||
} else if (type === 'series') {
|
||||
ret.push(
|
||||
|
|
@ -87,7 +85,7 @@ export class OMDbAPI extends APIModel {
|
|||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as SeriesModel),
|
||||
}),
|
||||
);
|
||||
} else if (type === 'game') {
|
||||
ret.push(
|
||||
|
|
@ -98,7 +96,7 @@ export class OMDbAPI extends APIModel {
|
|||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as GameModel),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +108,6 @@ export class OMDbAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
if (!this.plugin.settings.OMDbKey) {
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
}
|
||||
|
||||
|
|
@ -118,11 +115,9 @@ export class OMDbAPI extends APIModel {
|
|||
const fetchData = await fetch(searchUrl);
|
||||
|
||||
if (fetchData.status === 401) {
|
||||
new Notice(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||
}
|
||||
if (fetchData.status !== 200) {
|
||||
new Notice(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +125,6 @@ export class OMDbAPI extends APIModel {
|
|||
// console.debug(result);
|
||||
|
||||
if (result.Response === 'False') {
|
||||
new Notice(`MDB | Received error from ${this.apiName}: ${result.Error}`);
|
||||
throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`);
|
||||
}
|
||||
|
||||
|
|
@ -168,7 +162,7 @@ export class OMDbAPI extends APIModel {
|
|||
lastWatched: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
} as MovieModel);
|
||||
});
|
||||
} else if (type === 'series') {
|
||||
return new SeriesModel({
|
||||
type: type,
|
||||
|
|
@ -200,7 +194,7 @@ export class OMDbAPI extends APIModel {
|
|||
lastWatched: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
} as SeriesModel);
|
||||
});
|
||||
} else if (type === 'game') {
|
||||
return new GameModel({
|
||||
type: type,
|
||||
|
|
@ -224,9 +218,9 @@ export class OMDbAPI extends APIModel {
|
|||
played: false,
|
||||
personalRating: 0,
|
||||
},
|
||||
} as GameModel);
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
throw new Error(`MDB | Unknown media type for id ${id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue