diff options
| author | jfriedli | 2021-08-23 20:56:49 +0200 |
|---|---|---|
| committer | jfriedli | 2021-08-23 20:56:49 +0200 |
| commit | a60a0c845fb2da704c591f00078654feb2c01d20 (patch) | |
| tree | cc6280f85ebbc0bbdd4e4805a686fb5dc08c0758 /matweb/rest_api.py | |
| parent | 0219faa020eeaa960cd310c1d97de5b316e398e5 (diff) | |
validate bulk body is parsablev0.8.0
Diffstat (limited to 'matweb/rest_api.py')
| -rw-r--r-- | matweb/rest_api.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/matweb/rest_api.py b/matweb/rest_api.py index 48dcc10..5784bec 100644 --- a/matweb/rest_api.py +++ b/matweb/rest_api.py | |||
| @@ -7,7 +7,7 @@ from uuid import uuid4 | |||
| 7 | 7 | ||
| 8 | from flask import after_this_request, send_from_directory, Blueprint, current_app | 8 | from flask import after_this_request, send_from_directory, Blueprint, current_app |
| 9 | from flask_restful import Resource, reqparse, abort, request, url_for, Api | 9 | from flask_restful import Resource, reqparse, abort, request, url_for, Api |
| 10 | from cerberus import Validator | 10 | from cerberus import Validator, DocumentError |
| 11 | from werkzeug.datastructures import FileStorage | 11 | from werkzeug.datastructures import FileStorage |
| 12 | from flasgger import swag_from | 12 | from flasgger import swag_from |
| 13 | 13 | ||
| @@ -157,9 +157,13 @@ class APIBulkDownloadCreator(Resource): | |||
| 157 | if not data: | 157 | if not data: |
| 158 | abort(400, message="Post Body Required") | 158 | abort(400, message="Post Body Required") |
| 159 | current_app.logger.error('BulkDownload - Missing Post Body') | 159 | current_app.logger.error('BulkDownload - Missing Post Body') |
| 160 | if not self.v.validate(data): | 160 | try: |
| 161 | current_app.logger.error('BulkDownload - Missing Post Body: %s', str(self.v.errors)) | 161 | if not self.v.validate(data): |
| 162 | abort(400, message=self.v.errors) | 162 | current_app.logger.error('BulkDownload - Missing Post Body: %s', str(self.v.errors)) |
| 163 | abort(400, message=self.v.errors) | ||
| 164 | except DocumentError as e: | ||
| 165 | abort(400, message="Invalid Post Body") | ||
| 166 | current_app.logger.error('BulkDownload - Invalid Post Body: %s', str(e)) | ||
| 163 | # prevent the zip file from being overwritten | 167 | # prevent the zip file from being overwritten |
| 164 | zip_filename = 'files.' + str(uuid4()) + '.zip' | 168 | zip_filename = 'files.' + str(uuid4()) + '.zip' |
| 165 | zip_path = os.path.join(current_app.config['UPLOAD_FOLDER'], zip_filename) | 169 | zip_path = os.path.join(current_app.config['UPLOAD_FOLDER'], zip_filename) |
