diff options
| author | jvoisin | 2019-03-06 21:20:39 +0100 |
|---|---|---|
| committer | jvoisin | 2019-03-06 21:25:06 +0100 |
| commit | 457d171cd48bf4809d3809fc9511836795972bf5 (patch) | |
| tree | 1469ba539371703008abc659c0af87dd215e9930 | |
| parent | 769bafac0acdf3e0b41f42a60df1029d6e0e3829 (diff) | |
Improve the display of supported formats
- Show the extension instead of the mimetype
- Sort the results
| -rw-r--r-- | main.py | 5 | ||||
| -rw-r--r-- | tests.py | 4 |
2 files changed, 6 insertions, 3 deletions
| @@ -1,6 +1,7 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import hashlib | 2 | import hashlib |
| 3 | import hmac | 3 | import hmac |
| 4 | import mimetypes as mtype | ||
| 4 | 5 | ||
| 5 | from libmat2 import parser_factory | 6 | from libmat2 import parser_factory |
| 6 | 7 | ||
| @@ -60,7 +61,9 @@ def upload_file(): | |||
| 60 | 61 | ||
| 61 | mimetypes = set() | 62 | mimetypes = set() |
| 62 | for parser in parser_factory._get_parsers(): | 63 | for parser in parser_factory._get_parsers(): |
| 63 | mimetypes = mimetypes | parser.mimetypes | 64 | mimetypes |= set(map(mtype.guess_extension, parser.mimetypes)) |
| 65 | # since `guess_extension` might return `None`, we need to filter it out | ||
| 66 | mimetypes = sorted(filter(None, mimetypes)) | ||
| 64 | 67 | ||
| 65 | if request.method == 'POST': | 68 | if request.method == 'POST': |
| 66 | if 'file' not in request.files: # check if the post request has the file part | 69 | if 'file' not in request.files: # check if the post request has the file part |
| @@ -21,8 +21,8 @@ class FlaskrTestCase(unittest.TestCase): | |||
| 21 | 21 | ||
| 22 | def test_check_mimetypes(self): | 22 | def test_check_mimetypes(self): |
| 23 | rv = self.app.get('/') | 23 | rv = self.app.get('/') |
| 24 | self.assertIn(b'application/zip', rv.data) | 24 | self.assertIn(b'.torrent', rv.data) |
| 25 | self.assertIn(b'audio/x-flac', rv.data) | 25 | self.assertIn(b'.ods', rv.data) |
| 26 | 26 | ||
| 27 | def test_get_download_dangerous_file(self): | 27 | def test_get_download_dangerous_file(self): |
| 28 | rv = self.app.get('/download/1337/\..\filename') | 28 | rv = self.app.get('/download/1337/\..\filename') |
