File tree Expand file tree Collapse file tree 4 files changed +14
-21
lines changed Expand file tree Collapse file tree 4 files changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -17,20 +17,17 @@ export class APIManager {
1717 async query ( query : string , apisToQuery : string [ ] ) : Promise < MediaTypeModel [ ] > {
1818 console . debug ( `MDB | api manager queried with "${ query } "` ) ;
1919
20- let res : MediaTypeModel [ ] = [ ] ;
21-
22- for ( const api of this . apis ) {
23- if ( apisToQuery . contains ( api . apiName ) ) {
20+ const promises = this . apis
21+ . filter ( api => apisToQuery . contains ( api . apiName ) )
22+ . map ( async api => {
2423 try {
25- const apiRes = await api . searchByTitle ( query ) ;
26- res = res . concat ( apiRes ) ;
24+ return await api . searchByTitle ( query ) ;
2725 } catch ( e ) {
2826 console . warn ( e ) ;
2927 }
30- }
31- }
28+ } ) ;
3229
33- return res ;
30+ return ( await Promise . all ( promises ) ) . flat ( ) ;
3431 }
3532
3633 /**
Original file line number Diff line number Diff line change @@ -18,22 +18,17 @@ export abstract class APIModel {
1818
1919 abstract getById ( id : string ) : Promise < MediaTypeModel > ;
2020
21- hasType ( _type : MediaType ) : boolean {
21+ hasType ( type : MediaType ) : boolean {
2222 // if (
2323 // this.types.contains(type) &&
2424 // (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
2525 // ) {
2626 // return true;
2727 // }
28- return true ;
28+ return this . types . contains ( type ) ;
2929 }
3030
3131 hasTypeOverlap ( types : MediaType [ ] ) : boolean {
32- for ( const type of types ) {
33- if ( this . hasType ( type ) ) {
34- return true ;
35- }
36- }
37- return false ;
32+ return types . some ( type => this . hasType ( type ) ) ;
3833 }
3934}
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin {
195195 types = searchModalData . types ;
196196 const apis = this . apiManager . apis . filter ( x => x . hasTypeOverlap ( searchModalData . types ) ) . map ( x => x . apiName ) ;
197197 try {
198+ console . log ( apis ) ;
198199 return await this . apiManager . query ( searchModalData . query , apis ) ;
199200 } catch ( e ) {
200201 console . warn ( e ) ;
Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
99import { MediaType } from './MediaType' ;
1010
1111export enum ModalResultCode {
12- SUCCESS ,
13- SKIP ,
14- CLOSE ,
15- ERROR ,
12+ SUCCESS = 'SUCCESS' ,
13+ SKIP = 'SKIP' ,
14+ CLOSE = 'CLOSE' ,
15+ ERROR = 'ERROR' ,
1616}
1717
1818/**
You can’t perform that action at this time.
0 commit comments