aboutsummaryrefslogtreecommitdiffstats
path: root/app/Controllers/Http/RecipeController.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers/Http/RecipeController.js')
-rw-r--r--app/Controllers/Http/RecipeController.js16
1 files changed, 13 insertions, 3 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