Possible fix for the flat structured arrays
This commit is contained in:
parent
7a0f8e03bb
commit
daeefb9688
2 changed files with 45 additions and 66 deletions
|
|
@ -10,7 +10,7 @@ export abstract class APIModel {
|
||||||
plugin!: MediaDbPlugin;
|
plugin!: MediaDbPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
* This function should query the api and return a list of matches. The matches should be capped at 20.
|
||||||
*
|
*
|
||||||
* @param title the title to query for
|
* @param title the title to query for
|
||||||
*/
|
*/
|
||||||
|
|
@ -19,13 +19,8 @@ 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 (
|
const disabledMediaTypes = this.plugin.settings[`${this.apiName}_disabledMediaTypes` as keyof typeof this.plugin.settings] as MediaType[];
|
||||||
this.types.contains(type) &&
|
return this.types.includes(type) && !disabledMediaTypes.includes(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 false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasTypeOverlap(types: MediaType[]): boolean {
|
hasTypeOverlap(types: MediaType[]): boolean {
|
||||||
|
|
|
||||||
|
|
@ -21,32 +21,13 @@ export interface MediaDbPluginSettings {
|
||||||
openNoteInNewTab: boolean;
|
openNoteInNewTab: boolean;
|
||||||
useDefaultFrontMatter: boolean;
|
useDefaultFrontMatter: boolean;
|
||||||
enableTemplaterIntegration: boolean;
|
enableTemplaterIntegration: boolean;
|
||||||
apiToggle: {
|
OMDbAPI_disabledMediaTypes: string[];
|
||||||
OMDbAPI: {
|
MALAPI_disabledMediaTypes: string[];
|
||||||
movie: boolean;
|
MALAPIManga_disabledMediaTypes: string[];
|
||||||
series: boolean;
|
ComicVineAPI_disabledMediaTypes: string[];
|
||||||
game: boolean;
|
SteamAPI_disabledMediaTypes: string[];
|
||||||
};
|
MobyGamesAPI_disabledMediaTypes: string[];
|
||||||
MALAPI: {
|
GiantBombAPI_disabledMediaTypes: string[];
|
||||||
movie: boolean;
|
|
||||||
series: boolean;
|
|
||||||
};
|
|
||||||
MALAPIManga: {
|
|
||||||
comicManga: boolean;
|
|
||||||
};
|
|
||||||
ComicVineAPI: {
|
|
||||||
comicManga: boolean;
|
|
||||||
};
|
|
||||||
SteamAPI: {
|
|
||||||
game: boolean;
|
|
||||||
};
|
|
||||||
MobyGamesAPI: {
|
|
||||||
game: boolean;
|
|
||||||
};
|
|
||||||
GiantBombAPI: {
|
|
||||||
game: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
movieTemplate: string;
|
movieTemplate: string;
|
||||||
seriesTemplate: string;
|
seriesTemplate: string;
|
||||||
mangaTemplate: string;
|
mangaTemplate: string;
|
||||||
|
|
@ -97,32 +78,13 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
openNoteInNewTab: true,
|
openNoteInNewTab: true,
|
||||||
useDefaultFrontMatter: true,
|
useDefaultFrontMatter: true,
|
||||||
enableTemplaterIntegration: false,
|
enableTemplaterIntegration: false,
|
||||||
apiToggle: {
|
OMDbAPI_disabledMediaTypes: [],
|
||||||
OMDbAPI: {
|
MALAPI_disabledMediaTypes: [],
|
||||||
movie: true,
|
MALAPIManga_disabledMediaTypes: [],
|
||||||
series: true,
|
ComicVineAPI_disabledMediaTypes: [],
|
||||||
game: true,
|
SteamAPI_disabledMediaTypes: [],
|
||||||
},
|
MobyGamesAPI_disabledMediaTypes: [],
|
||||||
MALAPI: {
|
GiantBombAPI_disabledMediaTypes: [],
|
||||||
movie: true,
|
|
||||||
series: true,
|
|
||||||
},
|
|
||||||
MALAPIManga: {
|
|
||||||
comicManga: true,
|
|
||||||
},
|
|
||||||
ComicVineAPI: {
|
|
||||||
comicManga: true,
|
|
||||||
},
|
|
||||||
SteamAPI: {
|
|
||||||
game: true,
|
|
||||||
},
|
|
||||||
MobyGamesAPI: {
|
|
||||||
game: true,
|
|
||||||
},
|
|
||||||
GiantBombAPI: {
|
|
||||||
game: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
movieTemplate: '',
|
movieTemplate: '',
|
||||||
seriesTemplate: '',
|
seriesTemplate: '',
|
||||||
mangaTemplate: '',
|
mangaTemplate: '',
|
||||||
|
|
@ -329,31 +291,53 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
|
|
||||||
// Create a map to store APIs for each media type
|
// Create a map to store APIs for each media type
|
||||||
const mediaTypeApiMap = new Map<string, string[]>();
|
const mediaTypeApiMap = new Map<string, string[]>();
|
||||||
|
const apiMediaTypes = {
|
||||||
|
OMDbAPI: ['movie', 'series', 'game'],
|
||||||
|
MALAPI: ['movie', 'series'],
|
||||||
|
MALAPIManga: ['manga'],
|
||||||
|
ComicVineAPI: ['comic', 'manga'],
|
||||||
|
SteamAPI: ['game'],
|
||||||
|
MobyGamesAPI: ['game'],
|
||||||
|
GiantBombAPI: ['game'],
|
||||||
|
};
|
||||||
|
|
||||||
// Populate the map with APIs for each media type
|
// Populate the map with APIs for each media type
|
||||||
for (const [apiName, api] of Object.entries(this.plugin.settings.apiToggle)) {
|
for (const [api, mediaTypes] of Object.entries(apiMediaTypes)) {
|
||||||
for (const mediaType of Object.keys(api)) {
|
for (const mediaType of mediaTypes) {
|
||||||
if (!mediaTypeApiMap.has(mediaType)) {
|
if (!mediaTypeApiMap.has(mediaType)) {
|
||||||
mediaTypeApiMap.set(mediaType, []);
|
mediaTypeApiMap.set(mediaType, []);
|
||||||
}
|
}
|
||||||
mediaTypeApiMap.get(mediaType)!.push(apiName);
|
mediaTypeApiMap.get(mediaType)!.push(api);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the populated map to verify its contents
|
||||||
|
console.log('mediaTypeApiMap:', mediaTypeApiMap);
|
||||||
|
|
||||||
// Filter out media types with only one API
|
// Filter out media types with only one API
|
||||||
const filteredMediaTypes = Array.from(mediaTypeApiMap.entries()).filter(([_, apis]) => apis.length > 1);
|
const filteredMediaTypes = Array.from(mediaTypeApiMap.entries()).filter(([_, apis]) => apis.length > 1);
|
||||||
|
|
||||||
|
// Log the filtered media types to verify the filtering
|
||||||
|
console.log('filteredMediaTypes:', filteredMediaTypes);
|
||||||
|
|
||||||
// Dynamically create settings based on the filtered media types and their APIs
|
// Dynamically create settings based on the filtered media types and their APIs
|
||||||
for (const [mediaType, apis] of filteredMediaTypes) {
|
for (const [mediaType, apis] of filteredMediaTypes) {
|
||||||
new Setting(containerEl).setName(`Select APIs for ${unCamelCase(mediaType)}`).setHeading();
|
new Setting(containerEl).setName(`Select APIs for ${unCamelCase(mediaType)}`).setHeading();
|
||||||
for (const apiName of apis) {
|
for (const apiName of apis) {
|
||||||
const apiToggle = this.plugin.settings.apiToggle[apiName as keyof typeof this.plugin.settings.apiToggle];
|
const disabledMediaTypes = this.plugin.settings[`${apiName}_disabledMediaTypes` as keyof typeof this.plugin.settings] as string[];
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName(apiName)
|
.setName(apiName)
|
||||||
.setDesc(`Use ${apiName} API for ${unCamelCase(mediaType)}.`)
|
.setDesc(`Use ${apiName} API for ${unCamelCase(mediaType)}.`)
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
cb.setValue((apiToggle as Record<string, boolean>)[mediaType]).onChange(data => {
|
cb.setValue(!disabledMediaTypes.includes(mediaType)).onChange(data => {
|
||||||
(apiToggle as Record<string, boolean>)[mediaType] = data;
|
if (data) {
|
||||||
|
const index = disabledMediaTypes.indexOf(mediaType);
|
||||||
|
if (index > -1) {
|
||||||
|
disabledMediaTypes.splice(index, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
disabledMediaTypes.push(mediaType);
|
||||||
|
}
|
||||||
void this.plugin.saveSettings();
|
void this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue