diff options
Diffstat (limited to 'src/internal-server/app/Controllers/Http/RecipeController.js')
-rw-r--r-- | src/internal-server/app/Controllers/Http/RecipeController.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/internal-server/app/Controllers/Http/RecipeController.js b/src/internal-server/app/Controllers/Http/RecipeController.js index e88a89a0b..eac34aa5c 100644 --- a/src/internal-server/app/Controllers/Http/RecipeController.js +++ b/src/internal-server/app/Controllers/Http/RecipeController.js | |||
@@ -6,6 +6,7 @@ const Env = use('Env'); | |||
6 | const fetch = require('node-fetch'); | 6 | const fetch = require('node-fetch'); |
7 | const debug = require('../../../../preload-safe-debug')('Ferdium:internalServer:RecipeController'); | 7 | const debug = require('../../../../preload-safe-debug')('Ferdium:internalServer:RecipeController'); |
8 | const { LIVE_FERDIUM_API } = require('../../../../config'); | 8 | const { LIVE_FERDIUM_API } = require('../../../../config'); |
9 | const { convertToJSON } = require('../../../../jsUtils'); | ||
9 | const { API_VERSION } = require('../../../../environment-remote'); | 10 | const { API_VERSION } = require('../../../../environment-remote'); |
10 | 11 | ||
11 | const RECIPES_URL = `${LIVE_FERDIUM_API}/${API_VERSION}/recipes`; | 12 | const RECIPES_URL = `${LIVE_FERDIUM_API}/${API_VERSION}/recipes`; |
@@ -14,13 +15,13 @@ class RecipeController { | |||
14 | // List official and custom recipes | 15 | // List official and custom recipes |
15 | async list({ response }) { | 16 | async list({ response }) { |
16 | const recipesUrlFetch = await fetch(RECIPES_URL); | 17 | const recipesUrlFetch = await fetch(RECIPES_URL); |
17 | const officialRecipes = JSON.parse(await recipesUrlFetch.text()); | 18 | const officialRecipes = convertToJSON(await recipesUrlFetch.text()); |
18 | const allRecipes = await Recipe.all(); | 19 | const allRecipes = await Recipe.all(); |
19 | const customRecipesArray = allRecipes.rows; | 20 | const customRecipesArray = allRecipes.rows; |
20 | const customRecipes = customRecipesArray.map(recipe => ({ | 21 | const customRecipes = customRecipesArray.map(recipe => ({ |
21 | id: recipe.recipeId, | 22 | id: recipe.recipeId, |
22 | name: recipe.name, | 23 | name: recipe.name, |
23 | ...JSON.parse(recipe.data), | 24 | ...convertToJSON(recipe.data), |
24 | })); | 25 | })); |
25 | 26 | ||
26 | const recipes = [...officialRecipes, ...customRecipes]; | 27 | const recipes = [...officialRecipes, ...customRecipes]; |
@@ -53,7 +54,7 @@ class RecipeController { | |||
53 | results = dbResults.map(recipe => ({ | 54 | results = dbResults.map(recipe => ({ |
54 | id: recipe.recipeId, | 55 | id: recipe.recipeId, |
55 | name: recipe.name, | 56 | name: recipe.name, |
56 | ...JSON.parse(recipe.data), | 57 | ...convertToJSON(recipe.data), |
57 | })); | 58 | })); |
58 | } else { | 59 | } else { |
59 | let remoteResults = []; | 60 | let remoteResults = []; |
@@ -62,7 +63,7 @@ class RecipeController { | |||
62 | const recipesUrlFetch = await fetch( | 63 | const recipesUrlFetch = await fetch( |
63 | `${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`, | 64 | `${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`, |
64 | ); | 65 | ); |
65 | remoteResults = JSON.parse(await recipesUrlFetch.text()); | 66 | remoteResults = convertToJSON(await recipesUrlFetch.text()); |
66 | } | 67 | } |
67 | 68 | ||
68 | debug('remoteResults:', remoteResults); | 69 | debug('remoteResults:', remoteResults); |
@@ -74,7 +75,7 @@ class RecipeController { | |||
74 | const localResults = localResultsArray.map(recipe => ({ | 75 | const localResults = localResultsArray.map(recipe => ({ |
75 | id: recipe.recipeId, | 76 | id: recipe.recipeId, |
76 | name: recipe.name, | 77 | name: recipe.name, |
77 | ...JSON.parse(recipe.data), | 78 | ...convertToJSON(recipe.data), |
78 | })); | 79 | })); |
79 | 80 | ||
80 | debug('localResults:', localResults); | 81 | debug('localResults:', localResults); |
@@ -96,7 +97,7 @@ class RecipeController { | |||
96 | response, | 97 | response, |
97 | }) { | 98 | }) { |
98 | const recipesUrlFetch = await fetch(`${RECIPES_URL}/popular`); | 99 | const recipesUrlFetch = await fetch(`${RECIPES_URL}/popular`); |
99 | const featuredRecipes = JSON.parse(await recipesUrlFetch.text()); | 100 | const featuredRecipes = convertToJSON(await recipesUrlFetch.text()); |
100 | return response.send(featuredRecipes); | 101 | return response.send(featuredRecipes); |
101 | } | 102 | } |
102 | 103 | ||