diff options
-rw-r--r-- | .env.example | 2 | ||||
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 12 | ||||
-rw-r--r-- | app/Exceptions/Handler.js | 45 | ||||
-rw-r--r-- | package-lock.json | 87 | ||||
-rw-r--r-- | public/new.html | 2 |
5 files changed, 145 insertions, 3 deletions
diff --git a/.env.example b/.env.example index de9f030..91e92a1 100644 --- a/.env.example +++ b/.env.example | |||
@@ -17,3 +17,5 @@ DB_PASSWORD= | |||
17 | DB_DATABASE=adonis | 17 | DB_DATABASE=adonis |
18 | 18 | ||
19 | HASH_DRIVER=bcrypt | 19 | HASH_DRIVER=bcrypt |
20 | |||
21 | IS_CREATION_ENABLED=true \ No newline at end of file | ||
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index 11938b6..ec0cde9 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js | |||
@@ -6,6 +6,7 @@ const Drive = use('Drive') | |||
6 | const { | 6 | const { |
7 | validateAll | 7 | validateAll |
8 | } = use('Validator'); | 8 | } = use('Validator'); |
9 | const Env = use('Env') | ||
9 | 10 | ||
10 | const fetch = require('node-fetch'); | 11 | const fetch = require('node-fetch'); |
11 | const targz = require('targz'); | 12 | const targz = require('targz'); |
@@ -53,18 +54,23 @@ class RecipeController { | |||
53 | request, | 54 | request, |
54 | response | 55 | response |
55 | }) { | 56 | }) { |
57 | // Check if recipe creation is enabled | ||
58 | if (Env.get('IS_CREATION_ENABLED') == 'false') { | ||
59 | return response.send('This server doesn\'t allow the creation of new recipes.'); | ||
60 | } | ||
61 | |||
56 | // Validate user input | 62 | // Validate user input |
57 | const validation = await validateAll(request.all(), { | 63 | const validation = await validateAll(request.all(), { |
58 | name: 'required|alpha', | 64 | name: 'required|alpha', |
59 | recipeId: 'required|unique:recipes,recipeId', | 65 | id: 'required|unique:recipes,recipeId', |
60 | author: 'required|accepted', | 66 | author: 'required|accepted', |
61 | png: 'required|url', | 67 | png: 'required|url', |
62 | svg: 'required|url', | 68 | svg: 'required|url', |
63 | files: 'required', | ||
64 | }); | 69 | }); |
65 | if (validation.fails()) { | 70 | if (validation.fails()) { |
66 | return response.status(401).send({ | 71 | return response.status(401).send({ |
67 | "message": "Invalid POST arguments", | 72 | "message": "Invalid POST arguments", |
73 | "messages": validation.messages(), | ||
68 | "status": 401 | 74 | "status": 401 |
69 | }) | 75 | }) |
70 | } | 76 | } |
@@ -126,6 +132,7 @@ class RecipeController { | |||
126 | if (validation.fails()) { | 132 | if (validation.fails()) { |
127 | return response.status(401).send({ | 133 | return response.status(401).send({ |
128 | "message": "Please provide a needle", | 134 | "message": "Please provide a needle", |
135 | "messages": validation.messages(), | ||
129 | "status": 401 | 136 | "status": 401 |
130 | }) | 137 | }) |
131 | } | 138 | } |
@@ -162,6 +169,7 @@ class RecipeController { | |||
162 | if (validation.fails()) { | 169 | if (validation.fails()) { |
163 | return response.status(401).send({ | 170 | return response.status(401).send({ |
164 | "message": "Please provide a recipe ID", | 171 | "message": "Please provide a recipe ID", |
172 | "messages": validation.messages(), | ||
165 | "status": 401 | 173 | "status": 401 |
166 | }) | 174 | }) |
167 | } | 175 | } |
diff --git a/app/Exceptions/Handler.js b/app/Exceptions/Handler.js new file mode 100644 index 0000000..94d7246 --- /dev/null +++ b/app/Exceptions/Handler.js | |||
@@ -0,0 +1,45 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const BaseExceptionHandler = use('BaseExceptionHandler') | ||
4 | |||
5 | /** | ||
6 | * This class handles all exceptions thrown during | ||
7 | * the HTTP request lifecycle. | ||
8 | * | ||
9 | * @class ExceptionHandler | ||
10 | */ | ||
11 | class ExceptionHandler extends BaseExceptionHandler { | ||
12 | /** | ||
13 | * Handle exception thrown during the HTTP lifecycle | ||
14 | * | ||
15 | * @method handle | ||
16 | * | ||
17 | * @param {Object} error | ||
18 | * @param {Object} options.request | ||
19 | * @param {Object} options.response | ||
20 | * | ||
21 | * @return {void} | ||
22 | */ | ||
23 | async handle (error, { request, response }) { | ||
24 | if (error.name === 'ValidationException') { | ||
25 | return response.status(400).send('Invalid arguments') | ||
26 | } | ||
27 | |||
28 | response.status(error.status).send(error.message) | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Report exception for logging or debugging. | ||
33 | * | ||
34 | * @method report | ||
35 | * | ||
36 | * @param {Object} error | ||
37 | * @param {Object} options.request | ||
38 | * | ||
39 | * @return {void} | ||
40 | */ | ||
41 | async report (error, { request }) { | ||
42 | } | ||
43 | } | ||
44 | |||
45 | module.exports = ExceptionHandler | ||
diff --git a/package-lock.json b/package-lock.json index 9b70b2d..b6ccb17 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -796,6 +796,15 @@ | |||
796 | "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", | 796 | "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", |
797 | "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" | 797 | "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" |
798 | }, | 798 | }, |
799 | "bl": { | ||
800 | "version": "1.2.2", | ||
801 | "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", | ||
802 | "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", | ||
803 | "requires": { | ||
804 | "readable-stream": "^2.3.5", | ||
805 | "safe-buffer": "^5.1.1" | ||
806 | } | ||
807 | }, | ||
799 | "bluebird": { | 808 | "bluebird": { |
800 | "version": "3.5.5", | 809 | "version": "3.5.5", |
801 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", | 810 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", |
@@ -827,11 +836,30 @@ | |||
827 | "to-regex": "^3.0.1" | 836 | "to-regex": "^3.0.1" |
828 | } | 837 | } |
829 | }, | 838 | }, |
839 | "buffer-alloc": { | ||
840 | "version": "1.2.0", | ||
841 | "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", | ||
842 | "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", | ||
843 | "requires": { | ||
844 | "buffer-alloc-unsafe": "^1.1.0", | ||
845 | "buffer-fill": "^1.0.0" | ||
846 | } | ||
847 | }, | ||
848 | "buffer-alloc-unsafe": { | ||
849 | "version": "1.1.0", | ||
850 | "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", | ||
851 | "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==" | ||
852 | }, | ||
830 | "buffer-equal-constant-time": { | 853 | "buffer-equal-constant-time": { |
831 | "version": "1.0.1", | 854 | "version": "1.0.1", |
832 | "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", | 855 | "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", |
833 | "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" | 856 | "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" |
834 | }, | 857 | }, |
858 | "buffer-fill": { | ||
859 | "version": "1.0.0", | ||
860 | "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", | ||
861 | "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" | ||
862 | }, | ||
835 | "buffer-writer": { | 863 | "buffer-writer": { |
836 | "version": "2.0.0", | 864 | "version": "2.0.0", |
837 | "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", | 865 | "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", |
@@ -1648,6 +1676,11 @@ | |||
1648 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", | 1676 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", |
1649 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" | 1677 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" |
1650 | }, | 1678 | }, |
1679 | "fs-constants": { | ||
1680 | "version": "1.0.0", | ||
1681 | "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", | ||
1682 | "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" | ||
1683 | }, | ||
1651 | "fs-extra": { | 1684 | "fs-extra": { |
1652 | "version": "7.0.1", | 1685 | "version": "7.0.1", |
1653 | "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", | 1686 | "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", |
@@ -4310,6 +4343,50 @@ | |||
4310 | "yallist": "^3.0.3" | 4343 | "yallist": "^3.0.3" |
4311 | } | 4344 | } |
4312 | }, | 4345 | }, |
4346 | "tar-fs": { | ||
4347 | "version": "1.16.3", | ||
4348 | "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.16.3.tgz", | ||
4349 | "integrity": "sha512-NvCeXpYx7OsmOh8zIOP/ebG55zZmxLE0etfWRbWok+q2Qo8x/vOR/IJT1taADXPe+jsiu9axDb3X4B+iIgNlKw==", | ||
4350 | "requires": { | ||
4351 | "chownr": "^1.0.1", | ||
4352 | "mkdirp": "^0.5.1", | ||
4353 | "pump": "^1.0.0", | ||
4354 | "tar-stream": "^1.1.2" | ||
4355 | }, | ||
4356 | "dependencies": { | ||
4357 | "pump": { | ||
4358 | "version": "1.0.3", | ||
4359 | "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.3.tgz", | ||
4360 | "integrity": "sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==", | ||
4361 | "requires": { | ||
4362 | "end-of-stream": "^1.1.0", | ||
4363 | "once": "^1.3.1" | ||
4364 | } | ||
4365 | } | ||
4366 | } | ||
4367 | }, | ||
4368 | "tar-stream": { | ||
4369 | "version": "1.6.2", | ||
4370 | "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz", | ||
4371 | "integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==", | ||
4372 | "requires": { | ||
4373 | "bl": "^1.0.0", | ||
4374 | "buffer-alloc": "^1.2.0", | ||
4375 | "end-of-stream": "^1.0.0", | ||
4376 | "fs-constants": "^1.0.0", | ||
4377 | "readable-stream": "^2.3.0", | ||
4378 | "to-buffer": "^1.1.1", | ||
4379 | "xtend": "^4.0.0" | ||
4380 | } | ||
4381 | }, | ||
4382 | "targz": { | ||
4383 | "version": "1.0.1", | ||
4384 | "resolved": "https://registry.npmjs.org/targz/-/targz-1.0.1.tgz", | ||
4385 | "integrity": "sha1-j3alI2lM3t+7XWCkB2/27uzFOY8=", | ||
4386 | "requires": { | ||
4387 | "tar-fs": "^1.8.1" | ||
4388 | } | ||
4389 | }, | ||
4313 | "tarn": { | 4390 | "tarn": { |
4314 | "version": "1.1.5", | 4391 | "version": "1.1.5", |
4315 | "resolved": "https://registry.npmjs.org/tarn/-/tarn-1.1.5.tgz", | 4392 | "resolved": "https://registry.npmjs.org/tarn/-/tarn-1.1.5.tgz", |
@@ -4356,6 +4433,11 @@ | |||
4356 | "os-tmpdir": "~1.0.2" | 4433 | "os-tmpdir": "~1.0.2" |
4357 | } | 4434 | } |
4358 | }, | 4435 | }, |
4436 | "to-buffer": { | ||
4437 | "version": "1.1.1", | ||
4438 | "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", | ||
4439 | "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" | ||
4440 | }, | ||
4359 | "to-object-path": { | 4441 | "to-object-path": { |
4360 | "version": "0.3.0", | 4442 | "version": "0.3.0", |
4361 | "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", | 4443 | "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", |
@@ -4601,6 +4683,11 @@ | |||
4601 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", | 4683 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", |
4602 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" | 4684 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" |
4603 | }, | 4685 | }, |
4686 | "uuid": { | ||
4687 | "version": "3.3.3", | ||
4688 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", | ||
4689 | "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" | ||
4690 | }, | ||
4604 | "v8flags": { | 4691 | "v8flags": { |
4605 | "version": "3.1.3", | 4692 | "version": "3.1.3", |
4606 | "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.1.3.tgz", | 4693 | "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.1.3.tgz", |
diff --git a/public/new.html b/public/new.html index b0e4b41..c11da47 100644 --- a/public/new.html +++ b/public/new.html | |||
@@ -104,7 +104,7 @@ | |||
104 | </p> | 104 | </p> |
105 | </div> | 105 | </div> |
106 | </div> | 106 | </div> |
107 | <input type="file" name="files[]" id="files" value="" multiple><br /><br /> | 107 | <input type="file" name="files[]" id="files" value="" multiple required><br /><br /> |
108 | 108 | ||
109 | <button type="submit" id="submitbutton">Create recipe</button> | 109 | <button type="submit" id="submitbutton">Create recipe</button> |
110 | </form> | 110 | </form> |