diff options
author | kytwb <kytwb@pm.me> | 2022-01-07 12:29:51 +0100 |
---|---|---|
committer | kytwb <kytwb@pm.me> | 2022-01-07 12:29:51 +0100 |
commit | a53d5f8ab5c089f0f8ab19125db4c6f7b4058373 (patch) | |
tree | 565bf9b8f62f05dcfd9b1b2be50223a52c2b5cb0 /app | |
parent | Review recipes routes, fix download recipe response type (diff) | |
download | ferdium-server-a53d5f8ab5c089f0f8ab19125db4c6f7b4058373.tar.gz ferdium-server-a53d5f8ab5c089f0f8ab19125db4c6f7b4058373.tar.zst ferdium-server-a53d5f8ab5c089f0f8ab19125db4c6f7b4058373.zip |
Add recipes update
Diffstat (limited to 'app')
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index a2b129d..07cd430 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js | |||
@@ -9,6 +9,7 @@ const Env = use('Env'); | |||
9 | const targz = require('targz'); | 9 | const targz = require('targz'); |
10 | const path = require('path'); | 10 | const path = require('path'); |
11 | const fs = require('fs-extra'); | 11 | const fs = require('fs-extra'); |
12 | const semver = require('semver'); | ||
12 | 13 | ||
13 | const compress = (src, dest) => new Promise((resolve, reject) => { | 14 | const compress = (src, dest) => new Promise((resolve, reject) => { |
14 | targz.compress({ | 15 | targz.compress({ |
@@ -166,8 +167,24 @@ class RecipeController { | |||
166 | ); | 167 | ); |
167 | } | 168 | } |
168 | 169 | ||
169 | update({ response }) { | 170 | update({ request, response }) { |
170 | return response.send([]); | 171 | const updates = []; |
172 | const recipes = request.all(); | ||
173 | const allJson = fs.readJsonSync(path.join( | ||
174 | Helpers.appRoot(), 'recipes', 'all.json', | ||
175 | )); | ||
176 | |||
177 | for (const recipe of Object.keys(recipes)) { | ||
178 | const version = recipes[recipe]; | ||
179 | |||
180 | // Find recipe in local recipe repository | ||
181 | const localRecipe = allJson.find(r => r.id === recipe); | ||
182 | if (localRecipe && semver.lt(version, localRecipe.version)) { | ||
183 | updates.push(recipe); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | return response.send(updates); | ||
171 | } | 188 | } |
172 | 189 | ||
173 | // Download a recipe | 190 | // Download a recipe |