##// END OF EJS Templates
changed raw action to show images instead of saying about binary file...
marcink -
r1241:ed527052 beta
parent child Browse files
Show More
@@ -25,6 +25,7 b''
25 25
26 26 import os
27 27 import logging
28 import mimetypes
28 29 import rhodecode.lib.helpers as h
29 30
30 31 from pylons import request, response, session, tmpl_context as c, url
@@ -157,7 +158,43 b' class FilesController(BaseRepoController'
157 158 cs = self.__get_cs_or_redirect(revision, repo_name)
158 159 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
159 160
160 response.content_type = 'text/plain'
161 raw_mimetype_mapping = {
162 # map original mimetype to a mimetype used for "show as raw"
163 # you can also provide a content-disposition to override the
164 # default "attachment" disposition.
165 # orig_type: (new_type, new_dispo)
166
167 # show images inline:
168 'image/x-icon': ('image/x-icon', 'inline'),
169 'image/png': ('image/png', 'inline'),
170 'image/gif': ('image/gif', 'inline'),
171 'image/jpeg': ('image/jpeg', 'inline'),
172 'image/svg+xml': ('image/svg+xml', 'inline'),
173 }
174
175 mimetype = file_node.mimetype
176 try:
177 mimetype, dispo = raw_mimetype_mapping[mimetype]
178 except KeyError:
179 # we don't know anything special about this, handle it safely
180 if file_node.is_binary:
181 # do same as download raw for binary files
182 mimetype, dispo = 'application/octet-stream', 'attachment'
183 else:
184 # do not just use the original mimetype, but force text/plain,
185 # otherwise it would serve text/html and that might be unsafe.
186 # Note: underlying vcs library fakes text/plain mimetype if the
187 # mimetype can not be determined and it thinks it is not binary.
188 # This might lead to erroneous text display in some cases, but
189 # helps in other cases, like with text files without extension.
190 mimetype, dispo = 'text/plain', 'inline'
191
192 if dispo == 'attachment':
193 dispo = 'attachment; filename=%s' % \
194 f_path.split(os.sep)[-1].encode('utf8', 'replace')
195
196 response.content_disposition = dispo
197 response.content_type = mimetype
161 198 return file_node.content
162 199
163 200 def annotate(self, repo_name, revision, f_path):
@@ -64,7 +64,7 b''
64 64 </div>
65 65 <div class="code-body">
66 66 %if c.file.is_binary:
67 ${_('Binary file')}
67 ${_('Binary file (%s)') % c.file.mimetype}
68 68 %else:
69 69 % if c.file.size < c.cut_off_limit:
70 70 ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
@@ -37,7 +37,7 b''
37 37 </div>
38 38 <div class="code-body">
39 39 %if c.files_list.is_binary:
40 ${_('Binary file')}
40 ${_('Binary file (%s)') % c.files_list.mimetype}
41 41 %else:
42 42 % if c.files_list.size < c.cut_off_limit:
43 43 ${h.pygmentize(c.files_list,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")}
General Comments 0
You need to be logged in to leave comments. Login now