Commit 03c5cf92 authored by Medicean's avatar Medicean

fix jsp probedb bug

parent 1a30ec6e
......@@ -6,6 +6,7 @@ const LANG = antSword['language']['database'];
const LANG_T = antSword['language']['toastr'];
const dialog = antSword.remote.dialog;
const fs = require('fs');
const Decodes = antSword.Decodes;
class JSP {
......@@ -69,17 +70,17 @@ class JSP {
case 'conn':
this.getDatabases(arr[1]);
break;
// 获取数据库表名
// 获取数据库表名
case 'database':
let _db = arr[1].split(':');
this.getTables(_db[0], Buffer.from(_db[1], 'base64').toString());
break;
// 获取表名字段
// 获取表名字段
case 'table':
let _tb = arr[1].split(':');
this.getColumns(_tb[0], Buffer.from(_tb[1], 'base64').toString(), Buffer.from(_tb[2], 'base64').toString());
break;
// 生成查询SQL语句
// 生成查询SQL语句
case 'column':
let _co = arr[1].split(':');
const db = Buffer.from(_co[1], 'base64').toString();
......@@ -728,12 +729,50 @@ class JSP {
});
}
parseResult(data) {
// 1.分割数组
const arr = data.split('\n');
// 2.判断数据
if (arr.length < 2) {
return toastr.error(LANG['result']['error']['parse'], LANG_T['error']);
};
// 3.行头
let header_arr = (arr[0]).replace(/,/g, '&#44;').split('\t|\t');
if (header_arr.length === 1) {
return toastr.warning(LANG['result']['error']['noresult'], LANG_T['warning']);
};
if (header_arr[header_arr.length - 1] === '\r') {
header_arr.pop();
};
arr.shift();
// 4.数据
let data_arr = [];
arr.map((_) => {
let _data = _.split('\t|\t');
for (let i = 0; i < _data.length; i++) {
let buff = Buffer.from(_data[i], "base64");
let encoding = Decodes.detectEncoding(buff, { defaultEncoding: "unknown" });
if (encoding == "unknown") {
encoding = this.dbconf['encode'] || '';
}
encoding = encoding != "" ? encoding : this.opt.core.__opts__['encode'];
let text = Decodes.decode(buff, encoding);
_data[i] = antSword.noxss(text);
}
data_arr.push(_data);
});
data_arr.pop();
return {
headers: header_arr,
datas: data_arr
}
}
// 更新SQL执行结果
updateResult(data) {
// 1.分割数组
const arr = data.split('\n');
// let arr = []; _arr.map((_) => { arr.push(antSword.noxss(_)); });
// console.log(_arr, arr); 2.判断数据
// 2.判断数据
if (arr.length < 2) {
return toastr.error(LANG['result']['error']['parse'], LANG_T['error']);
};
......@@ -750,6 +789,16 @@ class JSP {
let data_arr = [];
arr.map((_) => {
let _data = _.split('\t|\t');
for (let i = 0; i < _data.length; i++) {
let buff = new Buffer.from(_data[i], "base64");
let encoding = Decodes.detectEncoding(buff, { defaultEncoding: "unknown" });
if (encoding == "unknown") {
encoding = this.dbconf['encode'] || '';
}
encoding = encoding != "" ? encoding : this.opt.core.__opts__['encode'];
let text = Decodes.decode(buff, encoding);
_data[i] = antSword.noxss(text, false);
}
data_arr.push(_data);
});
data_arr.pop();
......@@ -795,7 +844,7 @@ class JSP {
.core
.__opts__
.ip}_${new Date()
.format("yyyyMMddhhmmss")}.csv`;
.format("yyyyMMddhhmmss")}.csv`;
dialog.showSaveDialog({
title: LANG['result']['dump']['title'],
defaultPath: filename
......
......@@ -100,7 +100,7 @@ class FileManager {
this.isWin = false;
} else {
// windows 盘符统一大写
info_path = `${info_path.substr(0,1).toUpperCase()}${info_path.substr(1)}`;
info_path = `${info_path.substr(0, 1).toUpperCase()}${info_path.substr(1)}`;
info_drive = info_drive.toUpperCase();
};
this.path = info_path;
......@@ -145,11 +145,11 @@ class FileManager {
let self = this;
if (self.isWin) { // 处理输入为 f:\ 这种情况
p = p.replace(/\\/g, '/');
p = p.substr(1, 2) == ":/" ? `${p.substr(0,1).toUpperCase()}${p.substr(1)}` : p;
p = p.substr(1, 2) == ":/" ? `${p.substr(0, 1).toUpperCase()}${p.substr(1)}` : p;
}
let path = this.changePath(p);
if (self.isWin) { // 处理输入为 f: 这种情况
path = path.substr(1, 2) == ":/" ? `${path.substr(0,1).toUpperCase()}${path.substr(1)}` : path;
path = path.substr(1, 2) == ":/" ? `${path.substr(0, 1).toUpperCase()}${path.substr(1)}` : path;
}
let cache;
......@@ -208,6 +208,8 @@ class FileManager {
this.cache.set(cache_tag, JSON.stringify(data));
}).catch((err) => {
toastr.error((err instanceof Object) ? JSON.stringify(err) : String(err), LANG_T['error']);
this.folder.cell.progressOff();
this.files.cell.progressOff();
})
// this.core.filemanager.dir({
......@@ -650,15 +652,15 @@ class FileManager {
fs.unlinkSync(filePath);
}
self.core.download(filePath, self.core.filemanager.download_file({
path: path
}), (_size) => {
// 计算进度百分比
down_size += _size;
let down_progress = parseInt(parseFloat(down_size / item.size).toFixed(2) * 100);
if (!(down_progress % 5)) {
task.update(down_progress + '%');
};
})
path: path
}), (_size) => {
// 计算进度百分比
down_size += _size;
let down_progress = parseInt(parseFloat(down_size / item.size).toFixed(2) * 100);
if (!(down_progress % 5)) {
task.update(down_progress + '%');
};
})
.then((_size) => {
if (_size === item.size) {
task.success(LANG['download']['task']['success']);
......@@ -944,69 +946,69 @@ class FileManager {
icon: 'code',
type: 'button'
};
(_ === ext) ? _opt['selected'] = true: 0;
(_ === ext) ? _opt['selected'] = true : 0;
_options.push(_opt);
}
toolbar.loadStruct([{
id: 'hinttext',
type: 'text',
text: hinttext
},
{
id: 'filepath',
type: 'buttonInput',
width: 500,
value: antSword.noxss(path),
},
{
type: 'separator'
},
{
type: 'spacer'
},
{
id: 'refresh',
type: 'button',
icon: 'refresh',
text: LANG['editor']['toolbar']['refresh']
},
{
id: 'save',
type: 'button',
icon: 'save',
text: LANG['editor']['toolbar']['save']
},
{
type: 'separator'
},
{
id: 'encode',
type: 'buttonSelect',
icon: 'language',
openAll: true,
text: LANG['editor']['toolbar']['encode'],
options: (() => {
let ret = [];
ENCODES.map((_) => {
let _opt_ = {
id: `encode_${_}`,
text: _,
icon: 'font',
type: 'button'
};
(_ === self.opts['encode'] ? _opt_['selected'] = true : 0);
ret.push(_opt_);
});
return ret;
})()
}, {
id: 'mode',
type: 'buttonSelect',
icon: 'th-list',
openAll: true,
text: LANG['editor']['toolbar']['mode'],
options: _options
},
id: 'hinttext',
type: 'text',
text: hinttext
},
{
id: 'filepath',
type: 'buttonInput',
width: 500,
value: antSword.noxss(path),
},
{
type: 'separator'
},
{
type: 'spacer'
},
{
id: 'refresh',
type: 'button',
icon: 'refresh',
text: LANG['editor']['toolbar']['refresh']
},
{
id: 'save',
type: 'button',
icon: 'save',
text: LANG['editor']['toolbar']['save']
},
{
type: 'separator'
},
{
id: 'encode',
type: 'buttonSelect',
icon: 'language',
openAll: true,
text: LANG['editor']['toolbar']['encode'],
options: (() => {
let ret = [];
ENCODES.map((_) => {
let _opt_ = {
id: `encode_${_}`,
text: _,
icon: 'font',
type: 'button'
};
(_ === self.opts['encode'] ? _opt_['selected'] = true : 0);
ret.push(_opt_);
});
return ret;
})()
}, {
id: 'mode',
type: 'buttonSelect',
icon: 'th-list',
openAll: true,
text: LANG['editor']['toolbar']['mode'],
options: _options
},
]);
toolbar.setItemToolTip('hinttext', tooltip);
toolbar.attachEvent('onClick', (id) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment