diff --git a/seahub/seadoc/apis.py b/seahub/seadoc/apis.py index 9fbd00eb4fe..a3e98d0ce33 100644 --- a/seahub/seadoc/apis.py +++ b/seahub/seadoc/apis.py @@ -19,7 +19,7 @@ from django.db import transaction from django.urls import reverse -from seaserv import seafile_api, check_quota +from seaserv import seafile_api, check_quota, seafserv_threaded_rpc from seahub.views import check_folder_permission from seahub.api2.authentication import TokenAuthentication, SdocJWTTokenAuthentication @@ -44,6 +44,7 @@ from seahub.base.models import FileComment from seahub.constants import PERMISSION_READ_WRITE, PERMISSION_INVISIBLE from seahub.seadoc.sdoc_server_api import SdocServerAPI +from seahub.api2.views import get_repo_file logger = logging.getLogger(__name__) @@ -1438,3 +1439,34 @@ def get(self, request, file_uuid): file_list.sort(key=lambda x: x['name'].lower()) dentrys = dir_list + file_list return Response(dentrys) + + +class SdocFileHistory(APIView): + # authentication_classes = (SdocJWTTokenAuthentication, TokenAuthentication) + # permission_classes = (IsAuthenticated,) + # throttle_classes = (UserRateThrottle, ) + print('******************') + + def get(self, request, repo_id, format=None): + username = request.user.username + path = request.GET.get('p', None) + if path is None: + return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.') + + file_name = os.path.basename(path) + file_version = request.GET.get('file_version', None) + + if not file_version: + return api_error(status.HTTP_400_BAD_REQUEST, 'File version is missing.') + + token = seafile_api.get_fileserver_access_token(repo_id, + file_version, 'download', username) + if not token: + error_msg = 'file %s not found.' % file_version + return api_error(status.HTTP_404_NOT_FOUND, error_msg) + download_url = gen_inner_file_get_url(token, file_name) + resp = requests.get(download_url) + return Response({ + 'content': resp.content + }) + diff --git a/seahub/seadoc/urls.py b/seahub/seadoc/urls.py index 77d979b2458..7976742177d 100644 --- a/seahub/seadoc/urls.py +++ b/seahub/seadoc/urls.py @@ -2,7 +2,7 @@ from .apis import SeadocAccessToken, SeadocUploadLink, SeadocDownloadLink, SeadocRevisionDownloadLinks, SeadocUploadFile, \ SeadocUploadImage, SeadocDownloadImage, SeadocCopyHistoryFile, SeadocHistory, SeadocDrafts, SeadocMaskAsDraft, \ SeadocCommentsView, SeadocCommentView, SeadocStartRevise, SeadocPublishRevision, SeadocRevisionsCount, SeadocRevisions, \ - SeadocCommentRepliesView, SeadocCommentReplyView, SeadocFileView, SeadocDirView + SeadocCommentRepliesView, SeadocCommentReplyView, SeadocFileView, SeadocDirView, SdocFileHistory # api/v2.1/seadoc/ @@ -28,4 +28,5 @@ re_path(r'^revisions/(?P[-0-9a-f]{36})/$', SeadocRevisions.as_view(), name='seadoc_revisions'), re_path(r'^file/(?P[-0-9a-f]{36})/$', SeadocFileView.as_view(), name='seadoc_file_view'), re_path(r'^dir/(?P[-0-9a-f]{36})/$', SeadocDirView.as_view(), name='seadoc_dir_view'), + re_path(r'^(?P[-0-9a-f]{36})/file/history/$', SdocFileHistory.as_view(), name='seadoc_file_history'), ]