Skip to content

Commit

Permalink
fix some small things
Browse files Browse the repository at this point in the history
  • Loading branch information
mProjectsCode committed Jun 22, 2024
1 parent 4dcffab commit 1fb0939
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
15 changes: 6 additions & 9 deletions src/api/APIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ export class APIManager {
async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> {
console.debug(`MDB | api manager queried with "${query}"`);

let res: MediaTypeModel[] = [];

for (const api of this.apis) {
if (apisToQuery.contains(api.apiName)) {
const promises = this.apis
.filter(api => apisToQuery.contains(api.apiName))
.map(async api => {
try {
const apiRes = await api.searchByTitle(query);
res = res.concat(apiRes);
return await api.searchByTitle(query);
} catch (e) {
console.warn(e);
}
}
}
});

return res;
return (await Promise.all(promises)).flat();
}

/**
Expand Down
11 changes: 3 additions & 8 deletions src/api/APIModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ export abstract class APIModel {

abstract getById(id: string): Promise<MediaTypeModel>;

hasType(_type: MediaType): boolean {
hasType(type: MediaType): boolean {
// 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;
// }
return true;
return this.types.contains(type);
}

hasTypeOverlap(types: MediaType[]): boolean {
for (const type of types) {
if (this.hasType(type)) {
return true;
}
}
return false;
return types.some(type => this.hasType(type));
}
}
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin {
types = searchModalData.types;
const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName);
try {
console.log(apis);
return await this.apiManager.query(searchModalData.query, apis);
} catch (e) {
console.warn(e);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ModalHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
import { MediaType } from './MediaType';

export enum ModalResultCode {
SUCCESS,
SKIP,
CLOSE,
ERROR,
SUCCESS = 'SUCCESS',
SKIP = 'SKIP',
CLOSE = 'CLOSE',
ERROR = 'ERROR',
}

/**
Expand Down

0 comments on commit 1fb0939

Please sign in to comment.