Restored and updated api toggle

The settings screen where you can toggle each API per media type is now fully automatic and works for each media type that has more than 1 API.
This commit is contained in:
ltctceplrm 2025-03-04 23:01:44 +01:00
parent d54822444a
commit 4de707f29e
2 changed files with 540 additions and 559 deletions

View file

@ -19,13 +19,13 @@ export abstract class APIModel {
abstract getById(id: string): Promise<MediaTypeModel>; abstract getById(id: string): Promise<MediaTypeModel>;
hasType(type: MediaType): boolean { hasType(type: MediaType): boolean {
// if ( if (
// this.types.contains(type) && 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) (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); return false;
} }
hasTypeOverlap(types: MediaType[]): boolean { hasTypeOverlap(types: MediaType[]): boolean {

View file

@ -4,7 +4,7 @@ import { mount } from 'svelte';
import type MediaDbPlugin from '../main'; import type MediaDbPlugin from '../main';
import type { MediaTypeModel } from '../models/MediaTypeModel'; import type { MediaTypeModel } from '../models/MediaTypeModel';
import { MEDIA_TYPES } from '../utils/MediaTypeManager'; import { MEDIA_TYPES } from '../utils/MediaTypeManager';
import { fragWithHTML } from '../utils/Utils'; import { fragWithHTML, unCamelCase } from '../utils/Utils';
import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping'; import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping';
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte'; import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
import { FileSuggest } from './suggesters/FileSuggest'; import { FileSuggest } from './suggesters/FileSuggest';
@ -21,24 +21,35 @@ export interface MediaDbPluginSettings {
openNoteInNewTab: boolean; openNoteInNewTab: boolean;
useDefaultFrontMatter: boolean; useDefaultFrontMatter: boolean;
enableTemplaterIntegration: boolean; enableTemplaterIntegration: boolean;
// TODO: disabled for now, as i currently don't have the time to fix this from the original PR that introduced it (#133) apiToggle: {
// apiToggle: { OMDbAPI: {
// OMDbAPI: { movie: boolean;
// movie: boolean; series: boolean;
// series: boolean; game: boolean;
// game: boolean; };
// }; MALAPI: {
// MALAPI: { movie: boolean;
// movie: boolean; series: boolean;
// series: boolean; };
// }; MALAPIManga: {
// SteamAPI: { comicManga: boolean;
// game: boolean; };
// }; ComicVineAPI: {
// MobyGamesAPI: { comicManga: boolean;
// game: boolean; };
// }; SteamAPI: {
// }; game: boolean;
};
MobyGamesAPI: {
game: boolean;
};
GiantBombAPI: {
game: boolean;
};
VNDBAPI: {
game: boolean;
};
};
movieTemplate: string; movieTemplate: string;
seriesTemplate: string; seriesTemplate: string;
mangaTemplate: string; mangaTemplate: string;
@ -89,23 +100,35 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
openNoteInNewTab: true, openNoteInNewTab: true,
useDefaultFrontMatter: true, useDefaultFrontMatter: true,
enableTemplaterIntegration: false, enableTemplaterIntegration: false,
// apiToggle: { apiToggle: {
// OMDbAPI: { OMDbAPI: {
// movie: true, movie: true,
// series: true, series: true,
// game: true, game: true,
// }, },
// MALAPI: { MALAPI: {
// movie: true, movie: true,
// series: true, series: true,
// }, },
// SteamAPI: { MALAPIManga: {
// game: true, comicManga: true
// }, },
// MobyGamesAPI: { ComicVineAPI: {
// game: true, comicManga: true
// }, },
// }, SteamAPI: {
game: true,
},
MobyGamesAPI: {
game: true,
},
GiantBombAPI: {
game: true,
},
VNDBAPI: {
game: true,
},
},
movieTemplate: '', movieTemplate: '',
seriesTemplate: '', seriesTemplate: '',
mangaTemplate: '', mangaTemplate: '',
@ -310,82 +333,40 @@ export class MediaDbSettingTab extends PluginSettingTab {
}); });
}); });
// containerEl.createEl('h3', { text: 'APIs per media type' }); // Create a map to store APIs for each media type
// containerEl.createEl('h5', { text: 'Movies' }); const mediaTypeApiMap = new Map<string, string[]>();
// new Setting(containerEl)
// .setName('OMDb API') // Populate the map with APIs for each media type
// .setDesc('Use OMDb API for movies.') Object.entries(this.plugin.settings.apiToggle).forEach(([apiName, api]) => {
// .addToggle(cb => { Object.entries(api).forEach(([mediaType]) => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.movie).onChange(data => { if (!mediaTypeApiMap.has(mediaType)) {
// this.plugin.settings.apiToggle.OMDbAPI.movie = data; mediaTypeApiMap.set(mediaType, []);
// void this.plugin.saveSettings(); }
// }); mediaTypeApiMap.get(mediaType)!.push(apiName);
// }); });
// new Setting(containerEl) });
// .setName('MAL API')
// .setDesc('Use MAL API for movies.') // Filter out media types with only one API
// .addToggle(cb => { const filteredMediaTypes = Array.from(mediaTypeApiMap.entries()).filter(([_, apis]) => apis.length > 1);
// cb.setValue(this.plugin.settings.apiToggle.MALAPI.movie).onChange(data => {
// this.plugin.settings.apiToggle.MALAPI.movie = data; // Dynamically create settings based on the filtered media types and their APIs
// void this.plugin.saveSettings(); filteredMediaTypes.forEach(([mediaType, apis]) => {
// }); new Setting(containerEl).setName(`Select APIs for ${unCamelCase(mediaType)}`).setHeading();
// }); apis.forEach(apiName => {
// containerEl.createEl('h5', { text: 'Series' }); const apiToggle = this.plugin.settings.apiToggle[apiName as keyof typeof this.plugin.settings.apiToggle];
// new Setting(containerEl) new Setting(containerEl)
// .setName('OMDb API') .setName(apiName)
// .setDesc('Use OMDb API for series.') .setDesc(`Use ${apiName} API for ${unCamelCase(mediaType)}.`)
// .addToggle(cb => { .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.series).onChange(data => { cb.setValue((apiToggle as Record<string, boolean>)[mediaType])
// this.plugin.settings.apiToggle.OMDbAPI.series = data; .onChange(data => {
// void this.plugin.saveSettings(); (apiToggle as Record<string, boolean>)[mediaType] = data;
// }); void this.plugin.saveSettings();
// }); });
// new Setting(containerEl) });
// .setName('MAL API') });
// .setDesc('Use MAL API for series.') });
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.MALAPI.series).onChange(data => {
// this.plugin.settings.apiToggle.MALAPI.series = data;
// void this.plugin.saveSettings();
// });
// });
// containerEl.createEl('h5', { text: 'Games' });
// new Setting(containerEl)
// .setName('OMDb API')
// .setDesc('Use OMDb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.OMDbAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('Steam API')
// .setDesc('Use OMDb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.SteamAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.SteamAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('MobyGames API')
// .setDesc('Use MobyGames API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.MobyGamesAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.MobyGamesAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('Giantbomb API')
// .setDesc('Use Giantbomb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.GiantBombAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.GiantBombAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
new Setting(containerEl).setName('New file location').setHeading(); new Setting(containerEl).setName('New file location').setHeading();
// region new file location // region new file location
new Setting(containerEl) new Setting(containerEl)