diff options
author | vantezzen <properly@protonmail.com> | 2019-08-25 13:40:30 +0200 |
---|---|---|
committer | vantezzen <properly@protonmail.com> | 2019-08-25 13:40:30 +0200 |
commit | 7120e22b83d06c928a1b7b2ce6645904c434c8cd (patch) | |
tree | 98326511e596c95c17934e51e6b65178d05e58cc /app/Controllers | |
parent | Add custom recipe creator (diff) | |
download | ferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.tar.gz ferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.tar.zst ferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.zip |
Fix recipe store bundling of custom recipes
Diffstat (limited to 'app/Controllers')
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 16 | ||||
-rw-r--r-- | app/Controllers/Http/UserController.js | 3 |
2 files changed, 15 insertions, 4 deletions
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') | |||
6 | const fetch = require('node-fetch'); | 6 | const fetch = require('node-fetch'); |
7 | const targz = require('targz'); | 7 | const targz = require('targz'); |
8 | const path = require('path'); | 8 | const path = require('path'); |
9 | const fs = require('fs'); | 9 | const fs = require('fs-extra'); |
10 | 10 | ||
11 | const compress = (src, dest) => { | 11 | const compress = (src, dest) => { |
12 | return new Promise((resolve, reject) => { | 12 | return new Promise((resolve, reject) => { |
@@ -51,19 +51,29 @@ class RecipeController { | |||
51 | }) { | 51 | }) { |
52 | const data = request.all(); | 52 | const data = request.all(); |
53 | 53 | ||
54 | if (!data.id) { | ||
55 | return response.send('Please provide an ID'); | ||
56 | } | ||
57 | |||
54 | // Check for invalid characters | 58 | // Check for invalid characters |
55 | if (/\.{1,}/.test(data.id) || /\/{1,}/.test(data.id)) { | 59 | if (/\.{1,}/.test(data.id) || /\/{1,}/.test(data.id)) { |
56 | return response.send('Invalid recipe name. Your recipe name may not contain "." or "/"'); | 60 | return response.send('Invalid recipe name. Your recipe name may not contain "." or "/"'); |
57 | } | 61 | } |
58 | 62 | ||
63 | // Clear temporary recipe folder | ||
64 | await fs.emptyDir(Helpers.tmpPath('recipe')); | ||
65 | |||
59 | // Move uploaded files to temporary path | 66 | // Move uploaded files to temporary path |
60 | const files = request.file('files') | 67 | const files = request.file('files') |
61 | await files.moveAll(Helpers.tmpPath('recipe')) | 68 | await files.moveAll(Helpers.tmpPath('recipe')) |
62 | 69 | ||
63 | // Compress files to .tar.gz file | 70 | // Compress files to .tar.gz file |
71 | const source = Helpers.tmpPath('recipe'); | ||
72 | const destination = path.join(Helpers.appRoot(), '/recipes/' + data.id + '.tar.gz'); | ||
73 | console.log('a', source, destination) | ||
64 | compress( | 74 | compress( |
65 | Helpers.tmpPath('recipe'), | 75 | source, |
66 | path.join(Helpers.appRoot(), '/recipes/' + data.id + '.tar.gz') | 76 | destination |
67 | ); | 77 | ); |
68 | 78 | ||
69 | // Create recipe in db | 79 | // 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 { | |||
14 | }) { | 14 | }) { |
15 | const data = request.only(['firstname', 'email', 'password']); | 15 | const data = request.only(['firstname', 'email', 'password']); |
16 | 16 | ||
17 | let user; | ||
17 | try { | 18 | try { |
18 | const user = await User.create({ | 19 | user = await User.create({ |
19 | email: data.email, | 20 | email: data.email, |
20 | password: data.password, | 21 | password: data.password, |
21 | username: data.firstname | 22 | username: data.firstname |