mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 17:02:47 +00:00
[download zip] improvement, bugfix
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
{% endif %}
|
||||
</a>
|
||||
{% if not traffic_over_limit %}
|
||||
<a href="#" class="obv-btn vam shared-dir-zip" data-name="{{ dirent.obj_name }}">{% trans "ZIP"%}</a>
|
||||
<a href="#" class="obv-btn vam shared-dir-zip">{% trans "ZIP"%}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
<tbody>
|
||||
{% for dirent in dir_list %}
|
||||
<tr data-name="{{dirent.obj_name}}" >
|
||||
<tr>
|
||||
<td class="alc"><img src="{{ MEDIA_URL }}img/folder-24.png" alt="{% trans "Directory icon"%}" /></td>
|
||||
<td>
|
||||
<a href="?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}&mode={{mode}}" class="normal">{{ dirent.obj_name }}</a>
|
||||
@@ -69,7 +69,7 @@
|
||||
<td>{{ dirent.last_modified|translate_seahub_time }}</td>
|
||||
<td>
|
||||
{% if not traffic_over_limit %}
|
||||
<a class="op-icon vh download-dir" data-name="{{ dirent.obj_name }}" href="#" aria-label="{% trans 'Download' %}">
|
||||
<a class="op-icon vh download-dir" data-name="{{ dirent.obj_name }}" href="#" title="{% trans 'Download' %}" aria-label="{% trans 'Download' %}">
|
||||
<img src="{{MEDIA_URL}}img/download.png" alt="{% trans 'Download' %}" />
|
||||
</a>
|
||||
{% endif %}
|
||||
@@ -190,36 +190,34 @@ var share_link_token = '{{token}}';
|
||||
var file_server_root = '{{FILE_SERVER_ROOT}}';
|
||||
|
||||
$('.shared-dir-zip, .download-dir').click(function (e) {
|
||||
var cur_download_dir_path,
|
||||
cur_download_dir_name,
|
||||
zip_token;
|
||||
var cur_download_dir_path;
|
||||
var interval,
|
||||
zip_token,
|
||||
queryZipProgress;
|
||||
var packagingTip = "{% trans "Packaging..." %}";
|
||||
var $tip = $('<p></p>');
|
||||
|
||||
var target = e.target || event.srcElement;
|
||||
|
||||
if ($(target).hasClass("shared-dir-zip")) {
|
||||
if ($(this).hasClass("shared-dir-zip")) {
|
||||
cur_download_dir_path = cur_path;
|
||||
} else {
|
||||
cur_download_dir_name = $(target).closest('a').attr('data-name');
|
||||
if (cur_path.lastIndexOf('/') != cur_path.length - 1) {
|
||||
// cur_path NOT end with '/'
|
||||
cur_download_dir_path = cur_path.substring(0, cur_path.lastIndexOf('/')) + '/' + cur_download_dir_name;
|
||||
} else {
|
||||
cur_download_dir_path = cur_path + cur_download_dir_name;
|
||||
}
|
||||
cur_download_dir_path = cur_path + $(this).attr('data-name');
|
||||
}
|
||||
|
||||
var queryZipProgress = function() {
|
||||
queryZipProgress = function() {
|
||||
$.ajax({
|
||||
url: '{% url 'api-v2.1-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 = file_server_root + 'zip/' + zip_token;
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
error: function(xhr) {
|
||||
if (xhr.responseText) {
|
||||
feedback($.parseJSON(xhr.responseText).error_msg, 'error');
|
||||
} else {
|
||||
@@ -232,14 +230,16 @@ $('.shared-dir-zip, .download-dir').click(function (e) {
|
||||
|
||||
$.ajax({
|
||||
url: '{% url 'api-v2.1-share-link-zip-task' %}' + '?share_link_token=' + share_link_token + '&path=' + encodeURIComponent(cur_download_dir_path),
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
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) {
|
||||
if (xhr.responseText) {
|
||||
feedback($.parseJSON(xhr.responseText).error_msg, 'error');
|
||||
} else {
|
||||
@@ -247,6 +247,8 @@ $('.shared-dir-zip, .download-dir').click(function (e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
{% if not repo.encrypted and ENABLE_THUMBNAIL %}
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
|
@@ -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/';
|
||||
|
||||
|
Reference in New Issue
Block a user