Merge pull request #9362 from jumpserver/pr@dev@perf_applet_upload

perf: 优化 applet 上传报错
pull/9365/head
老广 2 years ago committed by GitHub
commit e5ca8c5b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -126,7 +126,9 @@ function csrfSafeMethod(method) {
function setAjaxCSRFToken() {
let prefix = getCookie('SESSION_COOKIE_NAME_PREFIX');
if (!prefix || [`""`, `''`].indexOf(prefix) > -1) { prefix = ''; }
if (!prefix || [`""`, `''`].indexOf(prefix) > -1) {
prefix = '';
}
var csrftoken = getCookie(`${prefix}csrftoken`);
var sessionid = getCookie(`${prefix}sessionid`);
@ -469,28 +471,7 @@ function parseTableFilter(value) {
var jumpserver = {};
jumpserver.checked = false;
jumpserver.selected = {};
jumpserver.language = {
processing: gettext('Loading') + '...',
search: gettext('Search'),
select: {
rows: {
_: gettext("Selected item %d"),
0: ""
}
},
lengthMenu: gettext("Per page _MENU_"),
info: gettext('Displays the results of items _START_ to _END_; A total of _TOTAL_ entries'),
infoFiltered: "",
infoEmpty: "",
zeroRecords: gettext("No match"),
emptyTable: gettext('No record'),
paginate: {
first: "«",
previous: "",
next: "",
last: "»"
}
};
jumpserver.language = {};
function setDataTablePagerLength(num) {
$.fn.DataTable.ext.pager.numbers_length = num;
@ -730,8 +711,7 @@ jumpserver.initServerSideDataTable = function (options) {
if (select.style === 'multi') {
table.selected.push(row.id);
table.selected_rows.push(row);
}
else{
} else {
table.selected = [row.id];
table.selected_rows = [row];
}
@ -915,14 +895,6 @@ var rules_short_map_id = {
'special': 'id_security_password_special_char'
};
var rules_id_map_label = {
'id_security_password_min_length': gettext('Password minimum length {N} bits'),
'id_security_password_upper_case': gettext('Must contain capital letters'),
'id_security_password_lower_case': gettext('Must contain lowercase letters'),
'id_security_password_number': gettext('Must contain numeric characters'),
'id_security_password_special_char': gettext('Must contain special characters')
};
function getRuleLabel(rule) {
var label = '';
if (rule.key === rules_short_map_id['min']) {
@ -1030,7 +1002,6 @@ function initPopover($container, $progress, $idPassword, $el, password_check_rul
}
function rootNodeAddDom(ztree, callback) {
var refreshIcon = "<a id='tree-refresh'><i class='fa fa-refresh'></i></a>";
var rootNode = ztree.getNodes()[0];
@ -1048,146 +1019,6 @@ function rootNodeAddDom(ztree, callback) {
})
}
function APIExportCSV(props) {
/*
{
listUrl:
objectsId:
template:
table:
params:
}
*/
var _listUrl = props.listUrl;
var _objectsId = props.objectsId;
var _template = props.template;
var _table = props.table;
var _params = props.params || {};
var tableParams = _table.ajax.params();
var exportUrl = setUrlParam(_listUrl, 'format', 'csv');
if (_template) {
exportUrl = setUrlParam(exportUrl, 'template', _template)
}
for (var k in tableParams) {
if (datatableInternalParams.includes(k)) {
continue
}
if (!tableParams[k]) {
continue
}
exportUrl = setUrlParam(exportUrl, k, tableParams[k])
}
for (var k in _params) {
exportUrl = setUrlParam(exportUrl, k, tableParams[k])
}
if (!_objectsId) {
console.log(exportUrl);
window.open(exportUrl);
return
}
requestApi({
url: '/api/v1/common/resources/cache/',
data: JSON.stringify({resources: _objectsId}),
method: "POST",
flash_message: false,
success: function (data) {
exportUrl = setUrlParam(exportUrl, 'spm', data.spm);
console.log(exportUrl);
window.open(exportUrl);
},
failed: function () {
toastr.error(gettext('Export failed'));
}
});
}
function APIExportData(props) {
props = props || {};
$.ajax({
url: '/api/common/v1/resources/cache/',
type: props.method || "POST",
data: props.body,
contentType: props.content_type || "application/json; charset=utf-8",
dataType: props.data_type || "json",
success: function (data) {
var export_url = props.success_url;
var params = props.params || {};
params['format'] = props.format;
params['spm'] = data.spm;
for (var k in params) {
export_url = setUrlParam(export_url, k, params[k])
}
window.open(export_url);
},
error: function () {
toastr.error(gettext('Export failed'));
}
})
}
function APIImportData(props) {
props = props || {};
$.ajax({
url: props.url,
type: props.method || "POST",
processData: false,
data: props.body,
contentType: props.content_type || 'text/csv',
success: function (data) {
if (props.method === 'POST') {
$('#created_failed').html('');
$('#created_failed_detail').html('');
$('#success_created').html(gettext("Import Success"));
$('#success_created_detail').html("Count" + ": " + data.length);
} else {
$('#updated_failed').html('');
$('#updated_failed_detail').html('');
$('#success_updated').html(gettext("Update Success"));
$('#success_updated_detail').html(gettext("Count") + ": " + data.length);
}
props.data_table.ajax.reload()
},
error: function (error) {
var data = error.responseJSON;
console.log(data);
if (data instanceof Array) {
var html = '';
var li = '';
var err = '';
$.each(data, function (index, item) {
err = '';
for (var prop in item) {
err += prop + ": " + item[prop][0] + " "
}
if (err) {
li = "<li>" + "Line " + (++index) + ". " + err + "</li>";
html += li
}
});
html = "<ul>" + html + "</ul>"
} else {
html = error.responseText
}
if (props.method === 'POST') {
$('#success_created').html('');
$('#success_created_detail').html('');
$('#created_failed').html(gettext("Import failed"));
$('#created_failed_detail').html(html);
} else {
$('#success_updated').html('');
$('#success_updated_detail').html('');
$('#updated_failed').html(gettext("Update failed"));
$('#updated_failed_detail').html(html);
}
}
})
}
function htmlEscape(d) {
return typeof d === 'string' ?
d.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') :
@ -1329,7 +1160,6 @@ function readFile(ref) {
}
function select2AjaxInit(option) {
/*
{
@ -1385,9 +1215,11 @@ function usersSelect2Init(selector, url, disabledData) {
if (!url) {
url = '/api/v1/users/users/'
}
function displayFormat(v) {
return v.name + '(' + v.username + ')';
}
var option = {
url: url,
selector: selector,
@ -1402,9 +1234,11 @@ function nodesSelect2Init(selector, url, disabledData) {
if (!url) {
url = '/api/v1/assets/nodes/'
}
function displayFormat(v) {
return v.full_value;
}
var option = {
url: url,
selector: selector,
@ -1423,8 +1257,7 @@ function getUserLang(){
let userLangEN = document.cookie.indexOf('django_language=en');
if (userLangEN === -1) {
return 'zh-CN'
}
else{
} else {
return 'en-US'
}
}
@ -1460,8 +1293,7 @@ function initDateRangePicker(selector, options) {
};
if (getUserLang() === 'zh-CN') {
defaultOption.locale = zhLocale;
}
else{
} else {
// en-US
defaultOption.locale = enLocale;
}
@ -1470,7 +1302,9 @@ function initDateRangePicker(selector, options) {
}
function reloadPage() {
setTimeout( function () {window.location.reload();}, 300);
setTimeout(function () {
window.location.reload();
}, 300);
}
function isEmptyObject(obj) {

@ -7,14 +7,13 @@
<link href="{% static 'css/plugins/sweetalert/sweetalert.css' %}" rel="stylesheet">
<link href="{% static 'css/style.css' %}" rel="stylesheet">
<link href="{% static 'css/plugins/vaildator/jquery.validator.css' %}" rel="stylesheet">
<link href="{% static 'css/plugins/datatables/datatables.min.css' %}" rel="stylesheet">
<link href="{% static 'css/plugins/select2/select2.min.css' %}" rel="stylesheet">
<!-- scripts -->
<script src="{% static 'js/jquery-3.6.1.min.js' %}"></script>
<script src="{% static 'js/plugins/sweetalert/sweetalert.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/plugins/datatables/datatables.min.js' %}"></script>
<script src="{% url 'javascript-catalog' %}"></script>
<link href="{% static 'css/plugins/select2/select2.min.css' %}" rel="stylesheet">
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<style>
:root {
--primary-color: #1ab394;

@ -7,6 +7,7 @@ from django.conf import settings
from django.core.files.storage import default_storage
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.request import Request
@ -41,10 +42,13 @@ class DownloadUploadMixin:
if os.path.exists(extract_to):
shutil.rmtree(extract_to)
try:
with zipfile.ZipFile(path) as zp:
if zp.testzip() is not None:
return Response({'msg': 'Invalid Zip file'}, status=400)
raise ValidationError({'error': _('Invalid zip file')})
zp.extractall(extract_to)
except RuntimeError as e:
raise ValidationError({'error': _('Invalid zip file') + ': {}'.format(e)})
tmp_dir = os.path.join(extract_to, file.name.replace('.zip', ''))
manifest = Applet.validate_pkg(tmp_dir)

@ -78,7 +78,7 @@ class Applet(JMSBaseModel):
for name in files:
path = os.path.join(d, name)
if not os.path.exists(path):
raise ValidationError({'error': 'Missing file {}'.format(path)})
raise ValidationError({'error': _('Applet pkg not valid, Missing file {}').format(name)})
with open(os.path.join(d, 'manifest.yml')) as f:
manifest = yaml.safe_load(f)

Loading…
Cancel
Save