From a54c87be1ce629cf13a5bfb9c2ba26958e0e4e74 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:22:38 +0100 Subject: Parse recipe author string --- src/models/Recipe.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/models') diff --git a/src/models/Recipe.js b/src/models/Recipe.js index 43a3450b1..4b613a40c 100644 --- a/src/models/Recipe.js +++ b/src/models/Recipe.js @@ -1,7 +1,8 @@ +import emailParser from 'address-rfc2822'; + export default class Recipe { id = ''; name = ''; - author = ''; description = ''; version = '1.0'; path = ''; @@ -30,7 +31,7 @@ export default class Recipe { this.id = data.id || this.id; this.name = data.name || this.name; - this.author = data.author || this.author; + this.rawAuthor = data.author || this.author; this.description = data.description || this.description; this.version = data.version || this.version; this.path = data.path; @@ -49,4 +50,15 @@ export default class Recipe { this.message = data.config.message || this.message; } + + get author() { + try { + const addresses = emailParser.parse(this.rawAuthor); + return addresses.map(a => ({ email: a.address, name: a.phrase })); + } catch (err) { + console.warn(`Not a valid author for ${this.name}`); + } + + return []; + } } -- cgit v1.2.3-70-g09d2 From 2e894d6d53a952bfae74f5b6b19040e505765416 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:59:23 +0100 Subject: fix(App): Add checks to service url validation to prevent app freeze --- src/models/Service.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/models') diff --git a/src/models/Service.js b/src/models/Service.js index 7a0310ebc..484252e7c 100644 --- a/src/models/Service.js +++ b/src/models/Service.js @@ -58,7 +58,12 @@ export default class Service { @computed get url() { if (this.recipe.hasCustomUrl && this.customUrl) { - let url = normalizeUrl(this.customUrl); + let url; + try { + url = normalizeUrl(this.customUrl); + } catch (err) { + console.error(`Service (${this.recipe.name}): '${this.customUrl}' is not a valid Url.`); + } if (typeof this.recipe.buildUrl === 'function') { url = this.recipe.buildUrl(url); -- cgit v1.2.3-70-g09d2 From def4b27e980da4e32f494c6832c1851e3364a252 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Sat, 4 Nov 2017 00:11:41 +0100 Subject: Improve (dev) recipe loading --- src/api/server/ServerApi.js | 17 ++++++++++++----- src/models/Recipe.js | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/models') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 8b0b7563c..932b70cdc 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -499,7 +499,7 @@ export default class ServerApi { return recipe; }), - ).catch(err => console.error(err)); + ).catch(err => console.error('Can\'t load recipe', err)); } _mapRecipePreviewModel(recipes) { @@ -562,9 +562,16 @@ export default class ServerApi { .filter(file => fs.statSync(path.join(recipesDirectory, file)).isDirectory() && file !== 'temp'); const recipes = paths.map((id) => { - // eslint-disable-next-line - const Recipe = require(id)(RecipeModel); - return new Recipe(loadRecipeConfig(id)); + let Recipe; + try { + // eslint-disable-next-line + Recipe = require(id)(RecipeModel); + return new Recipe(loadRecipeConfig(id)); + } catch (err) { + console.error(err); + } + + return false; }).filter(recipe => recipe.id).map((data) => { const recipe = data; @@ -579,7 +586,7 @@ export default class ServerApi { return recipes; } catch (err) { - console.debug('Folder `recipe/dev` does not exist'); + console.debug('Could not load dev recipes'); return false; } } diff --git a/src/models/Recipe.js b/src/models/Recipe.js index 4b613a40c..9971df77c 100644 --- a/src/models/Recipe.js +++ b/src/models/Recipe.js @@ -26,7 +26,8 @@ export default class Recipe { } if (!data.id) { - throw Error('Recipe requires Id'); + // Franz 4 recipes do not have an Id + throw Error(`Recipe '${data.name}' requires Id`); } this.id = data.id || this.id; -- cgit v1.2.3-70-g09d2