mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 18:03:48 +00:00
[download zip] improvement, bugfix
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
{% if not traffic_over_limit %}
|
{% 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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for dirent in dir_list %}
|
{% 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 class="alc"><img src="{{ MEDIA_URL }}img/folder-24.png" alt="{% trans "Directory icon"%}" /></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}&mode={{mode}}" class="normal">{{ dirent.obj_name }}</a>
|
<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>{{ dirent.last_modified|translate_seahub_time }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if not traffic_over_limit %}
|
{% 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' %}" />
|
<img src="{{MEDIA_URL}}img/download.png" alt="{% trans 'Download' %}" />
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -190,31 +190,29 @@ var share_link_token = '{{token}}';
|
|||||||
var file_server_root = '{{FILE_SERVER_ROOT}}';
|
var file_server_root = '{{FILE_SERVER_ROOT}}';
|
||||||
|
|
||||||
$('.shared-dir-zip, .download-dir').click(function (e) {
|
$('.shared-dir-zip, .download-dir').click(function (e) {
|
||||||
var cur_download_dir_path,
|
var cur_download_dir_path;
|
||||||
cur_download_dir_name,
|
var interval,
|
||||||
zip_token;
|
zip_token,
|
||||||
|
queryZipProgress;
|
||||||
|
var packagingTip = "{% trans "Packaging..." %}";
|
||||||
|
var $tip = $('<p></p>');
|
||||||
|
|
||||||
var target = e.target || event.srcElement;
|
if ($(this).hasClass("shared-dir-zip")) {
|
||||||
|
|
||||||
if ($(target).hasClass("shared-dir-zip")) {
|
|
||||||
cur_download_dir_path = cur_path;
|
cur_download_dir_path = cur_path;
|
||||||
} else {
|
} else {
|
||||||
cur_download_dir_name = $(target).closest('a').attr('data-name');
|
cur_download_dir_path = cur_path + $(this).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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryZipProgress = function() {
|
queryZipProgress = function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{% url 'api-v2.1-query-zip-progress' %}' + '?token=' + zip_token,
|
url: '{% url 'api-v2.1-query-zip-progress' %}' + '?token=' + zip_token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
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']) {
|
if (data['total'] == data['zipped']) {
|
||||||
|
setTimeout(function() { $.modal.close(); }, 500);
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
location.href = file_server_root + 'zip/' + zip_token;
|
location.href = file_server_root + 'zip/' + zip_token;
|
||||||
}
|
}
|
||||||
@@ -232,10 +230,12 @@ $('.shared-dir-zip, .download-dir').click(function (e) {
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{% url 'api-v2.1-share-link-zip-task' %}' + '?share_link_token=' + share_link_token + '&path=' + encodeURIComponent(cur_download_dir_path),
|
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,
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
zip_token = data['zip_token'];
|
zip_token = data['zip_token'];
|
||||||
|
$tip.html(packagingTip).modal();
|
||||||
|
$('#simplemodal-container').css({'width':'auto'});
|
||||||
queryZipProgress();
|
queryZipProgress();
|
||||||
interval = setInterval(queryZipProgress, 1000);
|
interval = setInterval(queryZipProgress, 1000);
|
||||||
},
|
},
|
||||||
@@ -247,6 +247,8 @@ $('.shared-dir-zip, .download-dir').click(function (e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if not repo.encrypted and ENABLE_THUMBNAIL %}
|
{% if not repo.encrypted and ENABLE_THUMBNAIL %}
|
||||||
|
@@ -810,18 +810,34 @@ define([
|
|||||||
var dirents = this.dir;
|
var dirents = this.dir;
|
||||||
var parent_dir = dirents.path;
|
var parent_dir = dirents.path;
|
||||||
var selected_dirents = dirents.where({'selected':true});
|
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 selected_names = [];
|
||||||
var interval;
|
var interval;
|
||||||
var zip_token;
|
var zip_token;
|
||||||
|
var packagingTip = gettext("Packaging...");
|
||||||
|
var $tip = $('<p></p>');
|
||||||
var queryZipProgress = function() {
|
var queryZipProgress = function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
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']) {
|
if (data['total'] == data['zipped']) {
|
||||||
|
setTimeout(function() { $.modal.close(); }, 500);
|
||||||
clearInterval(interval);
|
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) {
|
||||||
@@ -830,28 +846,21 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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_dirents).each(function() {
|
||||||
selected_names.push(this.get('obj_name'));
|
selected_names.push(this.get('obj_name'));
|
||||||
});
|
});
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: Common.getUrl({name: 'zip_task', repo_id: dirents.repo_id}),
|
url: Common.getUrl({name: 'zip_task', repo_id: dirents.repo_id}),
|
||||||
data: {
|
data: {
|
||||||
'parent_dir': parent_dir,
|
'parent_dir': parent_dir,
|
||||||
'dirents': selected_names
|
'dirents': selected_names
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
|
||||||
traditional: true,
|
traditional: true,
|
||||||
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
zip_token = data['zip_token'];
|
zip_token = data['zip_token'];
|
||||||
|
$tip.html(packagingTip).modal();
|
||||||
|
$('#simplemodal-container').css({'width':'auto'});
|
||||||
queryZipProgress();
|
queryZipProgress();
|
||||||
interval = setInterval(queryZipProgress, 1000);
|
interval = setInterval(queryZipProgress, 1000);
|
||||||
},
|
},
|
||||||
|
@@ -124,15 +124,23 @@ define([
|
|||||||
var obj_name = this.model.get('obj_name');
|
var obj_name = this.model.get('obj_name');
|
||||||
var interval;
|
var interval;
|
||||||
var zip_token;
|
var zip_token;
|
||||||
|
var packagingTip = gettext("Packaging...");
|
||||||
|
var $tip = $('<p></p>');
|
||||||
var queryZipProgress = function() {
|
var queryZipProgress = function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
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']) {
|
if (data['total'] == data['zipped']) {
|
||||||
|
setTimeout(function() { $.modal.close(); }, 500);
|
||||||
clearInterval(interval);
|
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) {
|
||||||
@@ -146,10 +154,16 @@ define([
|
|||||||
url: Common.getUrl({
|
url: Common.getUrl({
|
||||||
name: 'zip_task',
|
name: 'zip_task',
|
||||||
repo_id: dir.repo_id
|
repo_id: dir.repo_id
|
||||||
}) + '?parent_dir=' + encodeURIComponent(dir.path) + '&dirents=' + encodeURIComponent(obj_name),
|
}),
|
||||||
|
data: {
|
||||||
|
'parent_dir': dir.path,
|
||||||
|
'dirents': obj_name
|
||||||
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
zip_token = data['zip_token'];
|
zip_token = data['zip_token'];
|
||||||
|
$tip.html(packagingTip).modal();
|
||||||
|
$('#simplemodal-container').css({'width':'auto'});
|
||||||
queryZipProgress();
|
queryZipProgress();
|
||||||
interval = setInterval(queryZipProgress, 1000);
|
interval = setInterval(queryZipProgress, 1000);
|
||||||
},
|
},
|
||||||
|
@@ -97,7 +97,6 @@ define([
|
|||||||
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
|
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
|
||||||
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
|
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_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_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/';
|
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user