1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 22:01:06 +00:00

[download zip] improvement, bugfix

This commit is contained in:
llj
2016-07-04 14:46:49 +08:00
parent 6dca56e9d5
commit f9500c4f61
4 changed files with 65 additions and 41 deletions

View File

@@ -810,52 +810,61 @@ define([
var dirents = this.dir;
var parent_dir = dirents.path;
var selected_dirents = dirents.where({'selected':true});
// select 1 item, and it is a file
if (selected_dirents.length == 1 &&
selected_dirents[0].get('is_file')) {
location.href = selected_dirents[0].getDownloadUrl();
return;
}
var selected_names = [];
var interval;
var zip_token;
var packagingTip = gettext("Packaging...");
var $tip = $('<p></p>');
var queryZipProgress = function() {
$.ajax({
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
dataType: 'json',
cache: false,
success: function (data) {
success: function(data) {
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(2) + '%';
$tip.html(packagingTip + ' ' + progress);
if (data['total'] == data['zipped']) {
setTimeout(function() { $.modal.close(); }, 500);
clearInterval(interval);
location.href = Common.getUrl({name: 'download_dir_zip_url', zip_token: zip_token});
location.href = Common.getUrl({
name: 'download_dir_zip_url',
zip_token: zip_token
});
}
},
error: function (xhr) {
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
clearInterval(interval);
}
});
};
if (selected_dirents.length == 1 && selected_dirents[0].get('is_file')) {
// only select one file
var file_path = parent_dir + '/' + selected_dirents[0].get('obj_name');
location.href = Common.getUrl({name: 'get_file_download_url', repo_id: dirents.repo_id, file_path: encodeURIComponent(file_path)});
return false
}
$(selected_dirents).each(function() {
selected_names.push(this.get('obj_name'));
});
$.ajax({
url: Common.getUrl({name: 'zip_task', repo_id: dirents.repo_id}),
data: {
'parent_dir': parent_dir,
'dirents': selected_names
},
dataType: 'json',
traditional: true,
dataType: 'json',
success: function(data) {
zip_token = data['zip_token'];
$tip.html(packagingTip).modal();
$('#simplemodal-container').css({'width':'auto'});
queryZipProgress();
interval = setInterval(queryZipProgress, 1000);
},
error: function (xhr) {
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});

View File

@@ -124,18 +124,26 @@ define([
var obj_name = this.model.get('obj_name');
var interval;
var zip_token;
var packagingTip = gettext("Packaging...");
var $tip = $('<p></p>');
var queryZipProgress = function() {
$.ajax({
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
dataType: 'json',
cache: false,
success: function (data) {
success: function(data) {
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(2) + '%';
$tip.html(packagingTip + ' ' + progress);
if (data['total'] == data['zipped']) {
setTimeout(function() { $.modal.close(); }, 500);
clearInterval(interval);
location.href = Common.getUrl({name: 'download_dir_zip_url', zip_token: zip_token});
location.href = Common.getUrl({
name: 'download_dir_zip_url',
zip_token: zip_token
});
}
},
error: function (xhr) {
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
clearInterval(interval);
}
@@ -146,14 +154,20 @@ define([
url: Common.getUrl({
name: 'zip_task',
repo_id: dir.repo_id
}) + '?parent_dir=' + encodeURIComponent(dir.path) + '&dirents=' + encodeURIComponent(obj_name),
}),
data: {
'parent_dir': dir.path,
'dirents': obj_name
},
dataType: 'json',
success: function(data) {
zip_token = data['zip_token'];
$tip.html(packagingTip).modal();
$('#simplemodal-container').css({'width':'auto'});
queryZipProgress();
interval = setInterval(queryZipProgress, 1000);
},
error: function (xhr) {
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});

View File

@@ -97,7 +97,6 @@ define([
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/';
case 'get_file_download_url': return siteRoot + 'lib/' + options.repo_id + '/file' + options.file_path + '?dl=1';
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/';