diff --git a/src/api/APIManager.ts b/src/api/APIManager.ts index f557ee7..3634c90 100644 --- a/src/api/APIManager.ts +++ b/src/api/APIManager.ts @@ -1,5 +1,5 @@ import {APIModel} from './APIModel'; -import {APIRequestResult} from './APIRequestResult'; +import {MediaTypeModel} from '../models/MediaTypeModel'; export class APIManager { apis: APIModel[]; @@ -8,10 +8,10 @@ export class APIManager { this.apis = []; } - async query(query: string, types: string[] = []): Promise { + async query(query: string, types: string[] = []): Promise { console.log('MDB | api manager queried'); - let res: APIRequestResult[] = []; + let res: MediaTypeModel[] = []; for (const api of this.apis) { if (types.length === 0 || api.hasTypeOverlap(types)) { diff --git a/src/api/APIModel.ts b/src/api/APIModel.ts index 91bc6e7..f492810 100644 --- a/src/api/APIModel.ts +++ b/src/api/APIModel.ts @@ -1,7 +1,8 @@ -import {APIRequestResult} from './APIRequestResult'; +import {MediaTypeModel} from '../models/MediaTypeModel'; export abstract class APIModel { - name: string; + apiName: string; + apiUrl: string; types: string[]; /** @@ -9,14 +10,7 @@ export abstract class APIModel { * * @param title the title to query for */ - abstract getByTitle(title: string): Promise; - - /** - * This function should return the metadata corresponding to the api result. An implementation should check first, if the result is from this api. - * - * @param item - */ - abstract getMataDataFromResult(item: APIRequestResult): string; + abstract getByTitle(title: string): Promise; hasType(type: string): boolean { return this.types.contains(type); diff --git a/src/api/APIRequestResult.ts b/src/api/APIRequestResult.ts deleted file mode 100644 index 3030089..0000000 --- a/src/api/APIRequestResult.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface APIRequestResult { - title: string, - type: string, - description?: string, - apiName: string, - data: any, -} diff --git a/src/api/apis/TestAPI.ts b/src/api/apis/TestAPI.ts index 42be15c..30471c0 100644 --- a/src/api/apis/TestAPI.ts +++ b/src/api/apis/TestAPI.ts @@ -1,24 +1,25 @@ import {APIModel} from '../APIModel'; -import {APIRequestResult} from '../APIRequestResult'; +import {MediaTypeModel} from '../../models/MediaTypeModel'; export class TestAPI extends APIModel { constructor() { super(); - this.name = 'testAPI'; + this.apiName = 'testAPI'; + this.apiUrl = 'www.test.api'; this.types = ['test']; } - async getByTitle(title: string): Promise { - console.log(`MDB | api "${this.name}" queried`); + async getByTitle(title: string): Promise { + console.log(`MDB | api "${this.apiName}" queried`); return [ - {title: 'test1', type: this.types[0], apiName: this.name, data: {length: 126}} as APIRequestResult, - {title: 'test2', type: this.types[0], apiName: this.name, description: 'some test description', data: {}} as APIRequestResult, + {title: 'test1', type: this.types[0], dataSource: this.apiName} as MediaTypeModel, + {title: 'test2', type: this.types[0], dataSource: this.apiName} as MediaTypeModel, ]; } - getMataDataFromResult(item: APIRequestResult): string { - if (item.apiName !== this.name) { + getMataDataFromResult(item: MediaTypeModel): string { + if (item.dataSource !== this.apiUrl) { return ''; } diff --git a/src/main.ts b/src/main.ts index b80ac82..ea5da16 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import {Plugin} from 'obsidian'; -import {DEFAULT_SETTINGS, MediaDbPluginSettings, MediaDbSettingTab} from './settings/settings'; +import {DEFAULT_SETTINGS, MediaDbPluginSettings, MediaDbSettingTab} from './settings/Settings'; import {MediaDbSearchModal} from './modals/MediaDbSearchModal'; import {APIManager} from './api/APIManager'; import {TestAPI} from './api/apis/TestAPI'; diff --git a/src/modals/MediaDbSearchModal.ts b/src/modals/MediaDbSearchModal.ts index 7632ff5..c3a72d4 100644 --- a/src/modals/MediaDbSearchModal.ts +++ b/src/modals/MediaDbSearchModal.ts @@ -1,14 +1,14 @@ import {App, SuggestModal} from 'obsidian'; -import {APIRequestResult} from '../api/APIRequestResult'; import {APIManager} from '../api/APIManager'; +import {MediaTypeModel} from '../models/MediaTypeModel'; -export class MediaDbSearchModal extends SuggestModal { +export class MediaDbSearchModal extends SuggestModal { query: string; isBusy: boolean; apiManager: APIManager; - onChoose: (err: Error, result?: APIRequestResult) => void; + onChoose: (err: Error, result?: MediaTypeModel) => void; - constructor(app: App, apiManager: APIManager, onChoose?: (err: Error, result?: APIRequestResult) => void) { + constructor(app: App, apiManager: APIManager, onChoose?: (err: Error, result?: MediaTypeModel) => void) { super(app); this.apiManager = apiManager; @@ -16,7 +16,7 @@ export class MediaDbSearchModal extends SuggestModal { this.isBusy = false; } - async search(force: boolean = false): Promise { + async search(force: boolean = false): Promise { if (!this.query) { return; } @@ -48,18 +48,18 @@ export class MediaDbSearchModal extends SuggestModal { } } - async getSuggestions(query: string): Promise { + async getSuggestions(query: string): Promise { this.query = query; return await this.search(); } - renderSuggestion(item: APIRequestResult, el: HTMLElement): void { + renderSuggestion(item: MediaTypeModel, el: HTMLElement): void { el.createEl('div', {text: item.title}); el.createEl('small', {text: item.type}); } - onChooseSuggestion(item: APIRequestResult, evt: MouseEvent | KeyboardEvent): void { + onChooseSuggestion(item: MediaTypeModel, evt: MouseEvent | KeyboardEvent): void { this.onChoose(null, item); } } diff --git a/src/models/MediaTypeModel.ts b/src/models/MediaTypeModel.ts new file mode 100644 index 0000000..bb1c046 --- /dev/null +++ b/src/models/MediaTypeModel.ts @@ -0,0 +1,7 @@ +export abstract class MediaTypeModel { + type: string; + title: string; + dataSource: string; + + abstract toMetaData(): string; +} diff --git a/src/models/MovieModel.ts b/src/models/MovieModel.ts new file mode 100644 index 0000000..21a6c05 --- /dev/null +++ b/src/models/MovieModel.ts @@ -0,0 +1,32 @@ +import {MediaTypeModel} from './MediaTypeModel'; + +export class MovieModel extends MediaTypeModel { + type: string; + title: string; + dataSource: string; + + genres: string[]; + producer: string; + duration: string; + onlineRating: number; + image: string; + + released: boolean; + premiere: string; + + watched: boolean; + lastWatched: string; + personalRating: number; + + + constructor() { + super(); + + this.type = 'movie'; + } + + toMetaData(): string { + return ''; + } + +} diff --git a/src/settings/settings.ts b/src/settings/Settings.ts similarity index 100% rename from src/settings/settings.ts rename to src/settings/Settings.ts diff --git a/src/settings/suggesters/FolderSuggester.ts b/src/settings/suggesters/FolderSuggester.ts index dec6717..713d184 100644 --- a/src/settings/suggesters/FolderSuggester.ts +++ b/src/settings/suggesters/FolderSuggester.ts @@ -1,7 +1,7 @@ // Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes import {TAbstractFile, TFolder} from 'obsidian'; -import {TextInputSuggest} from './suggest'; +import {TextInputSuggest} from './Suggest'; export class FolderSuggest extends TextInputSuggest { getSuggestions(inputStr: string): TFolder[] { diff --git a/src/settings/suggesters/suggest.ts b/src/settings/suggesters/Suggest.ts similarity index 99% rename from src/settings/suggesters/suggest.ts rename to src/settings/suggesters/Suggest.ts index b3d1f06..366da4b 100644 --- a/src/settings/suggesters/suggest.ts +++ b/src/settings/suggesters/Suggest.ts @@ -2,7 +2,7 @@ import {App, ISuggestOwner, Scope} from 'obsidian'; import {createPopper, Instance as PopperInstance} from '@popperjs/core'; -import {wrapAround} from 'src/utils/utils'; +import {wrapAround} from 'src/utils/Utils'; export class Suggest { private owner: ISuggestOwner; diff --git a/src/utils/utils.ts b/src/utils/Utils.ts similarity index 100% rename from src/utils/utils.ts rename to src/utils/Utils.ts