diff options
author | 2022-01-07 02:07:56 +0100 | |
---|---|---|
committer | 2022-01-07 02:07:56 +0100 | |
commit | a02a2027760cd79ff5f5c2777244b2c5b4f66b6f (patch) | |
tree | 2777a90fe12e52403d2e4411ac572ba23a86d7f2 | |
parent | Use window.fetch in getRecipePackage, removes electron-fetch (diff) | |
download | ferdium-app-a02a2027760cd79ff5f5c2777244b2c5b4f66b6f.tar.gz ferdium-app-a02a2027760cd79ff5f5c2777244b2c5b4f66b6f.tar.zst ferdium-app-a02a2027760cd79ff5f5c2777244b2c5b4f66b6f.zip |
Eventually get remote recipes updates in internal server
-rw-r--r-- | src/internal-server/app/Controllers/Http/RecipeController.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/internal-server/app/Controllers/Http/RecipeController.js b/src/internal-server/app/Controllers/Http/RecipeController.js index daa9356f6..64838b338 100644 --- a/src/internal-server/app/Controllers/Http/RecipeController.js +++ b/src/internal-server/app/Controllers/Http/RecipeController.js | |||
@@ -85,10 +85,23 @@ class RecipeController { | |||
85 | return response.send(results); | 85 | return response.send(results); |
86 | } | 86 | } |
87 | 87 | ||
88 | // Return an empty array | 88 | async update({ request, response }) { |
89 | update({ | 89 | // eslint-disable-next-line eqeqeq |
90 | response, | 90 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { |
91 | }) { | 91 | const body = request.all(); |
92 | try { | ||
93 | const remoteUpdates = await fetch(`${RECIPES_URL}/update`, { | ||
94 | method: 'POST', | ||
95 | body: JSON.stringify(body), | ||
96 | headers: {'Content-Type': 'application/json'} | ||
97 | }); | ||
98 | return response.send( | ||
99 | remoteUpdates.ok ? await remoteUpdates.json() : remoteUpdates, | ||
100 | ); | ||
101 | } catch (error) { | ||
102 | return response.send({ error }); | ||
103 | } | ||
104 | } | ||
92 | return response.send([]); | 105 | return response.send([]); |
93 | } | 106 | } |
94 | 107 | ||
@@ -120,15 +133,14 @@ class RecipeController { | |||
120 | if (/\.+/.test(service) || /\/+/.test(service)) { | 133 | if (/\.+/.test(service) || /\/+/.test(service)) { |
121 | return response.send('Invalid recipe name'); | 134 | return response.send('Invalid recipe name'); |
122 | } | 135 | } |
123 | |||
124 | // Check if recipe exists in recipes folder | ||
125 | if (await Drive.exists(`${service}.tar.gz`)) { | ||
126 | return response.send(await Drive.get(`${service}.tar.gz`)); | ||
127 | } | ||
128 | // eslint-disable-next-line eqeqeq | 136 | // eslint-disable-next-line eqeqeq |
129 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { | 137 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { |
130 | return response.redirect(`${RECIPES_URL}/download/${service}`); | 138 | return response.redirect(`${RECIPES_URL}/download/${service}`); |
131 | } | 139 | } |
140 | // Check if recipe exists in recipes folder | ||
141 | if (await Drive.exists(`${service}.tar.gz`)) { | ||
142 | return response.send(await Drive.get(`${service}.tar.gz`)); | ||
143 | } | ||
132 | return response.status(400).send({ | 144 | return response.status(400).send({ |
133 | message: 'Recipe not found', | 145 | message: 'Recipe not found', |
134 | code: 'recipe-not-found', | 146 | code: 'recipe-not-found', |