1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-19 09:37:51 +00:00

Merge pull request #4991 from haiwen/office-preview-docker

office preview docker
This commit is contained in:
Daniel Pan 2021-09-24 17:21:06 +08:00 committed by GitHub
commit 5f61dbdb48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 52 deletions

View File

@ -110,12 +110,6 @@ urlpatterns = [
# serve office converter static files
from seahub.utils import HAS_OFFICE_CONVERTER
if HAS_OFFICE_CONVERTER:
from seahub.utils import OFFICE_HTML_DIR
from django.views.static import serve as static_view
urlpatterns += [
url(r'^office-convert/static/(?P<path>.*)$', static_view, {'document_root': OFFICE_HTML_DIR}, name='api_office_convert_static'),
]
urlpatterns += [
url(r'^office-convert/status/$', OfficeConvertQueryStatus.as_view()),
]

View File

@ -5061,7 +5061,7 @@ class OfficeGenerateView(APIView):
ret_dict = {}
if HAS_OFFICE_CONVERTER:
err = prepare_converted_html(inner_path, obj_id, fileext, ret_dict)
err = prepare_converted_html(raw_path, obj_id, fileext, ret_dict)
# populate return value dict
ret_dict['err'] = err
ret_dict['obj_id'] = obj_id

View File

@ -1084,41 +1084,21 @@ if EVENTS_CONFIG_FILE:
FILE_AUDIT_ENABLED = check_file_audit_enabled()
# office convert related
HAS_OFFICE_CONVERTER = False
if EVENTS_CONFIG_FILE:
def check_office_converter_enabled():
enabled = False
if hasattr(seafevents, 'is_office_converter_enabled'):
enabled = seafevents.is_office_converter_enabled(parsed_events_conf)
if enabled:
logging.debug('office converter: enabled')
else:
logging.debug('office converter: not enabled')
return enabled
def get_office_converter_html_dir():
return seafevents.get_office_converter_dir(parsed_events_conf, 'html')
def get_office_converter_pdf_dir():
return seafevents.get_office_converter_dir(parsed_events_conf, 'pdf')
def get_office_converter_limit():
return seafevents.get_office_converter_limit(parsed_events_conf)
HAS_OFFICE_CONVERTER = check_office_converter_enabled()
def check_office_converter_enabled():
if OFFICE_CONVERTOR_ROOT:
return True
return False
HAS_OFFICE_CONVERTER = check_office_converter_enabled()
OFFICE_PREVIEW_MAX_SIZE = 2 * 1024 * 1024
OFFICE_PREVIEW_MAX_PAGES = 50
if HAS_OFFICE_CONVERTER:
import time
import requests
import jwt
OFFICE_HTML_DIR = get_office_converter_html_dir()
OFFICE_PDF_DIR = get_office_converter_pdf_dir()
OFFICE_PREVIEW_MAX_SIZE, OFFICE_PREVIEW_MAX_PAGES = get_office_converter_limit()
def add_office_convert_task(file_id, doctype, raw_path):
payload = {'exp': int(time.time()) + 300, }
token = jwt.encode(payload, seahub.settings.SECRET_KEY, algorithm='HS256')
@ -1145,17 +1125,7 @@ if HAS_OFFICE_CONVERTER:
ret['status'] = d['status']
return ret
def get_office_converted_page(request, static_filename, file_id):
office_out_dir = OFFICE_HTML_DIR
filepath = os.path.join(file_id, static_filename)
if static_filename.endswith('.pdf'):
office_out_dir = OFFICE_PDF_DIR
filepath = static_filename
return django_static_serve(request,
filepath,
document_root=office_out_dir)
def cluster_get_office_converted_page(path, static_filename, file_id):
def get_office_converted_page(path, static_filename, file_id):
url = urljoin(OFFICE_CONVERTOR_ROOT, '/get-converted-page')
payload = {'exp': int(time.time()) + 300, }
token = jwt.encode(payload, seahub.settings.SECRET_KEY, algorithm='HS256')

View File

@ -81,8 +81,8 @@ from seahub.drafts.utils import get_file_draft, \
if HAS_OFFICE_CONVERTER:
from seahub.utils import (
query_office_convert_status, cluster_get_office_converted_page,
prepare_converted_html, get_office_converted_page, CLUSTER_MODE
query_office_convert_status, get_office_converted_page,
prepare_converted_html,
)
import seahub.settings as settings
@ -876,7 +876,7 @@ def view_lib_file(request, repo_id, path):
return_dict['err'] = error_msg
return render(request, template, return_dict)
error_msg = prepare_converted_html(inner_path, file_id, fileext, return_dict)
error_msg = prepare_converted_html(raw_path, file_id, fileext, return_dict)
if error_msg:
return_dict['err'] = error_msg
return render(request, template, return_dict)
@ -1815,10 +1815,7 @@ def office_convert_get_page(request, repo_id, commit_id, path, filename):
if filename.endswith('.pdf'):
filename = "{0}.pdf".format(file_id)
if CLUSTER_MODE:
resp = cluster_get_office_converted_page(path, filename, file_id)
else:
resp = get_office_converted_page(request, filename, file_id)
resp = get_office_converted_page(path, filename, file_id)
if filename.endswith('.page'):
content_type = 'text/html'