diff options
author | Boris Bobrov <breton@cynicmansion.ru> | 2014-07-27 07:25:14 +0400 |
---|---|---|
committer | Boris Bobrov <breton@cynicmansion.ru> | 2015-02-16 13:41:09 +0300 |
commit | 54b4b28f84444a5b4e95eca0c2ca6429d52573c3 (patch) | |
tree | a9b93e8af396a5dfc150dfc2ee929885d5535935 /mediagoblin/plugins | |
parent | 067ee131885c2c3df88cb75e1c41a33d6681752f (diff) | |
download | mediagoblin-54b4b28f84444a5b4e95eca0c2ca6429d52573c3.tar.lz mediagoblin-54b4b28f84444a5b4e95eca0c2ca6429d52573c3.tar.xz mediagoblin-54b4b28f84444a5b4e95eca0c2ca6429d52573c3.zip |
Add new hook for two-step media type checking
Before uploaded media files were checked by extension. This led to
situations when a plugin can support file with specific extension but
doesn't due to lack of codecs, for example. Since the plugin reported
that it supports uploaded file type, the upload was being declared
successful, but transcoding failed.
The failures were not easy to debug.
The change adds a new hook that could allow two-step checking of the
content. The result of the hook execution returns a tuple with
media type name, manager and a callable sniffer, that can be used to
perform probably expensive checks of the content.
Also the change adds implementation of the hook for video.
Diffstat (limited to 'mediagoblin/plugins')
-rw-r--r-- | mediagoblin/plugins/api/views.py | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/mediagoblin/plugins/api/views.py b/mediagoblin/plugins/api/views.py index ef0b87e3..23341065 100644 --- a/mediagoblin/plugins/api/views.py +++ b/mediagoblin/plugins/api/views.py @@ -26,8 +26,7 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import json_response from mediagoblin.decorators import require_active_login from mediagoblin.meddleware.csrf import csrf_exempt -from mediagoblin.media_types import \ - InvalidFileType, FileTypeNotSupported +from mediagoblin.media_types import FileTypeNotSupported from mediagoblin.plugins.api.tools import api_auth, get_entry_serializable from mediagoblin.submit.lib import \ check_file_field, submit_media, get_upload_file_limits, \ @@ -83,17 +82,8 @@ def post_entry(request): except UserPastUploadLimit: raise BadRequest( _('Sorry, you have reached your upload limit.')) - - except Exception as e: - ''' - This section is intended to catch exceptions raised in - mediagoblin.media_types - ''' - if isinstance(e, InvalidFileType) or \ - isinstance(e, FileTypeNotSupported): - raise BadRequest(six.text_type(e)) - else: - raise + except FileTypeNotSupported as e: + raise BadRequest(e) @api_auth |