diff options
| -rw-r--r-- | matweb/frontend.py | 31 | ||||
| -rw-r--r-- | matweb/rest_api.py | 46 | ||||
| -rw-r--r-- | test/test_api.py | 1 |
3 files changed, 41 insertions, 37 deletions
diff --git a/matweb/frontend.py b/matweb/frontend.py index 48e4c19..7a3037d 100644 --- a/matweb/frontend.py +++ b/matweb/frontend.py | |||
| @@ -71,22 +71,23 @@ def upload_file(): | |||
| 71 | current_app.logger.error('Unsupported type %s', mime) | 71 | current_app.logger.error('Unsupported type %s', mime) |
| 72 | return redirect(url_for('routes.upload_file')) | 72 | return redirect(url_for('routes.upload_file')) |
| 73 | 73 | ||
| 74 | meta = parser.get_meta() | 74 | try: |
| 75 | 75 | if parser.remove_all() is not True: | |
| 76 | if parser.remove_all() is not True: | 76 | flash('Unable to clean %s' % mime) |
| 77 | flash('Unable to clean %s' % mime) | 77 | current_app.logger.error('Unable to clean %s', mime) |
| 78 | current_app.logger.error('Unable to clean %s', mime) | 78 | return redirect(url_for('routes.upload_file')) |
| 79 | return redirect(url_for('routes.upload_file')) | 79 | meta = parser.get_meta() |
| 80 | 80 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) | |
| 81 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) | ||
| 82 | 81 | ||
| 83 | return render_template( | 82 | return render_template( |
| 84 | 'download.html', | 83 | 'download.html', |
| 85 | mimetypes=mime_types, | 84 | mimetypes=mime_types, |
| 86 | meta=meta, | 85 | meta=meta, |
| 87 | download_uri=url_for('routes.download_file', key=key, secret=secret, filename=output_filename), | 86 | download_uri=url_for('routes.download_file', key=key, secret=secret, filename=output_filename), |
| 88 | meta_after=meta_after, | 87 | meta_after=meta_after, |
| 89 | ) | 88 | ) |
| 89 | except (RuntimeError, ValueError): | ||
| 90 | flash('The type %s could no be cleaned' % mime) | ||
| 90 | 91 | ||
| 91 | max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024) | 92 | max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024) |
| 92 | return render_template('index.html', max_file_size=max_file_size, mimetypes=mime_types) \ No newline at end of file | 93 | return render_template('index.html', max_file_size=max_file_size, mimetypes=mime_types) \ No newline at end of file |
diff --git a/matweb/rest_api.py b/matweb/rest_api.py index d3d9d8f..ef1a55a 100644 --- a/matweb/rest_api.py +++ b/matweb/rest_api.py | |||
| @@ -46,29 +46,31 @@ class APIUpload(Resource): | |||
| 46 | if parser is None: | 46 | if parser is None: |
| 47 | current_app.logger.error('Upload - Invalid mime type %s', mime) | 47 | current_app.logger.error('Upload - Invalid mime type %s', mime) |
| 48 | abort(415, message='The type %s is not supported' % mime) | 48 | abort(415, message='The type %s is not supported' % mime) |
| 49 | 49 | try: | |
| 50 | meta = parser.get_meta() | 50 | if not parser.remove_all(): |
| 51 | if not parser.remove_all(): | 51 | raise ValueError() |
| 52 | meta = parser.get_meta() | ||
| 53 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, | ||
| 54 | current_app.config['UPLOAD_FOLDER']) | ||
| 55 | return utils.return_file_created_response( | ||
| 56 | utils.get_file_removal_max_age_sec(), | ||
| 57 | output_filename, | ||
| 58 | mime, | ||
| 59 | key, | ||
| 60 | secret, | ||
| 61 | meta, | ||
| 62 | meta_after, | ||
| 63 | url_for( | ||
| 64 | 'api_bp.apidownload', | ||
| 65 | key=key, | ||
| 66 | secret=secret, | ||
| 67 | filename=output_filename, | ||
| 68 | _external=True | ||
| 69 | ) | ||
| 70 | ), 201 | ||
| 71 | except (ValueError, RuntimeError) as e: | ||
| 52 | current_app.logger.error('Upload - Cleaning failed with mime: %s', mime) | 72 | current_app.logger.error('Upload - Cleaning failed with mime: %s', mime) |
| 53 | abort(500, message='Unable to clean %s' % mime) | 73 | abort(400, message='Unable to clean %s' % mime) |
| 54 | |||
| 55 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) | ||
| 56 | return utils.return_file_created_response( | ||
| 57 | utils.get_file_removal_max_age_sec(), | ||
| 58 | output_filename, | ||
| 59 | mime, | ||
| 60 | key, | ||
| 61 | secret, | ||
| 62 | meta, | ||
| 63 | meta_after, | ||
| 64 | url_for( | ||
| 65 | 'api_bp.apidownload', | ||
| 66 | key=key, | ||
| 67 | secret=secret, | ||
| 68 | filename=output_filename, | ||
| 69 | _external=True | ||
| 70 | ) | ||
| 71 | ), 201 | ||
| 72 | 74 | ||
| 73 | 75 | ||
| 74 | class APIDownload(Resource): | 76 | class APIDownload(Resource): |
diff --git a/test/test_api.py b/test/test_api.py index 6d48a35..907aabf 100644 --- a/test/test_api.py +++ b/test/test_api.py | |||
| @@ -135,6 +135,7 @@ class Mat2APITestCase(unittest.TestCase): | |||
| 135 | headers={'content-type': 'application/json'} | 135 | headers={'content-type': 'application/json'} |
| 136 | ) | 136 | ) |
| 137 | error = request.get_json()['message'] | 137 | error = request.get_json()['message'] |
| 138 | self.assertEqual(request.status_code, 400) | ||
| 138 | self.assertEqual(error, 'Unable to clean application/zip') | 139 | self.assertEqual(error, 'Unable to clean application/zip') |
| 139 | 140 | ||
| 140 | def test_api_download(self): | 141 | def test_api_download(self): |
