aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar kytwb <kytwb@pm.me>2022-01-06 23:10:16 +0100
committerLibravatar kytwb <kytwb@pm.me>2022-01-06 23:10:16 +0100
commite1cc68d8bf4d473307638607dfee98a90bc7a6be (patch)
tree0662959ae6b49f54831221c3f0d9cebd71d95a8e
parent1.3.1 (diff)
downloadferdium-server-e1cc68d8bf4d473307638607dfee98a90bc7a6be.tar.gz
ferdium-server-e1cc68d8bf4d473307638607dfee98a90bc7a6be.tar.zst
ferdium-server-e1cc68d8bf4d473307638607dfee98a90bc7a6be.zip
Review recipes routes, fix download recipe response type
-rw-r--r--app/Controllers/Http/RecipeController.js22
-rw-r--r--app/Controllers/Http/ServiceController.js4
-rw-r--r--app/Controllers/Http/StaticController.js12
-rw-r--r--start/routes.js7
4 files changed, 22 insertions, 23 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js
index 066728f..a2b129d 100644
--- a/app/Controllers/Http/RecipeController.js
+++ b/app/Controllers/Http/RecipeController.js
@@ -6,7 +6,6 @@ const {
6} = use('Validator'); 6} = use('Validator');
7const Env = use('Env'); 7const Env = use('Env');
8 8
9const fetch = require('node-fetch');
10const targz = require('targz'); 9const targz = require('targz');
11const path = require('path'); 10const path = require('path');
12const fs = require('fs-extra'); 11const fs = require('fs-extra');
@@ -90,7 +89,7 @@ class RecipeController {
90 89
91 // Compress files to .tar.gz file 90 // Compress files to .tar.gz file
92 const source = Helpers.tmpPath('recipe'); 91 const source = Helpers.tmpPath('recipe');
93 const destination = path.join(Helpers.appRoot(), `/recipes/${data.id}.tar.gz`); 92 const destination = path.join(Helpers.appRoot(), `/recipes/recipes/${data.id}.tar.gz`);
94 93
95 compress( 94 compress(
96 source, 95 source,
@@ -155,6 +154,22 @@ class RecipeController {
155 return response.send(results); 154 return response.send(results);
156 } 155 }
157 156
157 popularRecipes({
158 response,
159 }) {
160 return response.send(
161 fs
162 .readJsonSync(path.join(
163 Helpers.appRoot(), 'recipes', 'all.json',
164 ))
165 .filter((recipe) => recipe.featured),
166 );
167 }
168
169 update({ response }) {
170 return response.send([]);
171 }
172
158 // Download a recipe 173 // Download a recipe
159 async download({ 174 async download({
160 response, 175 response,
@@ -181,8 +196,9 @@ class RecipeController {
181 196
182 // Check if recipe exists in recipes folder 197 // Check if recipe exists in recipes folder
183 if (await Drive.exists(`${service}.tar.gz`)) { 198 if (await Drive.exists(`${service}.tar.gz`)) {
184 return response.send(await Drive.get(`${service}.tar.gz`)); 199 return response.type('.tar.gz').send(await Drive.get(`${service}.tar.gz`));
185 } 200 }
201
186 return response.status(400).send({ 202 return response.status(400).send({
187 message: 'Recipe not found', 203 message: 'Recipe not found',
188 code: 'recipe-not-found', 204 code: 'recipe-not-found',
diff --git a/app/Controllers/Http/ServiceController.js b/app/Controllers/Http/ServiceController.js
index ef8b168..3d10cb4 100644
--- a/app/Controllers/Http/ServiceController.js
+++ b/app/Controllers/Http/ServiceController.js
@@ -305,10 +305,6 @@ class ServiceController {
305 return response.send(servicesArray); 305 return response.send(servicesArray);
306 } 306 }
307 307
308 update({ response }) {
309 return response.send([]);
310 }
311
312 async delete({ params, auth, response }) { 308 async delete({ params, auth, response }) {
313 // Update data in database 309 // Update data in database
314 await Service.query() 310 await Service.query()
diff --git a/app/Controllers/Http/StaticController.js b/app/Controllers/Http/StaticController.js
index 7854fd6..aad1059 100644
--- a/app/Controllers/Http/StaticController.js
+++ b/app/Controllers/Http/StaticController.js
@@ -93,18 +93,6 @@ class StaticController {
93 }); 93 });
94 } 94 }
95 95
96 popularRecipes({
97 response,
98 }) {
99 return response.send(
100 fs
101 .readJsonSync(path.join(
102 Helpers.appRoot(), 'recipes', 'all.json',
103 ))
104 .filter((recipe) => recipe.featured),
105 );
106 }
107
108 // Show announcements 96 // Show announcements
109 async announcement({ 97 async announcement({
110 response, 98 response,
diff --git a/start/routes.js b/start/routes.js
index 4c5ce5b..f269dc8 100644
--- a/start/routes.js
+++ b/start/routes.js
@@ -34,15 +34,14 @@ Route.group(() => {
34 Route.delete('service/:id', 'ServiceController.delete').middleware('auth'); 34 Route.delete('service/:id', 'ServiceController.delete').middleware('auth');
35 Route.get('me/services', 'ServiceController.list').middleware('auth'); 35 Route.get('me/services', 'ServiceController.list').middleware('auth');
36 Route.get('recipe', 'ServiceController.list').middleware('auth'); 36 Route.get('recipe', 'ServiceController.list').middleware('auth');
37 Route.post('recipes/update', 'ServiceController.update').middleware('auth');
38 Route.get('icon/:id', 'ServiceController.icon'); 37 Route.get('icon/:id', 'ServiceController.icon');
39 38
40 // Recipe store 39 // Recipe store
41 Route.get('recipes', 'RecipeController.list'); 40 Route.get('recipes', 'RecipeController.list');
42 Route.get('recipes/download/:recipe', 'RecipeController.download');
43 Route.get('recipes/search', 'RecipeController.search'); 41 Route.get('recipes/search', 'RecipeController.search');
44 Route.get('recipes/popular', 'StaticController.popularRecipes'); 42 Route.get('recipes/popular', 'RecipeController.popularRecipes');
45 Route.get('recipes/update', 'StaticController.emptyArray'); 43 Route.get('recipes/download/:recipe', 'RecipeController.download');
44 Route.post('recipes/update', 'RecipeController.update');
46 45
47 // Workspaces 46 // Workspaces
48 Route.put('workspace/:id', 'WorkspaceController.edit').middleware('auth'); 47 Route.put('workspace/:id', 'WorkspaceController.edit').middleware('auth');