mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-14 15:35:35 +00:00
commit
cf41dd6be2
@ -36,6 +36,7 @@ urlpatterns = patterns('',
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/upload-blks-link/$', UploadBlksLinkView.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/update-blks-link/$', UpdateBlksLinkView.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/owa-file/$', OwaFileView.as_view(), name='api2-owa-file-view'),
|
||||
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/file/$', FileView.as_view(), name='FileView'),
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/files/(?P<file_id>[0-9a-f]{40})/blks/(?P<block_id>[0-9a-f]{40})/download-link/$', FileBlockDownloadLinkView.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/file/detail/$', FileDetailView.as_view()),
|
||||
|
@ -105,6 +105,16 @@ try:
|
||||
except ImportError:
|
||||
ORG_MEMBER_QUOTA_DEFAULT = None
|
||||
|
||||
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 pysearpc import SearpcError, SearpcObjEncoder
|
||||
import seaserv
|
||||
from seaserv import seafserv_rpc, seafserv_threaded_rpc, \
|
||||
@ -1643,6 +1653,71 @@ class StarredFileView(APIView):
|
||||
unstar_file(request.user.username, repo_id, path)
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
|
||||
class OwaFileView(APIView):
|
||||
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
permission_classes = (IsAuthenticated, )
|
||||
throttle_classes = (UserRateThrottle, )
|
||||
|
||||
def get(self, request, repo_id, format=None):
|
||||
""" Get action url and access token when view file through Office Web App
|
||||
"""
|
||||
|
||||
# check args
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
error_msg = 'Library %s not found.' % repo_id
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
path = request.GET.get('path', None)
|
||||
if not path:
|
||||
error_msg = 'path invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
try:
|
||||
file_id = seafile_api.get_file_id_by_path(repo_id, path)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
if not file_id:
|
||||
error_msg = 'File %s not found.' % path
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
# check permission
|
||||
if not is_pro_version():
|
||||
error_msg = 'Office Web App feature only supported in professional edition.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
if check_folder_permission(request, repo_id, path) is None:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
if repo.encrypted:
|
||||
error_msg = 'Library encrypted.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
if not ENABLE_OFFICE_WEB_APP:
|
||||
error_msg = 'Office Web App feature not enabled.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
filename = os.path.basename(path)
|
||||
filetype, fileext = get_file_type_and_ext(filename)
|
||||
if fileext not in OFFICE_WEB_APP_FILE_EXTENSION:
|
||||
error_msg = 'path invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# get wopi dict
|
||||
from seahub_extra.wopi.utils import get_wopi_dict
|
||||
username = request.user.username
|
||||
wopi_dict = get_wopi_dict(username, repo_id, path)
|
||||
|
||||
# send stats message
|
||||
send_file_access_msg(request, repo, path, 'api')
|
||||
return Response(wopi_dict)
|
||||
|
||||
|
||||
class FileView(APIView):
|
||||
"""
|
||||
Support uniform interface for file related operations,
|
||||
|
Loading…
Reference in New Issue
Block a user