diff options
author | kytwb <kytwb@pm.me> | 2021-12-31 13:00:14 +0100 |
---|---|---|
committer | kytwb <kytwb@pm.me> | 2021-12-31 13:00:14 +0100 |
commit | e4a7fcbde65f399bc09065890cad750e40d1568e (patch) | |
tree | b8886c7a47df34a6df09a86aba0f7babe82e6cb3 /app | |
parent | Add DigitalOcean refcode (diff) | |
download | ferdium-server-e4a7fcbde65f399bc09065890cad750e40d1568e.tar.gz ferdium-server-e4a7fcbde65f399bc09065890cad750e40d1568e.tar.zst ferdium-server-e4a7fcbde65f399bc09065890cad750e40d1568e.zip |
Remove calls to Franz infra for recipes
Diffstat (limited to 'app')
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 16 | ||||
-rw-r--r-- | app/Controllers/Http/StaticController.js | 3 |
2 files changed, 3 insertions, 16 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index 344548c..066728f 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js | |||
@@ -29,7 +29,7 @@ class RecipeController { | |||
29 | async list({ | 29 | async list({ |
30 | response, | 30 | response, |
31 | }) { | 31 | }) { |
32 | const officialRecipes = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes')).text()); | 32 | const officialRecipes = fs.readJsonSync(path.join(Helpers.appRoot(), 'recipes', 'all.json')); |
33 | const customRecipesArray = (await Recipe.all()).rows; | 33 | const customRecipesArray = (await Recipe.all()).rows; |
34 | const customRecipes = customRecipesArray.map((recipe) => ({ | 34 | const customRecipes = customRecipesArray.map((recipe) => ({ |
35 | id: recipe.recipeId, | 35 | id: recipe.recipeId, |
@@ -144,21 +144,12 @@ class RecipeController { | |||
144 | ...typeof recipe.data === 'string' ? JSON.parse(recipe.data) : recipe.data, | 144 | ...typeof recipe.data === 'string' ? JSON.parse(recipe.data) : recipe.data, |
145 | })); | 145 | })); |
146 | } else { | 146 | } else { |
147 | let remoteResults = []; | ||
148 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq | ||
149 | remoteResults = JSON.parse(await (await fetch(`https://api.franzinfra.com/v1/recipes/search?needle=${encodeURIComponent(needle)}`)).text()); | ||
150 | } | ||
151 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); | 147 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); |
152 | const localResults = localResultsArray.map((recipe) => ({ | 148 | results = localResultsArray.map((recipe) => ({ |
153 | id: recipe.recipeId, | 149 | id: recipe.recipeId, |
154 | name: recipe.name, | 150 | name: recipe.name, |
155 | ...typeof recipe.data === 'string' ? JSON.parse(recipe.data) : recipe.data, | 151 | ...typeof recipe.data === 'string' ? JSON.parse(recipe.data) : recipe.data, |
156 | })); | 152 | })); |
157 | |||
158 | results = [ | ||
159 | ...localResults, | ||
160 | ...remoteResults || [], | ||
161 | ]; | ||
162 | } | 153 | } |
163 | 154 | ||
164 | return response.send(results); | 155 | return response.send(results); |
@@ -192,9 +183,6 @@ class RecipeController { | |||
192 | if (await Drive.exists(`${service}.tar.gz`)) { | 183 | if (await Drive.exists(`${service}.tar.gz`)) { |
193 | return response.send(await Drive.get(`${service}.tar.gz`)); | 184 | return response.send(await Drive.get(`${service}.tar.gz`)); |
194 | } | 185 | } |
195 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq | ||
196 | return response.redirect(`https://api.franzinfra.com/v1/recipes/download/${service}`); | ||
197 | } | ||
198 | return response.status(400).send({ | 186 | return response.status(400).send({ |
199 | message: 'Recipe not found', | 187 | message: 'Recipe not found', |
200 | code: 'recipe-not-found', | 188 | code: 'recipe-not-found', |
diff --git a/app/Controllers/Http/StaticController.js b/app/Controllers/Http/StaticController.js index 4e604df..7854fd6 100644 --- a/app/Controllers/Http/StaticController.js +++ b/app/Controllers/Http/StaticController.js | |||
@@ -93,14 +93,13 @@ class StaticController { | |||
93 | }); | 93 | }); |
94 | } | 94 | } |
95 | 95 | ||
96 | // Return list of popular recipes (copy of the response Franz's API is returning) | ||
97 | popularRecipes({ | 96 | popularRecipes({ |
98 | response, | 97 | response, |
99 | }) { | 98 | }) { |
100 | return response.send( | 99 | return response.send( |
101 | fs | 100 | fs |
102 | .readJsonSync(path.join( | 101 | .readJsonSync(path.join( |
103 | Helpers.appRoot(), 'officialrecipes', 'recipes', 'all.json', | 102 | Helpers.appRoot(), 'recipes', 'all.json', |
104 | )) | 103 | )) |
105 | .filter((recipe) => recipe.featured), | 104 | .filter((recipe) => recipe.featured), |
106 | ); | 105 | ); |