From e1cc68d8bf4d473307638607dfee98a90bc7a6be Mon Sep 17 00:00:00 2001 From: kytwb Date: Thu, 6 Jan 2022 23:10:16 +0100 Subject: Review recipes routes, fix download recipe response type --- app/Controllers/Http/RecipeController.js | 22 +++++++++++++++++++--- app/Controllers/Http/ServiceController.js | 4 ---- app/Controllers/Http/StaticController.js | 12 ------------ 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'app') 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 { } = use('Validator'); const Env = use('Env'); -const fetch = require('node-fetch'); const targz = require('targz'); const path = require('path'); const fs = require('fs-extra'); @@ -90,7 +89,7 @@ class RecipeController { // Compress files to .tar.gz file const source = Helpers.tmpPath('recipe'); - const destination = path.join(Helpers.appRoot(), `/recipes/${data.id}.tar.gz`); + const destination = path.join(Helpers.appRoot(), `/recipes/recipes/${data.id}.tar.gz`); compress( source, @@ -155,6 +154,22 @@ class RecipeController { return response.send(results); } + popularRecipes({ + response, + }) { + return response.send( + fs + .readJsonSync(path.join( + Helpers.appRoot(), 'recipes', 'all.json', + )) + .filter((recipe) => recipe.featured), + ); + } + + update({ response }) { + return response.send([]); + } + // Download a recipe async download({ response, @@ -181,8 +196,9 @@ class RecipeController { // Check if recipe exists in recipes folder if (await Drive.exists(`${service}.tar.gz`)) { - return response.send(await Drive.get(`${service}.tar.gz`)); + return response.type('.tar.gz').send(await Drive.get(`${service}.tar.gz`)); } + return response.status(400).send({ message: 'Recipe not found', 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 { return response.send(servicesArray); } - update({ response }) { - return response.send([]); - } - async delete({ params, auth, response }) { // Update data in database 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 { }); } - popularRecipes({ - response, - }) { - return response.send( - fs - .readJsonSync(path.join( - Helpers.appRoot(), 'recipes', 'all.json', - )) - .filter((recipe) => recipe.featured), - ); - } - // Show announcements async announcement({ response, -- cgit v1.2.3-54-g00ecf