Show More
@@ -33,6 +33,7 b' from rhodecode.lib import audit_logger' | |||||
33 | from rhodecode.lib.auth import ( |
|
33 | from rhodecode.lib.auth import ( | |
34 | CSRFRequired, NotAnonymous, HasRepoPermissionAny, HasRepoGroupPermissionAny, |
|
34 | CSRFRequired, NotAnonymous, HasRepoPermissionAny, HasRepoGroupPermissionAny, | |
35 | LoginRequired) |
|
35 | LoginRequired) | |
|
36 | from rhodecode.lib.vcs.conf.mtypes import get_mimetypes_db | |||
36 | from rhodecode.model.db import Session, FileStore, UserApiKeys |
|
37 | from rhodecode.model.db import Session, FileStore, UserApiKeys | |
37 |
|
38 | |||
38 | log = logging.getLogger(__name__) |
|
39 | log = logging.getLogger(__name__) | |
@@ -46,6 +47,15 b' class FileStoreView(BaseAppView):' | |||||
46 | self.storage = utils.get_file_storage(self.request.registry.settings) |
|
47 | self.storage = utils.get_file_storage(self.request.registry.settings) | |
47 | return c |
|
48 | return c | |
48 |
|
49 | |||
|
50 | def _guess_type(self, file_name): | |||
|
51 | """ | |||
|
52 | Our own type guesser for mimetypes using the rich DB | |||
|
53 | """ | |||
|
54 | if not hasattr(self, 'db'): | |||
|
55 | self.db = get_mimetypes_db() | |||
|
56 | _content_type, _encoding = self.db.guess_type(file_name, strict=False) | |||
|
57 | return _content_type, _encoding | |||
|
58 | ||||
49 | def _serve_file(self, file_uid): |
|
59 | def _serve_file(self, file_uid): | |
50 |
|
60 | |||
51 | if not self.storage.exists(file_uid): |
|
61 | if not self.storage.exists(file_uid): | |
@@ -92,10 +102,18 b' class FileStoreView(BaseAppView):' | |||||
92 | FileStore.bump_access_counter(file_uid) |
|
102 | FileStore.bump_access_counter(file_uid) | |
93 |
|
103 | |||
94 | file_path = self.storage.store_path(file_uid) |
|
104 | file_path = self.storage.store_path(file_uid) | |
95 | return FileResponse(file_path) |
|
105 | content_type = 'application/octet-stream' | |
|
106 | content_encoding = None | |||
|
107 | ||||
|
108 | _content_type, _encoding = self._guess_type(file_path) | |||
|
109 | if _content_type: | |||
|
110 | content_type = _content_type | |||
|
111 | ||||
96 | # For file store we don't submit any session data, this logic tells the |
|
112 | # For file store we don't submit any session data, this logic tells the | |
97 | # Session lib to skip it |
|
113 | # Session lib to skip it | |
98 | setattr(self.request, '_file_response', True) |
|
114 | setattr(self.request, '_file_response', True) | |
|
115 | return FileResponse(file_path, request=self.request, | |||
|
116 | content_type=content_type, content_encoding=content_encoding) | |||
99 |
|
117 | |||
100 | @LoginRequired() |
|
118 | @LoginRequired() | |
101 | @NotAnonymous() |
|
119 | @NotAnonymous() |
@@ -18,6 +18,19 b'' | |||||
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
|
21 | DEFAULTS = { | |||
|
22 | 'encodings_map': {'.gz': 'gzip', | |||
|
23 | '.Z': 'compress', | |||
|
24 | '.bz2': 'bzip2', | |||
|
25 | '.xz': 'xz'}, | |||
|
26 | 'suffix_map': {'.svgz': '.svg.gz', | |||
|
27 | '.tgz': '.tar.gz', | |||
|
28 | '.taz': '.tar.gz', | |||
|
29 | '.tz': '.tar.gz', | |||
|
30 | '.tbz2': '.tar.bz2', | |||
|
31 | '.txz': '.tar.xz'}, | |||
|
32 | } | |||
|
33 | ||||
21 | TYPES_MAP = [ |
|
34 | TYPES_MAP = [ | |
22 | {'.jpg': 'image/jpg', |
|
35 | {'.jpg': 'image/jpg', | |
23 | '.mid': 'audio/midi', |
|
36 | '.mid': 'audio/midi', | |
@@ -1203,4 +1216,6 b' def get_mimetypes_db(extra_types=None):' | |||||
1203 | types_map[1].update(extra_types) |
|
1216 | types_map[1].update(extra_types) | |
1204 | db = mimetypes.MimeTypes() |
|
1217 | db = mimetypes.MimeTypes() | |
1205 | db.types_map = types_map |
|
1218 | db.types_map = types_map | |
|
1219 | db.encodings_map.update(DEFAULTS['encodings_map']) | |||
|
1220 | db.suffix_map.update(DEFAULTS['suffix_map']) | |||
1206 | return db |
|
1221 | return db |
General Comments 0
You need to be logged in to leave comments.
Login now