Skip to content

Commit

Permalink
feat: rebase sdoc api
Browse files Browse the repository at this point in the history
  • Loading branch information
YangGuoXuan-0503 committed Aug 15, 2023
1 parent c5dd3a1 commit f45f98c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion seahub/seadoc/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)
Expand Down Expand Up @@ -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
})

3 changes: 2 additions & 1 deletion seahub/seadoc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -28,4 +28,5 @@
re_path(r'^revisions/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocRevisions.as_view(), name='seadoc_revisions'),
re_path(r'^file/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocFileView.as_view(), name='seadoc_file_view'),
re_path(r'^dir/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocDirView.as_view(), name='seadoc_dir_view'),
re_path(r'^(?P<repo_id>[-0-9a-f]{36})/file/history/$', SdocFileHistory.as_view(), name='seadoc_file_history'),
]

0 comments on commit f45f98c

Please sign in to comment.