Made several improvements
- Replaced interpolated string to a new function getDisabledMediaTypes() - Added override for every API with the plugin settings for disabled media types - Added _disabledMediaTypes for API's even if they are the only provider of a media type - Replaced static apiMediaTypes to a dynamic version
This commit is contained in:
parent
666ca1e93b
commit
72198abd33
12 changed files with 69 additions and 33 deletions
|
|
@ -9,6 +9,7 @@ import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './
|
|||
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
|
||||
import { FileSuggest } from './suggesters/FileSuggest';
|
||||
import { FolderSuggest } from './suggesters/FolderSuggest';
|
||||
import type { MediaType } from 'src/utils/MediaType';
|
||||
|
||||
export interface MediaDbPluginSettings {
|
||||
OMDbKey: string;
|
||||
|
|
@ -28,6 +29,10 @@ export interface MediaDbPluginSettings {
|
|||
SteamAPI_disabledMediaTypes: string[];
|
||||
MobyGamesAPI_disabledMediaTypes: string[];
|
||||
GiantBombAPI_disabledMediaTypes: string[];
|
||||
WikipediaAPI_disabledMediaTypes: string[];
|
||||
BoardgameGeekAPI_disabledMediaTypes: string[];
|
||||
MusicBrainzAPI_disabledMediaTypes: string[];
|
||||
OpenLibraryAPI_disabledMediaTypes: string[];
|
||||
movieTemplate: string;
|
||||
seriesTemplate: string;
|
||||
mangaTemplate: string;
|
||||
|
|
@ -85,6 +90,10 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
|||
SteamAPI_disabledMediaTypes: [],
|
||||
MobyGamesAPI_disabledMediaTypes: [],
|
||||
GiantBombAPI_disabledMediaTypes: [],
|
||||
WikipediaAPI_disabledMediaTypes: [],
|
||||
BoardgameGeekAPI_disabledMediaTypes: [],
|
||||
MusicBrainzAPI_disabledMediaTypes: [],
|
||||
OpenLibraryAPI_disabledMediaTypes: [],
|
||||
movieTemplate: '',
|
||||
seriesTemplate: '',
|
||||
mangaTemplate: '',
|
||||
|
|
@ -291,23 +300,14 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
|
||||
// Create a map to store APIs for each media type
|
||||
const mediaTypeApiMap = new Map<string, string[]>();
|
||||
const apiMediaTypes = {
|
||||
OMDbAPI: ['movie', 'series', 'game'],
|
||||
MALAPI: ['movie', 'series'],
|
||||
MALAPIManga: ['comicManga'],
|
||||
ComicVineAPI: ['comicManga'],
|
||||
SteamAPI: ['game'],
|
||||
MobyGamesAPI: ['game'],
|
||||
GiantBombAPI: ['game'],
|
||||
};
|
||||
|
||||
// Populate the map with APIs for each media type
|
||||
for (const [api, mediaTypes] of Object.entries(apiMediaTypes)) {
|
||||
for (const mediaType of mediaTypes) {
|
||||
if (!mediaTypeApiMap.has(mediaType)) {
|
||||
mediaTypeApiMap.set(mediaType, []);
|
||||
// Populate the map with APIs for each media type dynamically
|
||||
for (const api of this.plugin.apiManager.apis) {
|
||||
for (const MediaType of api.types) {
|
||||
if (!mediaTypeApiMap.has(MediaType)) {
|
||||
mediaTypeApiMap.set(MediaType, []);
|
||||
}
|
||||
mediaTypeApiMap.get(mediaType)!.push(api);
|
||||
mediaTypeApiMap.get(MediaType)!.push(api.apiName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -315,26 +315,29 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
const filteredMediaTypes = Array.from(mediaTypeApiMap.entries()).filter(([_, apis]) => apis.length > 1);
|
||||
|
||||
// Dynamically create settings based on the filtered media types and their APIs
|
||||
for (const [mediaType, apis] of filteredMediaTypes) {
|
||||
new Setting(containerEl).setName(`Select APIs for ${unCamelCase(mediaType)}`).setHeading();
|
||||
for (const [MediaType, apis] of filteredMediaTypes) {
|
||||
new Setting(containerEl).setName(`Select APIs for ${unCamelCase(MediaType)}`).setHeading();
|
||||
for (const apiName of apis) {
|
||||
const disabledMediaTypes = this.plugin.settings[`${apiName}_disabledMediaTypes` as keyof typeof this.plugin.settings] as string[];
|
||||
new Setting(containerEl)
|
||||
.setName(apiName)
|
||||
.setDesc(`Use ${apiName} API for ${unCamelCase(mediaType)}.`)
|
||||
.addToggle(cb => {
|
||||
cb.setValue(!disabledMediaTypes.includes(mediaType)).onChange(data => {
|
||||
if (data) {
|
||||
const index = disabledMediaTypes.indexOf(mediaType);
|
||||
if (index > -1) {
|
||||
disabledMediaTypes.splice(index, 1);
|
||||
const api = this.plugin.apiManager.apis.find(api => api.apiName === apiName);
|
||||
if (api) {
|
||||
const disabledMediaTypes = api.getDisabledMediaTypes();
|
||||
new Setting(containerEl)
|
||||
.setName(apiName)
|
||||
.setDesc(`Use ${apiName} API for ${unCamelCase(MediaType)}.`)
|
||||
.addToggle(cb => {
|
||||
cb.setValue(!disabledMediaTypes.includes(MediaType as MediaType)).onChange(data => {
|
||||
if (data) {
|
||||
const index = disabledMediaTypes.indexOf(MediaType as MediaType);
|
||||
if (index > -1) {
|
||||
disabledMediaTypes.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
disabledMediaTypes.push(MediaType as MediaType);
|
||||
}
|
||||
} else {
|
||||
disabledMediaTypes.push(mediaType);
|
||||
}
|
||||
void this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue