1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 04:10:47 +00:00

if close query zip window then stop zip process

This commit is contained in:
ilearnit
2018-03-21 18:16:02 +08:00
parent 9b16ba0e8f
commit d29ab8a9ac
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
# Copyright (c) 2012-2016 Seafile Ltd.
import logging
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.utils import api_error
from seaserv import seafile_api
logger = logging.getLogger(__name__)
class CancelZipTaskView(APIView):
throttle_classes = (UserRateThrottle, )
def post(self, request, format=None):
""" stop progress when download dir/multi.
Permission checking:
"""
token = request.POST.get('token', None)
if not token:
error_msg = 'token invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
process = seafile_api.cancel_zip_task(token)
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()

View File

@@ -44,6 +44,7 @@ from seahub.api2.endpoints.repo_set_password import RepoSetPassword
from seahub.api2.endpoints.zip_task import ZipTaskView
from seahub.api2.endpoints.share_link_zip_task import ShareLinkZipTaskView
from seahub.api2.endpoints.query_zip_progress import QueryZipProgressView
from seahub.api2.endpoints.cancel_zip_task import CancelZipTaskView
from seahub.api2.endpoints.copy_move_task import CopyMoveTaskView
from seahub.api2.endpoints.query_copy_move_progress import QueryCopyMoveProgressView
from seahub.api2.endpoints.invitations import InvitationsView, InvitationsBatchView
@@ -249,6 +250,7 @@ urlpatterns = [
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/cancel-zip-task/$', CancelZipTaskView.as_view(), name='api-v2.1-cancel-zip-task'),
url(r'^api/v2.1/copy-move-task/$', CopyMoveTaskView.as_view(), name='api-v2.1-copy-move-task'),
url(r'^api/v2.1/query-copy-move-progress/$', QueryCopyMoveProgressView.as_view(), name='api-v2.1-query-copy-move-progress'),
url(r'^api/v2.1/notifications/$', NotificationsView.as_view(), name='api-v2.1-notifications'),

View File

@@ -80,6 +80,7 @@ define([
case 'download_dir_zip_url': return fileServerRoot + 'zip/' + options.zip_token;
case 'zip_task': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/zip-task/';
case 'query_zip_progress': return siteRoot + 'api/v2.1/query-zip-progress/';
case 'cancel_zip_task': return siteRoot + 'api/v2.1/cancel-zip-task/';
case 'copy_move_task': return siteRoot + 'api/v2.1/copy-move-task/';
case 'query_copy_move_progress': return siteRoot + 'api/v2.1/query-copy-move-progress/';
case 'rename_dir': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/dir/';
@@ -1057,6 +1058,18 @@ define([
});
};
var cancelZipTask = function(){
$.ajax({
url: _this.getUrl({name: 'cancel_zip_task'}) + '?token=' + zip_token,
success: function(date) {
clearInterval(interval);
},
error: function(xhr) {
_this.ajaxErrorHandler(xhr);
}
});
};
$.ajax({
url: _this.getUrl({
name: 'zip_task',
@@ -1072,6 +1085,7 @@ define([
zip_token = data['zip_token'];
$tip.html(packagingTip).modal();
$('#simplemodal-container').css({'width':'auto'});
$('.simplemodal-close').click(function(){ cancelZipTask(); });
queryZipProgress();
interval = setInterval(queryZipProgress, 1000);
},