From 7120e22b83d06c928a1b7b2ce6645904c434c8cd Mon Sep 17 00:00:00 2001 From: vantezzen Date: Sun, 25 Aug 2019 13:40:30 +0200 Subject: Fix recipe store bundling of custom recipes --- app/Controllers/Http/RecipeController.js | 16 +++++++++++++--- app/Controllers/Http/UserController.js | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index 407379e..594c298 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js @@ -6,7 +6,7 @@ const Drive = use('Drive') const fetch = require('node-fetch'); const targz = require('targz'); const path = require('path'); -const fs = require('fs'); +const fs = require('fs-extra'); const compress = (src, dest) => { return new Promise((resolve, reject) => { @@ -51,19 +51,29 @@ class RecipeController { }) { const data = request.all(); + if (!data.id) { + return response.send('Please provide an ID'); + } + // Check for invalid characters if (/\.{1,}/.test(data.id) || /\/{1,}/.test(data.id)) { return response.send('Invalid recipe name. Your recipe name may not contain "." or "/"'); } + // Clear temporary recipe folder + await fs.emptyDir(Helpers.tmpPath('recipe')); + // Move uploaded files to temporary path const files = request.file('files') await files.moveAll(Helpers.tmpPath('recipe')) // Compress files to .tar.gz file + const source = Helpers.tmpPath('recipe'); + const destination = path.join(Helpers.appRoot(), '/recipes/' + data.id + '.tar.gz'); + console.log('a', source, destination) compress( - Helpers.tmpPath('recipe'), - path.join(Helpers.appRoot(), '/recipes/' + data.id + '.tar.gz') + source, + destination ); // Create recipe in db diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js index f78f28d..5c4d7fb 100644 --- a/app/Controllers/Http/UserController.js +++ b/app/Controllers/Http/UserController.js @@ -14,8 +14,9 @@ class UserController { }) { const data = request.only(['firstname', 'email', 'password']); + let user; try { - const user = await User.create({ + user = await User.create({ email: data.email, password: data.password, username: data.firstname -- cgit v1.2.3-54-g00ecf