it creates files now

This commit is contained in:
mProjectsCode 2022-05-04 21:04:38 +02:00
parent c67a0bf590
commit 4405eb4a34
7 changed files with 61 additions and 19 deletions

View file

@ -15,7 +15,7 @@ export class APIManager {
for (const api of this.apis) {
if (types.length === 0 || api.hasTypeOverlap(types)) {
const apiRes = await api.getByTitle(query);
const apiRes = await api.searchByTitle(query);
// console.log(apiRes);
res = res.concat(apiRes);
}
@ -24,6 +24,14 @@ export class APIManager {
return res;
}
async queryDetailedInfo(item: MediaTypeModel): Promise<MediaTypeModel> {
for (const api of this.apis) {
if (api.apiName === item.dataSource) {
return api.getById(item);
}
}
}
registerAPI(api: APIModel): void {
this.apis.push(api);
}

View file

@ -10,7 +10,9 @@ export abstract class APIModel {
*
* @param title the title to query for
*/
abstract getByTitle(title: string): Promise<MediaTypeModel[]>;
abstract searchByTitle(title: string): Promise<MediaTypeModel[]>;
abstract getById(item: MediaTypeModel): Promise<MediaTypeModel>;
hasType(type: string): boolean {
return this.types.contains(type);

View file

@ -1,5 +1,6 @@
import {APIModel} from '../APIModel';
import {MediaTypeModel} from '../../models/MediaTypeModel';
import {MovieModel} from '../../models/MovieModel';
export class TestAPI extends APIModel {
constructor() {
@ -9,20 +10,16 @@ export class TestAPI extends APIModel {
this.types = ['test'];
}
async getByTitle(title: string): Promise<MediaTypeModel[]> {
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried`);
return [
{title: 'test1', type: this.types[0], dataSource: this.apiName} as MediaTypeModel,
{title: 'test2', type: this.types[0], dataSource: this.apiName} as MediaTypeModel,
new MovieModel ({title: 'test_1', type: this.types[0], dataSource: this.apiName}) ,
new MovieModel ({title: 'test_2', type: this.types[0], dataSource: this.apiName, producer: 'Max Musterman'}),
];
}
getMataDataFromResult(item: MediaTypeModel): string {
if (item.dataSource !== this.apiUrl) {
return '';
}
return '';
async getById(item: MediaTypeModel): Promise<MediaTypeModel> {
return item;
}
}