1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 15:38:15 +00:00

update get file uploaded bytes

This commit is contained in:
lian
2016-08-31 14:34:08 +08:00
committed by lian
parent 06bc49d17b
commit 7a8eb038e2
6 changed files with 74 additions and 29 deletions

View File

@@ -0,0 +1,68 @@
# Copyright (c) 2012-2016 Seafile Ltd.
import logging
import posixpath
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from seaserv import seafile_api
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.utils import api_error
from seahub.views import check_folder_permission
logger = logging.getLogger(__name__)
json_content_type = 'application/json; charset=utf-8'
class RepoFileUploadedBytesView(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle,)
def get(self, request, repo_id):
""" For resumable fileupload
Permission checking:
1. login user.
"""
# argument check
parent_dir = request.GET.get('parent_dir', None)
if not parent_dir:
error_msg = 'parent_dir invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_name = request.GET.get('file_name')
if not file_name:
error_msg = 'file_name invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# resource check
repo = seafile_api.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)
if not seafile_api.get_dir_id_by_path(repo_id, parent_dir):
error_msg = 'Folder %s not found.' % parent_dir
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# permission check
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
file_path = posixpath.join(parent_dir, file_name)
try:
uploadedBytes = seafile_api.get_upload_tmp_file_offset(repo_id, file_path)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({"uploadedBytes": uploadedBytes})

View File

@@ -165,7 +165,7 @@ form.fileupload({
file.size && file.size > block_size) {
form.fileupload('option', 'maxChunkSize', block_size);
$.ajax({
url: '{% url 'get_file_uploaded_bytes' uploadlink.repo_id %}',
url: '{% url 'api-v2.1-repo-file-uploaded-bytes' uploadlink.repo_id %}',
data: {
'parent_dir': "{{path|escapejs}}",
'file_name': file.name

View File

@@ -37,6 +37,7 @@ from seahub.api2.endpoints.invitations import InvitationsView
from seahub.api2.endpoints.invitation import InvitationView
from seahub.api2.endpoints.notifications import NotificationsView, NotificationView
from seahub.api2.endpoints.user_enabled_modules import UserEnabledModulesView
from seahub.api2.endpoints.repo_file_uploaded_bytes import RepoFileUploadedBytesView
from seahub.api2.endpoints.admin.login import Login
from seahub.api2.endpoints.admin.file_audit import FileAudit
@@ -144,7 +145,6 @@ urlpatterns = patterns(
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/current_commit/$', get_current_commit, name='get_current_commit'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/history/changes/$', repo_history_changes, name='repo_history_changes'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/encrypted_file/(?P<file_id>[0-9a-f]{40})/download/$', download_enc_file, name='download_enc_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/get-file-uploaded-bytes/$', get_file_uploaded_bytes, name='get_file_uploaded_bytes'),
url(r'^ajax/u/d/(?P<token>[-0-9a-f]{10})/upload/$', get_file_upload_url_ul, name='get_file_upload_url_ul'),
url(r'^ajax/group/(?P<group_id>\d+)/repos/$', get_unenc_group_repos, name='get_group_repos'),
url(r'^ajax/group/(?P<group_id>\d+)/members/import/$', ajax_group_members_import, name='ajax_group_members_import'),
@@ -179,6 +179,7 @@ urlpatterns = patterns(
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/file/$', FileView.as_view(), name='api-v2.1-file-view'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/dirents/download-link/$', DirentsDownloadLinkView.as_view(), name='api-v2.1-dirents-download-link-view'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/zip-task/$', ZipTaskView.as_view(), name='api-v2.1-zip-task'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/file-uploaded-bytes/$', RepoFileUploadedBytesView.as_view(), name='api-v2.1-repo-file-uploaded-bytes'),
url(r'^api/v2.1/share-link-zip-task/$', ShareLinkZipTaskView.as_view(), name='api-v2.1-share-link-zip-task'),
url(r'^api/v2.1/query-zip-progress/$', QueryZipProgressView.as_view(), name='api-v2.1-query-zip-progress'),
url(r'^api/v2.1/copy-move-task/$', CopyMoveTaskView.as_view(), name='api-v2.1-copy-move-task'),

View File

@@ -1035,31 +1035,6 @@ def get_group_repos(request, groups):
group_repos.append(r)
return group_repos
def get_file_uploaded_bytes(request, repo_id):
"""
For resumable fileupload
"""
content_type = 'application/json; charset=utf-8'
parent_dir = request.GET.get('parent_dir')
file_name = request.GET.get('file_name')
if not parent_dir or not file_name:
err_msg = _(u'Argument missing')
return HttpResponse(json.dumps({"error": err_msg}), status=400,
content_type=content_type)
repo = get_repo(repo_id)
if not repo:
err_msg = _(u'Library does not exist')
return HttpResponse(json.dumps({"error": err_msg}), status=400,
content_type=content_type)
file_path = os.path.join(parent_dir, file_name)
uploadedBytes = seafile_api.get_upload_tmp_file_offset(repo_id, file_path)
return HttpResponse(json.dumps({"uploadedBytes": uploadedBytes}),
content_type=content_type)
def get_file_upload_url_ul(request, token):
"""Get file upload url in dir upload link.

View File

@@ -183,7 +183,7 @@ define([
popup.fileupload('option', 'maxChunkSize', block_size);
$.ajax({
url: Common.getUrl({
name: 'get_file_uploaded_bytes',
name: 'repo_file_uploaded_bytes',
repo_id: dirents.repo_id
}),
data: {

View File

@@ -94,7 +94,6 @@ define([
case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/';
case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/';
case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/';
case 'get_file_uploaded_bytes': return siteRoot + 'ajax/repo/' + options.repo_id + '/get-file-uploaded-bytes/';
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
// Repos
@@ -118,6 +117,8 @@ define([
case 'repo_upload_link': return siteRoot + 'api2/repos/' + options.repo_id + '/upload-link/';
case 'repo_update_link': return siteRoot + 'api2/repos/' + options.repo_id + '/update-link/';
case 'repo_file_uploaded_bytes': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/file-uploaded-bytes/';
// Share admin
case 'share_admin_repos': return siteRoot + 'api/v2.1/shared-repos/';
case 'share_admin_repo': return siteRoot + 'api/v2.1/shared-repos/' + options.repo_id + '/';