Commit a10727c3 authored by Medicean's avatar Medicean

(Enhance:FileManager) 多文件下载

parent 22700479
...@@ -19,18 +19,18 @@ class Files { ...@@ -19,18 +19,18 @@ class Files {
let bookmark = JSON.parse(manager.storage('bookmarks').get('{}')); let bookmark = JSON.parse(manager.storage('bookmarks').get('{}'));
// 重新加载书签 // 重新加载书签
this.reloadToolbar = () => { this.reloadToolbar = () => {
let bookmark_opts = [ let bookmark_opts = [{
{
id: 'bookmark_add', id: 'bookmark_add',
type: 'button', type: 'button',
icon: 'plus-circle', icon: 'plus-circle',
text: LANG['bookmark']['add'], text: LANG['bookmark']['add'],
enabled: !bookmark[manager.path] enabled: !bookmark[manager.path]
} }];
];
let global_bookmarks = manager.config.bookmarks || {}; let global_bookmarks = manager.config.bookmarks || {};
if (Object.keys(global_bookmarks).length > 0) { if (Object.keys(global_bookmarks).length > 0) {
bookmark_opts.push({type: 'separator'}); bookmark_opts.push({
type: 'separator'
});
for (let gb in global_bookmarks) { for (let gb in global_bookmarks) {
bookmark_opts.push({ bookmark_opts.push({
id: 'bookmark_' + global_bookmarks[gb], id: 'bookmark_' + global_bookmarks[gb],
...@@ -42,7 +42,9 @@ class Files { ...@@ -42,7 +42,9 @@ class Files {
} }
} }
if (!$.isEmptyObject(bookmark)) { if (!$.isEmptyObject(bookmark)) {
bookmark_opts.push({type: 'separator'}); bookmark_opts.push({
type: 'separator'
});
}; };
for (let _ in bookmark) { for (let _ in bookmark) {
bookmark_opts.push({ bookmark_opts.push({
...@@ -55,7 +57,9 @@ class Files { ...@@ -55,7 +57,9 @@ class Files {
} }
// 添加清除按钮 // 添加清除按钮
if (bookmark_opts.length > 2) { if (bookmark_opts.length > 2) {
bookmark_opts.push({type: 'separator'}); bookmark_opts.push({
type: 'separator'
});
bookmark_opts.push({ bookmark_opts.push({
id: 'bookmark_remove', id: 'bookmark_remove',
icon: 'remove', icon: 'remove',
...@@ -63,19 +67,22 @@ class Files { ...@@ -63,19 +67,22 @@ class Files {
type: 'button', type: 'button',
enabled: !!bookmark[manager.path] enabled: !!bookmark[manager.path]
}); });
bookmark_opts.push({id: 'bookmark_clear', icon: 'trash-o', text: LANG['bookmark']['clear'], type: 'button'}); bookmark_opts.push({
id: 'bookmark_clear',
icon: 'trash-o',
text: LANG['bookmark']['clear'],
type: 'button'
});
}; };
toolbar.clearAll(); toolbar.clearAll();
toolbar.loadStruct([ toolbar.loadStruct([{
{
id: 'new', id: 'new',
type: 'buttonSelect', type: 'buttonSelect',
icon: 'plus-circle', icon: 'plus-circle',
text: LANG['toolbar']['new'], text: LANG['toolbar']['new'],
openAll: true, openAll: true,
options: [ options: [{
{
id: 'new_folder', id: 'new_folder',
icon: 'folder-o', icon: 'folder-o',
type: 'button', type: 'button',
...@@ -97,8 +104,7 @@ class Files { ...@@ -97,8 +104,7 @@ class Files {
icon: 'cloud-upload', icon: 'cloud-upload',
type: 'button', type: 'button',
text: LANG['toolbar']['upload'] text: LANG['toolbar']['upload']
} }]
]
}, { }, {
type: 'separator' type: 'separator'
}, { }, {
...@@ -143,8 +149,7 @@ class Files { ...@@ -143,8 +149,7 @@ class Files {
text: LANG['toolbar']['read'] text: LANG['toolbar']['read']
}, { }, {
type: 'separator' type: 'separator'
} }]);
]);
} }
this.reloadToolbar(); this.reloadToolbar();
...@@ -258,9 +263,8 @@ class Files { ...@@ -258,9 +263,8 @@ class Files {
grid.enableMultiselect(true); grid.enableMultiselect(true);
// grid.enableDragAndDrop(true); grid.enableMultiline(true); grid右键 空白数据右键fix // grid.enableDragAndDrop(true); grid.enableMultiline(true); grid右键 空白数据右键fix
$('.objbox').on('contextmenu', (e) => { $('.objbox').on('contextmenu', (e) => {
(e.target.nodeName === 'DIV' && grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab().startsWith('tab_filemanager_')) (e.target.nodeName === 'DIV' && grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab().startsWith('tab_filemanager_')) ?
? grid.callEvent('onRightClick', [-1, -1, e]) grid.callEvent('onRightClick', [-1, -1, e]): null;
: null;
}); });
$('.objbox').on('click', (e) => { $('.objbox').on('click', (e) => {
bmenu.hide(); bmenu.hide();
...@@ -289,9 +293,9 @@ class Files { ...@@ -289,9 +293,9 @@ class Files {
for (let c in self.Clipboard) { for (let c in self.Clipboard) {
_Clipboard.push({ _Clipboard.push({
text: antSword.noxss(c), text: antSword.noxss(c),
icon: 'fa fa-' + (c.endsWith('/') icon: 'fa fa-' + (c.endsWith('/') ?
? 'folder-o' 'folder-o' :
: 'file-o'), 'file-o'),
action: ((source, name) => { action: ((source, name) => {
return () => { return () => {
manager.pasteFile(source, name); manager.pasteFile(source, name);
...@@ -300,14 +304,19 @@ class Files { ...@@ -300,14 +304,19 @@ class Files {
}); });
_Clipboard_num++; _Clipboard_num++;
if (!(_Clipboard_num % 5)) { if (!(_Clipboard_num % 5)) {
_Clipboard.push({divider: true}); _Clipboard.push({
divider: true
});
}; };
} }
// 清除最后的divider if (_Clipboard.length % 5 && _Clipboard_num > 5) { // 清除最后的divider if (_Clipboard.length % 5 && _Clipboard_num > 5) {
// _Clipboard.pop() }; all item // _Clipboard.pop() }; all item
if (_Clipboard.length > 0) { if (_Clipboard.length > 0) {
_Clipboard.unshift({divider: true}); _Clipboard.unshift({
_Clipboard.unshift({text: LANG['grid']['contextmenu']['paste']['all'], divider: true
});
_Clipboard.unshift({
text: LANG['grid']['contextmenu']['paste']['all'],
count: _Clipboard_num, count: _Clipboard_num,
icon: 'fa fa-th-list', icon: 'fa fa-th-list',
action: () => { action: () => {
...@@ -325,10 +334,12 @@ class Files { ...@@ -325,10 +334,12 @@ class Files {
} }
}); });
// 清空剪贴板 // 清空剪贴板
!(_Clipboard[_Clipboard.length - 1].divider) !(_Clipboard[_Clipboard.length - 1].divider) ?
? _Clipboard.push({divider: true}) _Clipboard.push({
: 0; divider: true
_Clipboard.push({text: LANG['grid']['contextmenu']['paste']['clear']['title'], }): 0;
_Clipboard.push({
text: LANG['grid']['contextmenu']['paste']['clear']['title'],
icon: 'fa fa-trash-o', icon: 'fa fa-trash-o',
action: () => { action: () => {
self.Clipboard = {}; self.Clipboard = {};
...@@ -338,6 +349,7 @@ class Files { ...@@ -338,6 +349,7 @@ class Files {
}; };
let isFolder = id.endsWith('/'); let isFolder = id.endsWith('/');
let containsFolder = (ids.join("~assep~") + '~assep~').indexOf('/~assep~') > -1;
// 可编辑文件后缀 // 可编辑文件后缀
let isEdited = false; let isEdited = false;
'php,asp,aspx,jsp,cfm,js,css,html,py,sh,bat,txt,log,ini,conf,sql' 'php,asp,aspx,jsp,cfm,js,css,html,py,sh,bat,txt,log,ini,conf,sql'
...@@ -345,13 +357,12 @@ class Files { ...@@ -345,13 +357,12 @@ class Files {
.map((e) => { .map((e) => {
id id
.toLowerCase() .toLowerCase()
.endsWith(`.${e}`) .endsWith(`.${e}`) ?
? isEdited = true isEdited = true :
: 0; 0;
}); });
let menu = [ let menu = [{
{
text: LANG['grid']['contextmenu']['refresh'], text: LANG['grid']['contextmenu']['refresh'],
icon: 'fa fa-refresh', icon: 'fa fa-refresh',
action: () => { action: () => {
...@@ -374,17 +385,27 @@ class Files { ...@@ -374,17 +385,27 @@ class Files {
}, { }, {
text: LANG['grid']['contextmenu']['download'], text: LANG['grid']['contextmenu']['download'],
icon: 'fa fa-download', icon: 'fa fa-download',
disabled: isFolder || !id || ids.length > 1, disabled: isFolder || !id || containsFolder,
action: () => { action: () => {
if (ids.length === 1) {
manager.downloadFile(id, this.getRowAttribute(_ids[0], 'fsize')); manager.downloadFile(id, this.getRowAttribute(_ids[0], 'fsize'));
} else if (ids.length > 1) {
let dnames = [];
for (let i = 0; i < ids.length; i++) {
dnames.push({
name: ids[i],
size: this.getRowAttribute(_ids[i], 'fsize'),
});
}
manager.downloadFileMulti(dnames);
}
} }
}, { }, {
divider: true divider: true
}, { }, {
text: LANG['grid']['contextmenu']['copy']['title'], text: LANG['grid']['contextmenu']['copy']['title'],
icon: 'fa fa-copy', icon: 'fa fa-copy',
subMenu: [ subMenu: [{
{
text: LANG['grid']['contextmenu']['copy']['title'], text: LANG['grid']['contextmenu']['copy']['title'],
icon: 'fa fa-copy', icon: 'fa fa-copy',
disabled: !id, disabled: !id,
...@@ -429,8 +450,7 @@ class Files { ...@@ -429,8 +450,7 @@ class Files {
toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']); toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']);
} }
} }
} }]
]
}, { }, {
text: LANG['grid']['contextmenu']['paste']['title'], text: LANG['grid']['contextmenu']['paste']['title'],
icon: 'fa fa-paste', icon: 'fa fa-paste',
...@@ -448,10 +468,9 @@ class Files { ...@@ -448,10 +468,9 @@ class Files {
}, { }, {
text: LANG['grid']['contextmenu']['edit']['title'], text: LANG['grid']['contextmenu']['edit']['title'],
icon: 'fa fa-edit', icon: 'fa fa-edit',
disabled:/*!isEdited || */ disabled: /*!isEdited || */
!id || ids.length > 1 || isFolder, !id || ids.length > 1 || isFolder,
subMenu: [ subMenu: [{
{
text: LANG['grid']['contextmenu']['edit']['opentab'], text: LANG['grid']['contextmenu']['edit']['opentab'],
icon: 'fa fa-external-link', icon: 'fa fa-external-link',
action: () => { action: () => {
...@@ -463,8 +482,7 @@ class Files { ...@@ -463,8 +482,7 @@ class Files {
action: () => { action: () => {
manager.editFile(id, false); manager.editFile(id, false);
} }
} }]
]
}, { }, {
text: LANG['grid']['contextmenu']['delete'], text: LANG['grid']['contextmenu']['delete'],
icon: 'fa fa-trash-o', icon: 'fa fa-trash-o',
...@@ -499,8 +517,7 @@ class Files { ...@@ -499,8 +517,7 @@ class Files {
}, { }, {
text: LANG['grid']['contextmenu']['create']['title'], text: LANG['grid']['contextmenu']['create']['title'],
icon: 'fa fa-plus-circle', icon: 'fa fa-plus-circle',
subMenu: [ subMenu: [{
{
text: LANG['grid']['contextmenu']['create']['folder'], text: LANG['grid']['contextmenu']['create']['folder'],
icon: 'fa fa-folder-o', icon: 'fa fa-folder-o',
action: manager action: manager
...@@ -512,16 +529,16 @@ class Files { ...@@ -512,16 +529,16 @@ class Files {
action: manager action: manager
.createFile .createFile
.bind(manager) .bind(manager)
} }]
]
}, { }, {
text: LANG['grid']['contextmenu']['terminal'], text: LANG['grid']['contextmenu']['terminal'],
icon: 'fa fa-terminal', icon: 'fa fa-terminal',
action: () => { action: () => {
new Terminal(self.manager.opts, {'path': self.manager.path}); new Terminal(self.manager.opts, {
} 'path': self.manager.path
});
} }
]; }];
bmenu(menu, event); bmenu(menu, event);
...@@ -554,7 +571,7 @@ class Files { ...@@ -554,7 +571,7 @@ class Files {
// 键盘按下事件 // 键盘按下事件
grid.attachEvent('onKeyPress', (code, cFlag, sFlag) => { grid.attachEvent('onKeyPress', (code, cFlag, sFlag) => {
switch (true) { switch (true) {
case(code <= 90 && code >= 65) || (code <= 57 && code >= 48): case (code <= 90 && code >= 65) || (code <= 57 && code >= 48):
// A-Z 0-9 // A-Z 0-9
var input = String.fromCharCode(code); var input = String.fromCharCode(code);
input = input.toLowerCase(); input = input.toLowerCase();
...@@ -572,7 +589,7 @@ class Files { ...@@ -572,7 +589,7 @@ class Files {
} }
} }
break break
case(code == 38): case (code == 38):
//up //up
var ids = grid var ids = grid
.getAllRowIds() .getAllRowIds()
...@@ -580,12 +597,12 @@ class Files { ...@@ -580,12 +597,12 @@ class Files {
var sid = grid var sid = grid
.getSelectedRowId() .getSelectedRowId()
.toString(); .toString();
var cid = ids.indexOf(sid) <= 0 var cid = ids.indexOf(sid) <= 0 ?
? parseInt(ids[0]) - 1 parseInt(ids[0]) - 1 :
: parseInt(ids[ids.indexOf(sid) - 1]) - 1; parseInt(ids[ids.indexOf(sid) - 1]) - 1;
grid.selectRow(cid); grid.selectRow(cid);
break; break;
case(code == 40): case (code == 40):
//down //down
var ids = grid var ids = grid
.getAllRowIds() .getAllRowIds()
...@@ -593,9 +610,9 @@ class Files { ...@@ -593,9 +610,9 @@ class Files {
var sid = grid var sid = grid
.getSelectedRowId() .getSelectedRowId()
.toString(); .toString();
var cid = ids.indexOf(sid) >= ids.length - 1 var cid = ids.indexOf(sid) >= ids.length - 1 ?
? parseInt(ids[ids.length - 1]) - 1 parseInt(ids[ids.length - 1]) - 1 :
: parseInt(ids[ids.indexOf(sid) + 1]) - 1; parseInt(ids[ids.indexOf(sid) + 1]) - 1;
grid.selectRow(cid); grid.selectRow(cid);
break; break;
default: default:
...@@ -647,9 +664,9 @@ class Files { ...@@ -647,9 +664,9 @@ class Files {
.map((e) => { .map((e) => {
name name
.toLowerCase() .toLowerCase()
.endsWith(`.${e}`) .endsWith(`.${e}`) ?
? isPreviewed = true isPreviewed = true :
: 0; 0;
}); });
return isPreviewed; return isPreviewed;
} }
...@@ -713,9 +730,8 @@ class Files { ...@@ -713,9 +730,8 @@ class Files {
fname: file['name'], fname: file['name'],
fsize: parseInt(file['size']), fsize: parseInt(file['size']),
// 如果是可执行文件(exe、dll..),则设置为红色字体 // 如果是可执行文件(exe、dll..),则设置为红色字体
style: /\.exe$|\.dll$|\.bat$|\.sh$|\.com$/.test(file['name']) style: /\.exe$|\.dll$|\.bat$|\.sh$|\.com$/.test(file['name']) ?
? 'color:red' 'color:red' : '',
: '',
data: [ data: [
self.fileIcon(file['name']), self.fileIcon(file['name']),
antSword.noxss(file['name'].replace(/\/$/, '')), antSword.noxss(file['name'].replace(/\/$/, '')),
......
...@@ -61,7 +61,7 @@ class FileManager { ...@@ -61,7 +61,7 @@ class FileManager {
const cache_info = this.cache.get('info'); const cache_info = this.cache.get('info');
if (cache_info) { if (cache_info) {
this.initUI(cache_info); this.initUI(cache_info);
}else{ } else {
this.cell.progressOn(); this.cell.progressOn();
this.core.request( this.core.request(
this.core.base.info() this.core.base.info()
...@@ -71,7 +71,7 @@ class FileManager { ...@@ -71,7 +71,7 @@ class FileManager {
}).catch((err) => { }).catch((err) => {
this.cell.progressOff(); this.cell.progressOff();
this.cell.close(); this.cell.close();
toastr.error((typeof(err) === 'object') ? JSON.stringify(err) : String(err), LANG_T['error']); toastr.error((typeof (err) === 'object') ? JSON.stringify(err) : String(err), LANG_T['error']);
}); });
// this.core.base.info((ret) => { // this.core.base.info((ret) => {
// this.initUI(ret); // this.initUI(ret);
...@@ -98,7 +98,7 @@ class FileManager { ...@@ -98,7 +98,7 @@ class FileManager {
// 判断是否为linux // 判断是否为linux
if (info_path.substr(0, 1) === '/') { if (info_path.substr(0, 1) === '/') {
this.isWin = false; this.isWin = false;
}else{ } else {
// windows 盘符统一大写 // 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(); info_drive = info_drive.toUpperCase();
...@@ -106,7 +106,9 @@ class FileManager { ...@@ -106,7 +106,9 @@ class FileManager {
this.path = info_path; this.path = info_path;
this.home = info_path; this.home = info_path;
info_drive.split(':').map((_) => { info_drive.split(':').map((_) => {
if (!_) { return }; if (!_) {
return
};
this.devices.push(_ === '/' ? _ : _ + ':/'); this.devices.push(_ === '/' ? _ : _ + ':/');
}); });
...@@ -141,17 +143,19 @@ class FileManager { ...@@ -141,17 +143,19 @@ class FileManager {
getFiles(p, callback) { getFiles(p, callback) {
let self = this; let self = this;
if(self.isWin) { // 处理输入为 f:\ 这种情况 if (self.isWin) { // 处理输入为 f:\ 这种情况
p = p.replace(/\\/g, '/'); 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); let path = this.changePath(p);
if (self.isWin){ // 处理输入为 f: 这种情况 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; let cache;
if (!path.endsWith('/')) { path += '/' }; if (!path.endsWith('/')) {
path += '/'
};
this.path = path; this.path = path;
let cache_tag = 'filemanager-files-' + Buffer.from(this.path).toString('base64'); let cache_tag = 'filemanager-files-' + Buffer.from(this.path).toString('base64');
...@@ -181,7 +185,7 @@ class FileManager { ...@@ -181,7 +185,7 @@ class FileManager {
let folders = []; let folders = [];
let files = []; let files = [];
tmp.map( (t) => { tmp.map((t) => {
let _ = t.split('\t'); let _ = t.split('\t');
let d = { let d = {
name: _[0], name: _[0],
...@@ -191,10 +195,10 @@ class FileManager { ...@@ -191,10 +195,10 @@ class FileManager {
} }
if (_[0].endsWith('/')) { if (_[0].endsWith('/')) {
folders.push(d); folders.push(d);
}else{ } else {
files.push(d); files.push(d);
} }
} ); });
let data = folders.concat(files); let data = folders.concat(files);
callback(data); callback(data);
...@@ -259,23 +263,23 @@ class FileManager { ...@@ -259,23 +263,23 @@ class FileManager {
if (path === './') { if (path === './') {
return this.path; return this.path;
// 如果是上级目录,则判断是否为最后一级?返回最后一级:返回上一级 // 如果是上级目录,则判断是否为最后一级?返回最后一级:返回上一级
}else if (path === '../') { } else if (path === '../') {
let _ = this.path.split('/'); let _ = this.path.split('/');
if (_.length === 2) { if (_.length === 2) {
return _.join('/'); return _.join('/');
}else if (_.length > 2) { } else if (_.length > 2) {
_.pop(); _.pop();
_.pop(); _.pop();
_.length === 1 ? _.push('') : 0; _.length === 1 ? _.push('') : 0;
return _.join('/'); return _.join('/');
}else{ } else {
return this.path; return this.path;
} }
// 如果是根目录,返回 // 如果是根目录,返回
}else if (path.startsWith('/') || path.substr(1, 2) === ':/') { } else if (path.startsWith('/') || path.substr(1, 2) === ':/') {
return path; return path;
// 如果是相对路径,返回绝对全路径 // 如果是相对路径,返回绝对全路径
}else{ } else {
return this.path + path; return this.path + path;
} }
} }
...@@ -310,7 +314,7 @@ class FileManager { ...@@ -310,7 +314,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
toastr.success(LANG['delete']['success'](path), LANG_T['success']); toastr.success(LANG['delete']['success'](path), LANG_T['success']);
this.files.refreshPath(); this.files.refreshPath();
}else{ } else {
toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -360,7 +364,7 @@ class FileManager { ...@@ -360,7 +364,7 @@ class FileManager {
// 删除缓存 // 删除缓存
delete this.files.Clipboard[name]; delete this.files.Clipboard[name];
toastr.success(LANG['paste']['success'](name), LANG_T['success']); toastr.success(LANG['paste']['success'](name), LANG_T['success']);
}else{ } else {
toastr.error(LANG['paste']['error'](name, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['paste']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -387,7 +391,7 @@ class FileManager { ...@@ -387,7 +391,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
this.files.refreshPath(); this.files.refreshPath();
toastr.success(LANG['rename']['success'], LANG_T['success']); toastr.success(LANG['rename']['success'], LANG_T['success']);
}else{ } else {
toastr.error(LANG['rename']['error'](ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['rename']['error'](ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -414,7 +418,7 @@ class FileManager { ...@@ -414,7 +418,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
this.files.refreshPath(); this.files.refreshPath();
toastr.success(LANG['createFolder']['success'](value), LANG_T['success']); toastr.success(LANG['createFolder']['success'](value), LANG_T['success']);
}else{ } else {
toastr.error(LANG['createFolder']['error'](value, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['createFolder']['error'](value, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -444,7 +448,7 @@ class FileManager { ...@@ -444,7 +448,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
this.files.refreshPath(); this.files.refreshPath();
toastr.success(LANG['createFile']['success'](value), LANG_T['success']); toastr.success(LANG['createFile']['success'](value), LANG_T['success']);
}else{ } else {
toastr.error(LANG['createFile']['error'](value, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['createFile']['error'](value, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -479,7 +483,7 @@ class FileManager { ...@@ -479,7 +483,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
this.files.refreshPath(); this.files.refreshPath();
toastr.success(LANG['retime']['success'](name), LANG_T['success']); toastr.success(LANG['retime']['success'](name), LANG_T['success']);
}else{ } else {
toastr.error(LANG['retime']['error'](name, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['retime']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -495,7 +499,7 @@ class FileManager { ...@@ -495,7 +499,7 @@ class FileManager {
value: antSword.noxss(oldmod), value: antSword.noxss(oldmod),
title: `<i class="fa fa-users"></i> ${LANG['chmod']['title']} (${antSword.noxss(name)})`, title: `<i class="fa fa-users"></i> ${LANG['chmod']['title']} (${antSword.noxss(name)})`,
}, (value, i, e) => { }, (value, i, e) => {
if(!value.match(/^[0-7]{4}$/)){ if (!value.match(/^[0-7]{4}$/)) {
toastr.error(LANG['chmod']['check'], LANG_T['error']); toastr.error(LANG['chmod']['check'], LANG_T['error']);
return return
} }
...@@ -516,7 +520,7 @@ class FileManager { ...@@ -516,7 +520,7 @@ class FileManager {
if (ret === '1') { if (ret === '1') {
this.files.refreshPath(); this.files.refreshPath();
toastr.success(LANG['chmod']['success'](name), LANG_T['success']); toastr.success(LANG['chmod']['success'](name), LANG_T['success']);
}else{ } else {
toastr.error(LANG['chmod']['error'](name, ret === '0' ? false : ret), LANG_T['error']); toastr.error(LANG['chmod']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
...@@ -536,15 +540,15 @@ class FileManager { ...@@ -536,15 +540,15 @@ class FileManager {
height: 600, height: 600,
}); });
var filemime = mime.lookup(name); var filemime = mime.lookup(name);
let savepath = PATH.join(process.env.AS_WORKDIR,`antData/.temp/`,Buffer.from(name).toString("hex")); let savepath = PATH.join(process.env.AS_WORKDIR, `antData/.temp/`, Buffer.from(name).toString("hex"));
win.cell.lastChild['style']['overflow'] = 'scroll'; win.cell.lastChild['style']['overflow'] = 'scroll';
win.cell.lastChild['style']['textAlign'] = 'center'; win.cell.lastChild['style']['textAlign'] = 'center';
let down_size = 0; let down_size = 0;
this.core.download( this.core.download(
savepath savepath, this.core.filemanager.download_file({
,this.core.filemanager.download_file({path: remote_path}) path: remote_path
, (_size) => { }), (_size) => {
down_size += _size; down_size += _size;
let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100); let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100);
if (!(down_progress % 5)) { if (!(down_progress % 5)) {
...@@ -555,14 +559,14 @@ class FileManager { ...@@ -555,14 +559,14 @@ class FileManager {
if (_size === size) { if (_size === size) {
win.setText(`Preview File: ${antSword.noxss(remote_path)}`); win.setText(`Preview File: ${antSword.noxss(remote_path)}`);
let buff = fs.readFileSync(savepath); let buff = fs.readFileSync(savepath);
switch (filemime){ switch (filemime) {
default: default:
let data = Buffer.from(buff).toString('base64'); let data = Buffer.from(buff).toString('base64');
win.attachHTMLString(`<img style="width:100%" src="data:/${filemime};base64,${data}"/>`); win.attachHTMLString(`<img style="width:100%" src="data:/${filemime};base64,${data}"/>`);
break; break;
} }
fs.unlink(savepath); fs.unlink(savepath);
}else{ } else {
fs.unlink(savepath); fs.unlink(savepath);
throw Error(`Load Error: downsize ${_size} != ${size}`); throw Error(`Load Error: downsize ${_size} != ${size}`);
} }
...@@ -574,13 +578,15 @@ class FileManager { ...@@ -574,13 +578,15 @@ class FileManager {
// 下载文件 // 下载文件
downloadFile(name, size) { downloadFile(name, size) {
const path = this.path + name; const path = this.path + name;
const task = this.tasks.new(LANG['download']['task']['name'], path , LANG['download']['task']['wait']); const task = this.tasks.new(LANG['download']['task']['name'], path, LANG['download']['task']['wait']);
// 获取要保存的路径 // 获取要保存的路径
dialog.showSaveDialog({ dialog.showSaveDialog({
title: LANG['download']['title'], title: LANG['download']['title'],
defaultPath: name defaultPath: name
}, (filePath) => { }, (filePath) => {
if (!filePath) { return task.end(LANG['download']['task']['cancel']) }; if (!filePath) {
return task.end(LANG['download']['task']['cancel'])
};
task.update(LANG['download']['task']['start']); task.update(LANG['download']['task']['start']);
let down_size = 0; let down_size = 0;
// 删除旧文件(如果存在 // 删除旧文件(如果存在
...@@ -588,11 +594,9 @@ class FileManager { ...@@ -588,11 +594,9 @@ class FileManager {
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
} }
this.core.download( this.core.download(
filePath filePath, this.core.filemanager.download_file({
, this.core.filemanager.download_file({
path: path path: path
}) }), (_size) => {
, (_size) => {
// 计算进度百分比 // 计算进度百分比
down_size += _size; down_size += _size;
let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100); let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100);
...@@ -607,7 +611,7 @@ class FileManager { ...@@ -607,7 +611,7 @@ class FileManager {
toastr.success(LANG['download']['success'](name), LANG_T['success']); toastr.success(LANG['download']['success'](name), LANG_T['success']);
// }else if (_size === 21) { // }else if (_size === 21) {
// task.failed('len=' + _size); // task.failed('len=' + _size);
}else{ } else {
throw Error(`SizeErr: ${_size} != ${size}`); throw Error(`SizeErr: ${_size} != ${size}`);
// task.failed(LANG['download']['task']['error']()) // task.failed(LANG['download']['task']['error']())
} }
...@@ -618,6 +622,60 @@ class FileManager { ...@@ -618,6 +622,60 @@ class FileManager {
}); });
} }
// 下载多个文件
// [{name:"123.txt", size: 1234}]
downloadFileMulti(names = []) {
let self = this;
let selectPaths = dialog.showOpenDialog({
title: LANG['download']['title'],
properties: ['openDirectory'],
});
let savePath = null;
if (selectPaths && selectPaths.length === 1) {
savePath = selectPaths[0];
}
if (!savePath) {
return;
}
names.forEach((item) => {
const path = self.path + item.name;
const task = self
.tasks
.new(LANG['download']['task']['name'], path, LANG['download']['task']['wait']);
task.update(LANG['download']['task']['start']);
let down_size = 0;
let filePath = PATH.join(savePath, item.name);
// 删除旧文件(如果存在
if (fs.existsSync(filePath)) {
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 + '%');
};
})
.then((_size) => {
if (_size === item.size) {
task.success(LANG['download']['task']['success']);
toastr.success(LANG['download']['success'](name), LANG_T['success']);
// }else if (_size === 21) { task.failed('len=' + _size);
} else {
throw Error(`SizeErr: ${_size} != ${item.size}`);
// task.failed(LANG['download']['task']['error']())
}
})
.catch((err) => {
task.failed(LANG['download']['task']['error'](err));
toastr.error(LANG['download']['error'](name, err), LANG_T['error']);
});
});
}
// wget文件 // wget文件
wgetFile() { wgetFile() {
let self = this; let self = this;
...@@ -658,7 +716,7 @@ class FileManager { ...@@ -658,7 +716,7 @@ class FileManager {
task.success(LANG['wget']['task']['success']); task.success(LANG['wget']['task']['success']);
let _ = path.substr(0, path.lastIndexOf('/') + 1); let _ = path.substr(0, path.lastIndexOf('/') + 1);
this.files.refreshPath((_ === self.path) ? false : _); this.files.refreshPath((_ === self.path) ? false : _);
}else{ } else {
task.failed(LANG['wget']['task']['failed'](ret)); task.failed(LANG['wget']['task']['failed'](ret));
} }
}).catch((err) => { }).catch((err) => {
...@@ -686,9 +744,11 @@ class FileManager { ...@@ -686,9 +744,11 @@ class FileManager {
return res(_filePaths); return res(_filePaths);
} }
dialog.showOpenDialog({ dialog.showOpenDialog({
properties: [ 'openFile', 'multiSelections' ] properties: ['openFile', 'multiSelections']
}, (_filePaths) => { }, (_filePaths) => {
if (!_filePaths) { return }; if (!_filePaths) {
return
};
return res(_filePaths); return res(_filePaths);
}) })
}).then((filePaths) => { }).then((filePaths) => {
...@@ -713,7 +773,7 @@ class FileManager { ...@@ -713,7 +773,7 @@ class FileManager {
let buff = []; let buff = [];
// 分段上传大小,默认0.5M(jsp 超过1M响应会出错) // 分段上传大小,默认0.5M(jsp 超过1M响应会出错)
let dataSplit = 500 * 1024; let dataSplit = 500 * 1024;
if ( parseInt((this.opts.otherConf || {})['upload-fragment']) > 0 ) { if (parseInt((this.opts.otherConf || {})['upload-fragment']) > 0) {
dataSplit = parseInt((this.opts.otherConf || {})['upload-fragment']) * 1024; dataSplit = parseInt((this.opts.otherConf || {})['upload-fragment']) * 1024;
} }
let task = tasks[filePath]; let task = tasks[filePath];
...@@ -739,7 +799,7 @@ class FileManager { ...@@ -739,7 +799,7 @@ class FileManager {
let _b = _buff.shift(); let _b = _buff.shift();
if (_b) { if (_b) {
res(_b); res(_b);
}else{ } else {
// 上传完毕 // 上传完毕
task.success(LANG['upload']['task']['success']); task.success(LANG['upload']['task']['success']);
toastr.success(LANG['upload']['success'](fileName), LANG_T['success']); toastr.success(LANG['upload']['success'](fileName), LANG_T['success']);
...@@ -771,15 +831,15 @@ class FileManager { ...@@ -771,15 +831,15 @@ class FileManager {
let errmsg = err; let errmsg = err;
if (err.hasOwnProperty('status') && err.hasOwnProperty('response')) { if (err.hasOwnProperty('status') && err.hasOwnProperty('response')) {
errmsg = `${err.status} ${err.response.res.statusMessage}`; errmsg = `${err.status} ${err.response.res.statusMessage}`;
switch(err.status) { switch (err.status) {
case 413: case 413:
errmsg += `${LANG['upload']['task']['httperr_413']}`; errmsg += `${LANG['upload']['task']['httperr_413']}`;
break; break;
default: default:
break; break;
} }
}else if(err.hasOwnProperty('errno')) { } else if (err.hasOwnProperty('errno')) {
switch(err.errno) { switch (err.errno) {
case 'ETIME': case 'ETIME':
errmsg = `${LANG['upload']['task']['httperr_etime']}`; errmsg = `${LANG['upload']['task']['httperr_etime']}`;
break; break;
...@@ -804,20 +864,20 @@ class FileManager { ...@@ -804,20 +864,20 @@ class FileManager {
} }
// 编辑文件 // 编辑文件
editFile(name, openfileintab=false) { editFile(name, openfileintab = false) {
let self = this; let self = this;
let path = this.path + name; let path = this.path + name;
let editor = null; let editor = null;
let codes = ''; let codes = '';
let win; let win;
let hinttext = ''; let hinttext = '';
if (openfileintab == false){ if (openfileintab == false) {
win = this.createWin({ win = this.createWin({
title: LANG['editor']['title'](antSword.noxss(path)), title: LANG['editor']['title'](antSword.noxss(path)),
width: 800 width: 800
}); });
win.maximize(); win.maximize();
}else{ } else {
let _id = String(Math.random()).substr(5, 10); let _id = String(Math.random()).substr(5, 10);
antSword['tabbar'].addTab( antSword['tabbar'].addTab(
`tab_file_${_id}`, `tab_file_${_id}`,
...@@ -833,15 +893,37 @@ class FileManager { ...@@ -833,15 +893,37 @@ class FileManager {
// 检测文件后缀 // 检测文件后缀
let ext = name.substr(name.lastIndexOf('.') + 1); let ext = name.substr(name.lastIndexOf('.') + 1);
let ext_dict = { let ext_dict = {
'php': 'php', 'c': 'c_cpp', 'cpp': 'c_cpp', 'h': 'c_cpp', 'php': 'php',
'coffee': 'coffee', 'cfm': 'coldfusion', 'css': 'css', 'c': 'c_cpp',
'go': 'golang', 'html': 'html', 'ini': 'ini', 'conf': 'ini', 'cpp': 'c_cpp',
'jade': 'jade', 'java': 'java', 'js': 'javascript', 'json': 'json', 'h': 'c_cpp',
'jsp': 'jsp', 'jsx': 'jsx', 'less': 'less', 'lua': 'lua', 'md': 'markdown', 'coffee': 'coffee',
'sql': 'sql', 'pl': 'perl', 'py': 'python', 'rb': 'ruby', 'cfm': 'coldfusion',
'sh': 'sh', 'txt': 'text', 'xml': 'xml' 'css': 'css',
} 'go': 'golang',
if (!(ext in ext_dict)) { ext = 'txt' }; 'html': 'html',
'ini': 'ini',
'conf': 'ini',
'jade': 'jade',
'java': 'java',
'js': 'javascript',
'json': 'json',
'jsp': 'jsp',
'jsx': 'jsx',
'less': 'less',
'lua': 'lua',
'md': 'markdown',
'sql': 'sql',
'pl': 'perl',
'py': 'python',
'rb': 'ruby',
'sh': 'sh',
'txt': 'text',
'xml': 'xml'
}
if (!(ext in ext_dict)) {
ext = 'txt'
};
// 创建窗口工具栏 // 创建窗口工具栏
let toolbar = win.attachToolbar(); let toolbar = win.attachToolbar();
let _options = []; let _options = [];
...@@ -853,17 +935,34 @@ class FileManager { ...@@ -853,17 +935,34 @@ class FileManager {
icon: 'code', icon: 'code',
type: 'button' type: 'button'
}; };
(_ === ext) ? _opt['selected'] = true : 0; (_ === ext) ? _opt['selected'] = true: 0;
_options.push(_opt); _options.push(_opt);
} }
toolbar.loadStruct([ toolbar.loadStruct([{
{ id: 'hinttext', type: 'text', text: hinttext}, id: 'hinttext',
{ type: 'separator' }, type: 'text',
{ type: 'spacer' }, text: hinttext
{ id: 'save', type: 'button', icon: 'save', text: LANG['editor']['toolbar']['save'] }, },
{ type: 'separator' }, {
type: 'separator'
},
{
type: 'spacer'
},
{
id: 'save',
type: 'button',
icon: 'save',
text: LANG['editor']['toolbar']['save']
},
{
type: 'separator'
},
{ {
id: 'encode', type: 'buttonSelect', icon: 'language', openAll: true, id: 'encode',
type: 'buttonSelect',
icon: 'language',
openAll: true,
text: LANG['editor']['toolbar']['encode'], text: LANG['editor']['toolbar']['encode'],
options: (() => { options: (() => {
let ret = []; let ret = [];
...@@ -880,7 +979,10 @@ class FileManager { ...@@ -880,7 +979,10 @@ class FileManager {
return ret; return ret;
})() })()
}, { }, {
id: 'mode', type: 'buttonSelect', icon: 'th-list', openAll: true, id: 'mode',
type: 'buttonSelect',
icon: 'th-list',
openAll: true,
text: LANG['editor']['toolbar']['mode'], text: LANG['editor']['toolbar']['mode'],
options: _options options: _options
}, },
...@@ -901,19 +1003,19 @@ class FileManager { ...@@ -901,19 +1003,19 @@ class FileManager {
toastr.success(LANG['editor']['success'](path), LANG_T['success']); toastr.success(LANG['editor']['success'](path), LANG_T['success']);
// 刷新目录(显示更改时间、大小等) // 刷新目录(显示更改时间、大小等)
self.files.refreshPath(); self.files.refreshPath();
}else{ } else {
toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br/>' + ret), LANG_T['error']); toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br/>' + ret), LANG_T['error']);
} }
}).catch((err) => { }).catch((err) => {
}); });
}else if (id.startsWith('mode_')) { } else if (id.startsWith('mode_')) {
let mode = id.split('_')[1]; let mode = id.split('_')[1];
editor.session.setMode(`ace/mode/${mode}`); editor.session.setMode(`ace/mode/${mode}`);
}else if (id.startsWith('encode_')) { } else if (id.startsWith('encode_')) {
let encode = id.split('_')[1]; let encode = id.split('_')[1];
editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString()); editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString());
}else{ } else {
console.info('toolbar.onClick', id); console.info('toolbar.onClick', id);
} }
}); });
...@@ -927,7 +1029,7 @@ class FileManager { ...@@ -927,7 +1029,7 @@ class FileManager {
let ret = res['text']; let ret = res['text'];
codes = res['buff']; codes = res['buff'];
let encoding = res['encoding'] || this.opts['encode']; let encoding = res['encoding'] || this.opts['encode'];
if(encoding.toUpperCase() == "UTF-8") { if (encoding.toUpperCase() == "UTF-8") {
encoding = "UTF8"; encoding = "UTF8";
} }
toolbar.setListOptionSelected('encode', `encode_${encoding}`); toolbar.setListOptionSelected('encode', `encode_${encoding}`);
......
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