Skip to content

Commit

Permalink
fixed incredibly painful validate files bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed May 11, 2022
1 parent 6b38411 commit c69635b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .validate-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as glob from "glob";
let isValid = true;
const validator = new json.Validator(undefined, undefined, { useDefaults: false });
let presetFiles: string[] = glob.sync("./files/presets/*.json")
console.log(presetFiles)
let presetPromises: Promise<object|void>[] = []
for(let i=0; i <presetFiles.length; i++) {
presetPromises.push(json.read(presetFiles[i])
Expand All @@ -32,4 +31,3 @@ Promise.all(presetPromises).catch((error: Error) => {
console.log(isValid ? 'Valid' : 'Invalid');
process.exit(isValid ? 0 : 1);
});

4 changes: 4 additions & 0 deletions src/lib/image-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ProviderPostEventMap, ProviderCallback, ProviderReceiveEventMap, Provid
import { FuzzyService, LoggerService, SettingsService } from "../renderer/services";
import { imageProviders } from './image-providers';
import { availableProviders, providerInfo } from './image-providers/available-providers';
import { providerInfoLang } from './image-providers/available-providers-lang';
import { APP } from '../variables';
import { queue } from "async";
import { Subject } from "rxjs";
Expand Down Expand Up @@ -64,6 +65,9 @@ export class ImageProvider {
getProviderInfo(provider: string) {
return providerInfo[provider];
}
getProviderInfoLang(provider: string) {
return providerInfoLang[provider];
}

retrieveUrls(title: string, imageType: string, imageProviderAPIs: ImageProviderAPI, providers: string[], eventCallback: ProviderCallback) {
for (let i = 0; i < providers.length; i++) {
Expand Down
39 changes: 39 additions & 0 deletions src/lib/image-providers/available-providers-lang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ProviderInfo } from '../../models';
import { APP } from '../../variables';
// necessary to split this out because of ts-node .validate-files
export const providerInfoLang: ProviderInfo = {
SteamGridDB: {
info: APP.lang.sgdbProvider.docs__md.self.join(''),
inputs: {
nsfw: {
label: APP.lang.sgdbProvider.nsfwInputTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
humor: {
label: APP.lang.sgdbProvider.humorInputTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
styles: {
label: APP.lang.sgdbProvider.stylesTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesHero: {
label: APP.lang.sgdbProvider.stylesHeroTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesLogo: {
label: APP.lang.sgdbProvider.stylesLogoTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesIcon: {
label: APP.lang.sgdbProvider.stylesIconTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
imageMotionTypes: {
label: APP.lang.sgdbProvider.imageMotionTypesTitle,
info: APP.lang.sgdbProvider.docs__md.input.join('')
}
}
}
};

17 changes: 0 additions & 17 deletions src/lib/image-providers/available-providers.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,42 @@
import { ProviderInfo } from '../../models';
import { APP } from '../../variables';

export const providerInfo: ProviderInfo = {
SteamGridDB: {
info: APP.lang.sgdbProvider.docs__md.self.join(''),
inputs: {
nsfw: {
label: APP.lang.sgdbProvider.nsfwInputTitle,
inputType: 'toggle',
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
humor: {
label: APP.lang.sgdbProvider.humorInputTitle,
inputType: 'toggle',
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
styles: {
label: APP.lang.sgdbProvider.stylesTitle,
inputType: 'multiselect',
allowedValues: ['alternate', 'blurred', 'white_logo', 'material', 'no_logo'],
multiple: true,
allowEmpty: true,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesHero: {
label: APP.lang.sgdbProvider.stylesHeroTitle,
inputType: 'multiselect',
allowedValues: ['alternate', 'blurred', 'material'],
multiple: true,
allowEmpty: true,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesLogo: {
label: APP.lang.sgdbProvider.stylesLogoTitle,
inputType: 'multiselect',
allowedValues: ['official', 'white', 'black', 'custom'],
multiple: true,
allowEmpty: true,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
stylesIcon: {
label: APP.lang.sgdbProvider.stylesIconTitle,
inputType: 'multiselect',
allowedValues: ['official','custom'],
multiple: true,
allowEmpty: true,
info: APP.lang.sgdbProvider.docs__md.input.join('')
},
imageMotionTypes: {
label: APP.lang.sgdbProvider.imageMotionTypesTitle,
inputType: 'multiselect',
allowedValues: ['static', 'animated'],
multiple: true,
allowEmpty: false,
info: APP.lang.sgdbProvider.docs__md.input.join('')
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/image-providers.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ImageProviderAPI } from "./user-configuration.model";

export interface ProviderInputField {
[inputKey: string]: {
label: string,
inputType: 'multiselect' | 'toggle',
label?: string,
inputType?: 'multiselect' | 'toggle',
info?: string,
multiple?: boolean,
allowEmpty?: boolean,
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/components/parsers.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,20 @@ export class ParsersComponent implements AfterViewInit, OnDestroy {
let providerNames = this.imageProviderService.instance.getAvailableProviders();
for (let i=0;i < providerNames.length; i++) {
let provider = this.imageProviderService.instance.getProviderInfo(providerNames[i]);
let providerL = this.imageProviderService.instance.getProviderInfoLang(providerNames[i]);
if (provider && provider.inputs !== undefined) {
imageProviderAPIs[providerNames[i]] = (()=>{
let apiInputs = {}
for (let inputFieldName in provider.inputs) {
let input = provider.inputs[inputFieldName];
if(input.inputType == 'toggle') {
apiInputs[inputFieldName] = new NestedFormElement.Toggle({
text: input.label
text: providerL.inputs[inputFieldName].label
});
}
else if (input.inputType == 'multiselect') {
apiInputs[inputFieldName] = new NestedFormElement.Select({
label: input.label,
label: providerL.inputs[inputFieldName].label,
multiple: input.multiple,
allowEmpty: input.allowEmpty,
placeholder: this.lang.placeholder.multiAPIPlaceholder,
Expand All @@ -367,7 +368,7 @@ export class ParsersComponent implements AfterViewInit, OnDestroy {
},
onInfoClick: (self, path) => {
this.currentDoc.activePath = path.join();
this.currentDoc.content = input.info;
this.currentDoc.content = providerL.inputs[inputFieldName].info;
}
})
}
Expand Down

0 comments on commit c69635b

Please sign in to comment.