aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-08-25 13:40:30 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-08-25 13:40:30 +0200
commit7120e22b83d06c928a1b7b2ce6645904c434c8cd (patch)
tree98326511e596c95c17934e51e6b65178d05e58cc /app
parentAdd custom recipe creator (diff)
downloadferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.tar.gz
ferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.tar.zst
ferdium-server-7120e22b83d06c928a1b7b2ce6645904c434c8cd.zip
Fix recipe store bundling of custom recipes
Diffstat (limited to 'app')
-rw-r--r--app/Controllers/Http/RecipeController.js16
-rw-r--r--app/Controllers/Http/UserController.js3
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')
6const fetch = require('node-fetch'); 6const fetch = require('node-fetch');
7const targz = require('targz'); 7const targz = require('targz');
8const path = require('path'); 8const path = require('path');
9const fs = require('fs'); 9const fs = require('fs-extra');
10 10
11const compress = (src, dest) => { 11const 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