diff options
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 16 | ||||
-rw-r--r-- | app/Controllers/Http/UserController.js | 3 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | yarn.lock | 11 |
4 files changed, 26 insertions, 5 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 |
diff --git a/package.json b/package.json index 327fb8e..27e92df 100644 --- a/package.json +++ b/package.json | |||
@@ -26,6 +26,7 @@ | |||
26 | "@adonisjs/ignitor": "^2.0.8", | 26 | "@adonisjs/ignitor": "^2.0.8", |
27 | "@adonisjs/lucid": "^6.1.3", | 27 | "@adonisjs/lucid": "^6.1.3", |
28 | "atob": "^2.1.2", | 28 | "atob": "^2.1.2", |
29 | "fs-extra": "^8.1.0", | ||
29 | "node-fetch": "^2.6.0", | 30 | "node-fetch": "^2.6.0", |
30 | "pg": "^7.12.1", | 31 | "pg": "^7.12.1", |
31 | "sqlite3": "^4.1.0", | 32 | "sqlite3": "^4.1.0", |
@@ -1377,6 +1377,15 @@ fs-extra@^7.0.0: | |||
1377 | jsonfile "^4.0.0" | 1377 | jsonfile "^4.0.0" |
1378 | universalify "^0.1.0" | 1378 | universalify "^0.1.0" |
1379 | 1379 | ||
1380 | fs-extra@^8.1.0: | ||
1381 | version "8.1.0" | ||
1382 | resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" | ||
1383 | integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g== | ||
1384 | dependencies: | ||
1385 | graceful-fs "^4.2.0" | ||
1386 | jsonfile "^4.0.0" | ||
1387 | universalify "^0.1.0" | ||
1388 | |||
1380 | fs-minipass@^1.2.5: | 1389 | fs-minipass@^1.2.5: |
1381 | version "1.2.6" | 1390 | version "1.2.6" |
1382 | resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07" | 1391 | resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07" |
@@ -1454,7 +1463,7 @@ global-prefix@^1.0.1: | |||
1454 | is-windows "^1.0.1" | 1463 | is-windows "^1.0.1" |
1455 | which "^1.2.14" | 1464 | which "^1.2.14" |
1456 | 1465 | ||
1457 | graceful-fs@^4.1.2, graceful-fs@^4.1.6: | 1466 | graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0: |
1458 | version "4.2.2" | 1467 | version "4.2.2" |
1459 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" | 1468 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" |
1460 | integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q== | 1469 | integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q== |