1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

Merge pull request #715 from haiwen/office-preview-xls-embedded-images

several improvements to office preview
This commit is contained in:
Daniel Pan
2015-07-13 22:27:19 +08:00
2 changed files with 23 additions and 4 deletions

View File

@@ -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'), 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'), IMAGE: ('gif', 'jpeg', 'jpg', 'png', 'ico', 'bmp'),
DOCUMENT: ('doc', 'docx', 'ppt', 'pptx'), DOCUMENT: ('doc', 'docx', 'ppt', 'pptx'),
SPREADSHEET: ('xls', 'xlsx'), SPREADSHEET: ('xls', 'xlsx', 'ods', 'fods'),
# SVG: ('svg',), # SVG: ('svg',),
PDF: ('pdf',), PDF: ('pdf',),
OPENDOCUMENT: ('odt', 'fodt', 'odp', 'fodp', 'ods', 'fods'), OPENDOCUMENT: ('odt', 'fodt', 'odp', 'fodp'),
MARKDOWN: ('markdown', 'md'), MARKDOWN: ('markdown', 'md'),
VIDEO: ('mp4', 'ogv', 'webm', 'flv', 'wmv'), VIDEO: ('mp4', 'ogv', 'webm', 'flv', 'wmv'),
AUDIO: ('mp3', 'oga', 'ogg'), AUDIO: ('mp3', 'oga', 'ogg'),
@@ -935,6 +935,12 @@ if HAS_OFFICE_CONVERTER:
OFFICE_HTML_DIR = get_office_converter_html_dir() OFFICE_HTML_DIR = get_office_converter_html_dir()
OFFICE_PREVIEW_MAX_SIZE, OFFICE_PREVIEW_MAX_PAGES = get_office_converter_limit() 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 from seafevents.office_converter import OfficeConverterRpcClient
office_converter_rpc = None office_converter_rpc = None

View File

@@ -13,6 +13,8 @@ import chardet
import logging import logging
import posixpath import posixpath
import re import re
import mimetypes
import urlparse
from django.core.cache import cache from django.core.cache import cache
from django.contrib.sites.models import RequestSite from django.contrib.sites.models import RequestSite
@@ -1322,6 +1324,13 @@ def check_office_token(func):
if not token: if not token:
token = request.GET.get('office_preview_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 request.office_preview_token = token
return func(request, *args, **kwargs) return func(request, *args, **kwargs)
@@ -1371,7 +1380,7 @@ def office_convert_query_status(request, internal=False):
# 1.page # 1.page
# 2.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 @check_office_token
def office_convert_get_page(request, path, internal=False): def office_convert_get_page(request, path, internal=False):
if not HAS_OFFICE_CONVERTER: if not HAS_OFFICE_CONVERTER:
@@ -1389,7 +1398,11 @@ def office_convert_get_page(request, path, internal=False):
# return HttpResponseForbidden() # return HttpResponseForbidden()
resp = get_office_converted_page(request, path, file_id, internal=internal) 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 return resp
###### private file/dir shares ###### private file/dir shares