fix some issues; migrate to bun'
This commit is contained in:
parent
cf3d5c6d6f
commit
54293ac3a1
56 changed files with 1360 additions and 764 deletions
|
|
@ -21,8 +21,12 @@ export class APIManager {
|
|||
|
||||
for (const api of this.apis) {
|
||||
if (apisToQuery.contains(api.apiName)) {
|
||||
const apiRes = await api.searchByTitle(query);
|
||||
res = res.concat(apiRes);
|
||||
try {
|
||||
const apiRes = await api.searchByTitle(query);
|
||||
res = res.concat(apiRes);
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
import { MediaDbPluginSettings } from 'src/settings/Settings';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export abstract class APIModel {
|
||||
|
|
@ -20,7 +19,10 @@ export abstract class APIModel {
|
|||
abstract getById(id: string): Promise<MediaTypeModel>;
|
||||
|
||||
hasType(type: MediaType): boolean {
|
||||
if (this.types.contains(type) && (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] as MediaDbPluginSettings) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] as MediaDbPluginSettings === undefined)) {
|
||||
if (
|
||||
this.types.contains(type) &&
|
||||
(Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
|
||||
// WIP
|
||||
export class LocGovAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
typeMappings: Map<string, string>;
|
||||
|
||||
constructor(plugin: MediaDbPlugin) {
|
||||
super();
|
||||
|
||||
this.plugin = plugin;
|
||||
this.apiName = 'loc.gov API';
|
||||
this.apiDescription = 'A free API for the Library of Congress collections.';
|
||||
this.apiUrl = 'https://libraryofcongress.github.io/data-exploration/index.html';
|
||||
this.types = [];
|
||||
this.typeMappings = new Map<string, string>();
|
||||
// this.typeMappings.set('movie', 'movie');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `https://www.loc.gov/search/?q=${encodeURIComponent(title)}&fo=json&c=20`;
|
||||
const fetchData = await fetch(searchUrl);
|
||||
console.debug(fetchData);
|
||||
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json();
|
||||
console.debug(data);
|
||||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
throw new Error('MDB | Under construction, API implementation not finished');
|
||||
|
||||
// return ret;
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<MediaTypeModel> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `https://www.loc.gov/item/${encodeURIComponent(id)}/?fo=json`;
|
||||
const fetchData = await fetch(searchUrl);
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json();
|
||||
console.debug(data);
|
||||
const result = data.data;
|
||||
|
||||
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||
if (type === undefined) {
|
||||
throw Error(`${result.type.toLowerCase()} is an unsupported type.`);
|
||||
}
|
||||
|
||||
throw new Error('MDB | Under construction, API implementation not finished');
|
||||
|
||||
// return;
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,13 @@ export class SteamAPI extends APIModel {
|
|||
const filteredData = [];
|
||||
|
||||
for (const app of data.applist.apps) {
|
||||
if (app.name.toLowerCase().includes(title.toLowerCase())) {
|
||||
if (
|
||||
app.name
|
||||
.normalize('NFD')
|
||||
.replace(/\p{Diacritic}/gu, '')
|
||||
.toLowerCase()
|
||||
.includes(title.toLowerCase())
|
||||
) {
|
||||
filteredData.push(app);
|
||||
}
|
||||
if (filteredData.length > 20) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue