From 55f9ee605f78b788680e207ab8c02b3b035ce918 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 19 Feb 2022 17:39:16 +0100 Subject: [PATCH] More checks --- Models/ThemeConfig/Conversion/FixImages.ts | 16 ++++++++++++---- Models/ThemeConfig/Conversion/Validation.ts | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Models/ThemeConfig/Conversion/FixImages.ts b/Models/ThemeConfig/Conversion/FixImages.ts index 9558e2f6e..0b8bb1de0 100644 --- a/Models/ThemeConfig/Conversion/FixImages.ts +++ b/Models/ThemeConfig/Conversion/FixImages.ts @@ -19,7 +19,7 @@ export class ExtractImages extends Conversion { } convert(json: LayoutConfigJson, context: string): { result: string[], errors: string[], warnings: string[] } { - const allFoundImages = [] + const allFoundImages : string[] = [] const errors = [] const warnings = [] for (const metapath of ExtractImages.layoutMetaPaths) { @@ -33,7 +33,7 @@ export class ExtractImages extends Conversion { if (typeof foundImage === "string") { if(foundImage == ""){ - errors.push(context+"."+path.join(".")+" Found an empty image") + warnings.push(context+"."+path.join(".")+" Found an empty image") } if(this._sharedTagRenderings?.has(foundImage)){ @@ -54,7 +54,7 @@ export class ExtractImages extends Conversion { allFoundImages.push(...fromPath.map(i => i.leaf).filter(i => typeof i=== "string")) for (const pathAndImg of fromPath) { if(pathAndImg.leaf === "" || pathAndImg.leaf["path"] == ""){ - errors.push(context+[...path,...pathAndImg.path].join(".")+": Found an empty image at ") + warnings.push(context+[...path,...pathAndImg.path].join(".")+": Found an empty image at ") } } } @@ -62,7 +62,14 @@ export class ExtractImages extends Conversion { } } } else { - allFoundImages.push(...found.map(i => i.leaf)) + for (const foundElement of found) { + if(foundElement.leaf === ""){ + warnings.push(context+"."+foundElement.path.join(".")+" Found an empty image") + continue + } + allFoundImages.push(foundElement.leaf) + } + } } @@ -70,6 +77,7 @@ export class ExtractImages extends Conversion { .map(img => img["path"] ?? img) .map(img => img.split(";"))) .map(img => img.split(":")[0]) + .filter(img => img !== "") return {result: Utils.Dedup(splitParts), errors, warnings}; } diff --git a/Models/ThemeConfig/Conversion/Validation.ts b/Models/ThemeConfig/Conversion/Validation.ts index 571cc7d3a..bcdb3902d 100644 --- a/Models/ThemeConfig/Conversion/Validation.ts +++ b/Models/ThemeConfig/Conversion/Validation.ts @@ -208,11 +208,29 @@ class OverrideShadowingCheck extends DesugaringStep { } +class MiscThemeChecks extends DesugaringStep{ + constructor() { + super("Miscelleanous checks on the theme", [],"MiscThemesChecks"); + } + + convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } { + const warnings = [] + if(json.socialImage === ""){ + warnings.push("Social image for theme "+json.id+" is the emtpy string") + } + return { + result :json, + warnings + }; + } +} + export class PrevalidateTheme extends Fuse { constructor() { super("Various consistency checks on the raw JSON", - new OverrideShadowingCheck() + new OverrideShadowingCheck(), + new MiscThemeChecks() ); }