diff --git a/seahub/api2/urls.py b/seahub/api2/urls.py index a59551f855..d0a5fb978a 100644 --- a/seahub/api2/urls.py +++ b/seahub/api2/urls.py @@ -122,3 +122,9 @@ if HAS_OFFICE_CONVERTER: urlpatterns += patterns('', url(r'^office-convert/generate/repos/(?P[-0-9-a-f]{36})/$', OfficeGenerateView.as_view()), ) + +from seahub import settings +if getattr(settings, 'ENABLE_OFFICE_WEB_APP', False): + urlpatterns += patterns('', + (r'^wopi/', include('seahub_extra.wopi.urls')), + ) diff --git a/seahub/templates/view_wopi_file.html b/seahub/templates/view_wopi_file.html new file mode 100644 index 0000000000..7876a68be6 --- /dev/null +++ b/seahub/templates/view_wopi_file.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + diff --git a/seahub/views/file.py b/seahub/views/file.py index d3beac346b..3db77112df 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -74,6 +74,17 @@ if HAS_OFFICE_CONVERTER: import seahub.settings as settings from seahub.settings import FILE_ENCODING_LIST, FILE_PREVIEW_MAX_SIZE, \ FILE_ENCODING_TRY_LIST, USE_PDFJS, MEDIA_URL, SITE_ROOT + +try: + from seahub.settings import ENABLE_OFFICE_WEB_APP +except ImportError: + ENABLE_OFFICE_WEB_APP = False + +try: + from seahub.settings import OFFICE_WEB_APP_FILE_EXTENSION +except ImportError: + OFFICE_WEB_APP_FILE_EXTENSION = () + from seahub.views import is_registered_user, check_repo_access_permission, \ get_unencry_rw_repos_by_user, get_file_access_permission @@ -366,6 +377,19 @@ def _file_view(request, repo_id, path): if not user_perm: return render_permission_error(request, _(u'Unable to view file')) + # check if use wopi host page according to filetype + if ENABLE_OFFICE_WEB_APP and fileext in OFFICE_WEB_APP_FILE_EXTENSION: + try: + from seahub_extra.wopi.utils import get_wopi_dict + except ImportError: + wopi_dict = None + else: + wopi_dict = get_wopi_dict(username, repo_id, path) + + if wopi_dict: + return render_to_response('view_wopi_file.html', wopi_dict, + context_instance=RequestContext(request)) + # check if the user is the owner or not, for 'private share' if is_org_context(request): repo_owner = seafile_api.get_org_repo_owner(repo.id)