diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 2f14a07460..33bad389e6 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -101,10 +101,10 @@ PREVIEW_FILEEXT = { TEXT: ('ac', 'am', 'bat', 'c', 'cc', 'cmake', 'cpp', 'cs', 'css', 'diff', 'el', 'h', 'html', 'htm', 'java', 'js', 'json', 'less', 'make', 'org', 'php', 'pl', 'properties', 'py', 'rb', 'scala', 'script', 'sh', 'sql', 'txt', 'text', 'tex', 'vi', 'vim', 'xhtml', 'xml', 'log', 'csv', 'groovy', 'rst', 'patch', 'go'), IMAGE: ('gif', 'jpeg', 'jpg', 'png', 'ico', 'bmp'), DOCUMENT: ('doc', 'docx', 'ppt', 'pptx'), - SPREADSHEET: ('xls', 'xlsx'), + SPREADSHEET: ('xls', 'xlsx', 'ods', 'fods'), # SVG: ('svg',), PDF: ('pdf',), - OPENDOCUMENT: ('odt', 'fodt', 'odp', 'fodp', 'ods', 'fods'), + OPENDOCUMENT: ('odt', 'fodt', 'odp', 'fodp'), MARKDOWN: ('markdown', 'md'), VIDEO: ('mp4', 'ogv', 'webm', 'flv', 'wmv'), AUDIO: ('mp3', 'oga', 'ogg'), @@ -935,6 +935,12 @@ if HAS_OFFICE_CONVERTER: OFFICE_HTML_DIR = get_office_converter_html_dir() OFFICE_PREVIEW_MAX_SIZE, OFFICE_PREVIEW_MAX_PAGES = get_office_converter_limit() + all_doc_types = PREVIEW_FILEEXT[DOCUMENT] + PREVIEW_FILEEXT[OPENDOCUMENT] + PREVIEW_FILEEXT[DOCUMENT] = all_doc_types + PREVIEW_FILEEXT.pop(OPENDOCUMENT) + + FILEEXT_TYPE_MAP = gen_fileext_type_map() + from seafevents.office_converter import OfficeConverterRpcClient office_converter_rpc = None diff --git a/seahub/views/file.py b/seahub/views/file.py index cec8477fb1..f1034d5e86 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -13,6 +13,8 @@ import chardet import logging import posixpath import re +import mimetypes +import urlparse from django.core.cache import cache from django.contrib.sites.models import RequestSite @@ -1322,6 +1324,13 @@ def check_office_token(func): if not token: token = request.GET.get('office_preview_token', '') + if not token: + # Work around for the images embedded in excel files + referer = request.META.get('HTTP_REFERER', '') + if referer: + token = urlparse.parse_qs( + urlparse.urlparse(referer).query).get('office_preview_token', [''])[0] + request.office_preview_token = token return func(request, *args, **kwargs) @@ -1371,7 +1380,7 @@ def office_convert_query_status(request, internal=False): # 1.page # 2.page # ... -_OFFICE_PAGE_PATTERN = re.compile(r'^([0-9a-f]{40})/([\d]+\.page|file\.css|file\.outline|index.html)$') +_OFFICE_PAGE_PATTERN = re.compile(r'^([0-9a-f]{40})/([\d]+\.page|file\.css|file\.outline|index.html|index_html_(.*).png)$') @check_office_token def office_convert_get_page(request, path, internal=False): if not HAS_OFFICE_CONVERTER: @@ -1389,7 +1398,11 @@ def office_convert_get_page(request, path, internal=False): # return HttpResponseForbidden() resp = get_office_converted_page(request, path, file_id, internal=internal) - resp['Content-Type'] = 'text/html' + if path.endswith('.page'): + content_type = 'text/html' + else: + content_type = mimetypes.guess_type(path)[0] or 'text/html' + resp['Content-Type'] = content_type return resp ###### private file/dir shares