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 {
17
17
async query ( query : string , apisToQuery : string [ ] ) : Promise < MediaTypeModel [ ] > {
18
18
console . debug ( `MDB | api manager queried with "${ query } "` ) ;
19
19
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 => {
24
23
try {
25
- const apiRes = await api . searchByTitle ( query ) ;
26
- res = res . concat ( apiRes ) ;
24
+ return await api . searchByTitle ( query ) ;
27
25
} catch ( e ) {
28
26
console . warn ( e ) ;
29
27
}
30
- }
31
- }
28
+ } ) ;
32
29
33
- return res ;
30
+ return ( await Promise . all ( promises ) ) . flat ( ) ;
34
31
}
35
32
36
33
/**
Original file line number Diff line number Diff line change @@ -18,22 +18,17 @@ export abstract class APIModel {
18
18
19
19
abstract getById ( id : string ) : Promise < MediaTypeModel > ;
20
20
21
- hasType ( _type : MediaType ) : boolean {
21
+ hasType ( type : MediaType ) : boolean {
22
22
// if (
23
23
// this.types.contains(type) &&
24
24
// (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
25
25
// ) {
26
26
// return true;
27
27
// }
28
- return true ;
28
+ return this . types . contains ( type ) ;
29
29
}
30
30
31
31
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 ) ) ;
38
33
}
39
34
}
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin {
195
195
types = searchModalData . types ;
196
196
const apis = this . apiManager . apis . filter ( x => x . hasTypeOverlap ( searchModalData . types ) ) . map ( x => x . apiName ) ;
197
197
try {
198
+ console . log ( apis ) ;
198
199
return await this . apiManager . query ( searchModalData . query , apis ) ;
199
200
} catch ( e ) {
200
201
console . warn ( e ) ;
Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
9
9
import { MediaType } from './MediaType' ;
10
10
11
11
export enum ModalResultCode {
12
- SUCCESS ,
13
- SKIP ,
14
- CLOSE ,
15
- ERROR ,
12
+ SUCCESS = 'SUCCESS' ,
13
+ SKIP = 'SKIP' ,
14
+ CLOSE = 'CLOSE' ,
15
+ ERROR = 'ERROR' ,
16
16
}
17
17
18
18
/**
You can’t perform that action at this time.
0 commit comments