fix some small things

This commit is contained in:
Moritz Jung 2024-06-22 15:53:07 +02:00
parent 4dcffab5b0
commit 1fb09395fd
4 changed files with 14 additions and 21 deletions

View file

@ -17,20 +17,17 @@ export class APIManager {
async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> { async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> {
console.debug(`MDB | api manager queried with "${query}"`); console.debug(`MDB | api manager queried with "${query}"`);
let res: MediaTypeModel[] = []; const promises = this.apis
.filter(api => apisToQuery.contains(api.apiName))
for (const api of this.apis) { .map(async api => {
if (apisToQuery.contains(api.apiName)) {
try { try {
const apiRes = await api.searchByTitle(query); return await api.searchByTitle(query);
res = res.concat(apiRes);
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
} }
} });
}
return res; return (await Promise.all(promises)).flat();
} }
/** /**

View file

@ -18,22 +18,17 @@ export abstract class APIModel {
abstract getById(id: string): Promise<MediaTypeModel>; abstract getById(id: string): Promise<MediaTypeModel>;
hasType(_type: MediaType): boolean { hasType(type: MediaType): boolean {
// if ( // if (
// this.types.contains(type) && // 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) // (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
// ) { // ) {
// return true; // return true;
// } // }
return true; return this.types.contains(type);
} }
hasTypeOverlap(types: MediaType[]): boolean { hasTypeOverlap(types: MediaType[]): boolean {
for (const type of types) { return types.some(type => this.hasType(type));
if (this.hasType(type)) {
return true;
}
}
return false;
} }
} }

View file

@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin {
types = searchModalData.types; types = searchModalData.types;
const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName); const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName);
try { try {
console.log(apis);
return await this.apiManager.query(searchModalData.query, apis); return await this.apiManager.query(searchModalData.query, apis);
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);

View file

@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
import { MediaType } from './MediaType'; import { MediaType } from './MediaType';
export enum ModalResultCode { export enum ModalResultCode {
SUCCESS, SUCCESS = 'SUCCESS',
SKIP, SKIP = 'SKIP',
CLOSE, CLOSE = 'CLOSE',
ERROR, ERROR = 'ERROR',
} }
/** /**