Commit a10727c3 authored by Medicean's avatar Medicean

(Enhance:FileManager) 多文件下载

parent 22700479
......@@ -19,18 +19,18 @@ class Files {
let bookmark = JSON.parse(manager.storage('bookmarks').get('{}'));
// 重新加载书签
this.reloadToolbar = () => {
let bookmark_opts = [
{
id: 'bookmark_add',
type: 'button',
icon: 'plus-circle',
text: LANG['bookmark']['add'],
enabled: !bookmark[manager.path]
}
];
let bookmark_opts = [{
id: 'bookmark_add',
type: 'button',
icon: 'plus-circle',
text: LANG['bookmark']['add'],
enabled: !bookmark[manager.path]
}];
let global_bookmarks = manager.config.bookmarks || {};
if (Object.keys(global_bookmarks).length > 0) {
bookmark_opts.push({type: 'separator'});
bookmark_opts.push({
type: 'separator'
});
for (let gb in global_bookmarks) {
bookmark_opts.push({
id: 'bookmark_' + global_bookmarks[gb],
......@@ -42,7 +42,9 @@ class Files {
}
}
if (!$.isEmptyObject(bookmark)) {
bookmark_opts.push({type: 'separator'});
bookmark_opts.push({
type: 'separator'
});
};
for (let _ in bookmark) {
bookmark_opts.push({
......@@ -55,7 +57,9 @@ class Files {
}
// 添加清除按钮
if (bookmark_opts.length > 2) {
bookmark_opts.push({type: 'separator'});
bookmark_opts.push({
type: 'separator'
});
bookmark_opts.push({
id: 'bookmark_remove',
icon: 'remove',
......@@ -63,88 +67,89 @@ class Files {
type: 'button',
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.loadStruct([
{
id: 'new',
type: 'buttonSelect',
icon: 'plus-circle',
text: LANG['toolbar']['new'],
openAll: true,
options: [
{
id: 'new_folder',
icon: 'folder-o',
type: 'button',
text: LANG['toolbar']['folder']
}, {
id: 'new_file',
icon: 'file-o',
type: 'button',
text: LANG['toolbar']['file']
}, {
type: 'separator'
}, {
id: 'new_wget',
icon: 'cloud-download',
type: 'button',
text: LANG['toolbar']['wget']
}, {
id: 'new_upload',
icon: 'cloud-upload',
type: 'button',
text: LANG['toolbar']['upload']
}
]
}, {
type: 'separator'
}, {
id: 'up',
toolbar.loadStruct([{
id: 'new',
type: 'buttonSelect',
icon: 'plus-circle',
text: LANG['toolbar']['new'],
openAll: true,
options: [{
id: 'new_folder',
icon: 'folder-o',
type: 'button',
icon: 'arrow-up',
text: LANG['toolbar']['up']
text: LANG['toolbar']['folder']
}, {
type: 'separator'
}, {
id: 'refresh',
id: 'new_file',
icon: 'file-o',
type: 'button',
icon: 'refresh',
text: LANG['toolbar']['refresh']
text: LANG['toolbar']['file']
}, {
type: 'separator'
}, {
id: 'home',
id: 'new_wget',
icon: 'cloud-download',
type: 'button',
icon: 'home',
text: LANG['toolbar']['home']
}, {
type: 'separator'
text: LANG['toolbar']['wget']
}, {
id: 'bookmark',
type: 'buttonSelect',
icon: 'bookmark',
text: LANG['toolbar']['bookmark'],
openAll: true,
options: bookmark_opts
}, {
type: 'separator'
}, {
id: 'path',
width: 300,
type: 'buttonInput',
value: antSword.noxss(manager.path) || 'loading..'
}, {
id: 'read_path',
id: 'new_upload',
icon: 'cloud-upload',
type: 'button',
icon: 'arrow-right',
text: LANG['toolbar']['read']
}, {
type: 'separator'
}
]);
text: LANG['toolbar']['upload']
}]
}, {
type: 'separator'
}, {
id: 'up',
type: 'button',
icon: 'arrow-up',
text: LANG['toolbar']['up']
}, {
type: 'separator'
}, {
id: 'refresh',
type: 'button',
icon: 'refresh',
text: LANG['toolbar']['refresh']
}, {
type: 'separator'
}, {
id: 'home',
type: 'button',
icon: 'home',
text: LANG['toolbar']['home']
}, {
type: 'separator'
}, {
id: 'bookmark',
type: 'buttonSelect',
icon: 'bookmark',
text: LANG['toolbar']['bookmark'],
openAll: true,
options: bookmark_opts
}, {
type: 'separator'
}, {
id: 'path',
width: 300,
type: 'buttonInput',
value: antSword.noxss(manager.path) || 'loading..'
}, {
id: 'read_path',
type: 'button',
icon: 'arrow-right',
text: LANG['toolbar']['read']
}, {
type: 'separator'
}]);
}
this.reloadToolbar();
......@@ -258,9 +263,8 @@ class Files {
grid.enableMultiselect(true);
// grid.enableDragAndDrop(true); grid.enableMultiline(true); grid右键 空白数据右键fix
$('.objbox').on('contextmenu', (e) => {
(e.target.nodeName === 'DIV' && grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab().startsWith('tab_filemanager_'))
? grid.callEvent('onRightClick', [-1, -1, e])
: null;
(e.target.nodeName === 'DIV' && grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab().startsWith('tab_filemanager_')) ?
grid.callEvent('onRightClick', [-1, -1, e]): null;
});
$('.objbox').on('click', (e) => {
bmenu.hide();
......@@ -289,9 +293,9 @@ class Files {
for (let c in self.Clipboard) {
_Clipboard.push({
text: antSword.noxss(c),
icon: 'fa fa-' + (c.endsWith('/')
? 'folder-o'
: 'file-o'),
icon: 'fa fa-' + (c.endsWith('/') ?
'folder-o' :
'file-o'),
action: ((source, name) => {
return () => {
manager.pasteFile(source, name);
......@@ -300,14 +304,19 @@ class Files {
});
_Clipboard_num++;
if (!(_Clipboard_num % 5)) {
_Clipboard.push({divider: true});
_Clipboard.push({
divider: true
});
};
}
// 清除最后的divider if (_Clipboard.length % 5 && _Clipboard_num > 5) {
// _Clipboard.pop() }; all item
if (_Clipboard.length > 0) {
_Clipboard.unshift({divider: true});
_Clipboard.unshift({text: LANG['grid']['contextmenu']['paste']['all'],
_Clipboard.unshift({
divider: true
});
_Clipboard.unshift({
text: LANG['grid']['contextmenu']['paste']['all'],
count: _Clipboard_num,
icon: 'fa fa-th-list',
action: () => {
......@@ -325,10 +334,12 @@ class Files {
}
});
// 清空剪贴板
!(_Clipboard[_Clipboard.length - 1].divider)
? _Clipboard.push({divider: true})
: 0;
_Clipboard.push({text: LANG['grid']['contextmenu']['paste']['clear']['title'],
!(_Clipboard[_Clipboard.length - 1].divider) ?
_Clipboard.push({
divider: true
}): 0;
_Clipboard.push({
text: LANG['grid']['contextmenu']['paste']['clear']['title'],
icon: 'fa fa-trash-o',
action: () => {
self.Clipboard = {};
......@@ -338,190 +349,196 @@ class Files {
};
let isFolder = id.endsWith('/');
let containsFolder = (ids.join("~assep~") + '~assep~').indexOf('/~assep~') > -1;
// 可编辑文件后缀
let isEdited = false;
'php,asp,aspx,jsp,cfm,js,css,html,py,sh,bat,txt,log,ini,conf,sql'
.split(',')
.split(',')
.map((e) => {
id
.toLowerCase()
.endsWith(`.${e}`)
? isEdited = true
: 0;
.endsWith(`.${e}`) ?
isEdited = true :
0;
});
let menu = [
{
text: LANG['grid']['contextmenu']['refresh'],
icon: 'fa fa-refresh',
action: () => {
self.refreshPath();
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['wget'],
icon: 'fa fa-cloud-download',
action: manager
.wgetFile
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['upload'],
icon: 'fa fa-upload',
action: manager
.uploadFile
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['download'],
icon: 'fa fa-download',
disabled: isFolder || !id || ids.length > 1,
action: () => {
let menu = [{
text: LANG['grid']['contextmenu']['refresh'],
icon: 'fa fa-refresh',
action: () => {
self.refreshPath();
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['wget'],
icon: 'fa fa-cloud-download',
action: manager
.wgetFile
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['upload'],
icon: 'fa fa-upload',
action: manager
.uploadFile
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['download'],
icon: 'fa fa-download',
disabled: isFolder || !id || containsFolder,
action: () => {
if (ids.length === 1) {
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'],
icon: 'fa fa-copy',
subMenu: [{
text: LANG['grid']['contextmenu']['copy']['title'],
icon: 'fa fa-copy',
subMenu: [
{
text: LANG['grid']['contextmenu']['copy']['title'],
icon: 'fa fa-copy',
disabled: !id,
action: () => {
// 如果只有一个id,则显示id名称,否则显示ids数量
ids.map((id) => {
let path = manager.path + id;
// 判断是否已经复制
if (id in self.Clipboard) {
return toastr.warning(LANG['grid']['contextmenu']['copy']['warning'](id), LANG_T['warning']);
};
self.Clipboard[id] = path;
toastr.info(LANG['grid']['contextmenu']['copy']['info'](id), LANG_T['info']);
});
}
}, {
text: LANG['grid']['contextmenu']['copy']['copyname'],
icon: 'fa fa-file-word-o',
disabled: !id || ids.length > 1,
action: () => {
clipboard.writeText(id);
// 检测是否复制成功
let txt = clipboard.readText();
if (txt == id) {
toastr.success(LANG['grid']['contextmenu']['copy']['copysuccess'], LANG_T['success']);
} else {
toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']);
}
}
}, {
text: LANG['grid']['contextmenu']['copy']['copypath'],
icon: 'fa fa-file-powerpoint-o',
disabled: !id || ids.length > 1,
action: () => {
let txt = `${self.manager.path}${id}`;
clipboard.writeText(txt);
// 检测是否复制成功
let cptxt = clipboard.readText();
if (cptxt == txt) {
toastr.success(LANG['grid']['contextmenu']['copy']['copysuccess'], LANG_T['success']);
} else {
toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']);
}
}
}
]
}, {
text: LANG['grid']['contextmenu']['paste']['title'],
icon: 'fa fa-paste',
disabled: _Clipboard_num === 0,
subMenu: _Clipboard
}, {
text: LANG['grid']['contextmenu']['preview'],
icon: 'fa fa-eye',
disabled: !id || ids.length > 1 || !self.checkPreview(id),
action: () => {
manager.previewFile(id, this.getRowAttribute(_ids[0], 'fsize'));
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['edit']['title'],
icon: 'fa fa-edit',
disabled:/*!isEdited || */
!id || ids.length > 1 || isFolder,
subMenu: [
{
text: LANG['grid']['contextmenu']['edit']['opentab'],
icon: 'fa fa-external-link',
action: () => {
manager.editFile(id, true);
}
}, {
text: LANG['grid']['contextmenu']['edit']['openwindow'],
icon: 'fa fa-arrows-alt',
action: () => {
manager.editFile(id, false);
}
}
]
}, {
text: LANG['grid']['contextmenu']['delete'],
icon: 'fa fa-trash-o',
disabled: !id,
action: () => {
manager.deleteFile(ids);
// 如果只有一个id,则显示id名称,否则显示ids数量
ids.map((id) => {
let path = manager.path + id;
// 判断是否已经复制
if (id in self.Clipboard) {
return toastr.warning(LANG['grid']['contextmenu']['copy']['warning'](id), LANG_T['warning']);
};
self.Clipboard[id] = path;
toastr.info(LANG['grid']['contextmenu']['copy']['info'](id), LANG_T['info']);
});
}
}, {
text: LANG['grid']['contextmenu']['rename'],
icon: 'fa fa-font',
text: LANG['grid']['contextmenu']['copy']['copyname'],
icon: 'fa fa-file-word-o',
disabled: !id || ids.length > 1,
action: () => {
manager.renameFile(id);
clipboard.writeText(id);
// 检测是否复制成功
let txt = clipboard.readText();
if (txt == id) {
toastr.success(LANG['grid']['contextmenu']['copy']['copysuccess'], LANG_T['success']);
} else {
toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']);
}
}
}, {
text: LANG['grid']['contextmenu']['modify'],
icon: 'fa fa-clock-o',
text: LANG['grid']['contextmenu']['copy']['copypath'],
icon: 'fa fa-file-powerpoint-o',
disabled: !id || ids.length > 1,
action: () => {
// manager.retimeFile(id, this.rowsAr[id]['cells'][2].innerText);
manager.retimeFile(id, this.getRowAttribute(_ids[0], 'data')[2]);
let txt = `${self.manager.path}${id}`;
clipboard.writeText(txt);
// 检测是否复制成功
let cptxt = clipboard.readText();
if (cptxt == txt) {
toastr.success(LANG['grid']['contextmenu']['copy']['copysuccess'], LANG_T['success']);
} else {
toastr.error(LANG['grid']['contextmenu']['copy']['copyfail'], LANG_T['error']);
}
}
}, {
text: LANG['grid']['contextmenu']['chmod'],
icon: 'fa fa-users',
disabled: !id || ids.length > 1,
}]
}, {
text: LANG['grid']['contextmenu']['paste']['title'],
icon: 'fa fa-paste',
disabled: _Clipboard_num === 0,
subMenu: _Clipboard
}, {
text: LANG['grid']['contextmenu']['preview'],
icon: 'fa fa-eye',
disabled: !id || ids.length > 1 || !self.checkPreview(id),
action: () => {
manager.previewFile(id, this.getRowAttribute(_ids[0], 'fsize'));
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['edit']['title'],
icon: 'fa fa-edit',
disabled: /*!isEdited || */
!id || ids.length > 1 || isFolder,
subMenu: [{
text: LANG['grid']['contextmenu']['edit']['opentab'],
icon: 'fa fa-external-link',
action: () => {
manager.chmodFile(id, this.getRowAttribute(_ids[0], 'data')[4]);
manager.editFile(id, true);
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['create']['title'],
icon: 'fa fa-plus-circle',
subMenu: [
{
text: LANG['grid']['contextmenu']['create']['folder'],
icon: 'fa fa-folder-o',
action: manager
.createFolder
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['create']['file'],
icon: 'fa fa-file-o',
action: manager
.createFile
.bind(manager)
}
]
}, {
text: LANG['grid']['contextmenu']['terminal'],
icon: 'fa fa-terminal',
text: LANG['grid']['contextmenu']['edit']['openwindow'],
icon: 'fa fa-arrows-alt',
action: () => {
new Terminal(self.manager.opts, {'path': self.manager.path});
manager.editFile(id, false);
}
}]
}, {
text: LANG['grid']['contextmenu']['delete'],
icon: 'fa fa-trash-o',
disabled: !id,
action: () => {
manager.deleteFile(ids);
}
];
}, {
text: LANG['grid']['contextmenu']['rename'],
icon: 'fa fa-font',
disabled: !id || ids.length > 1,
action: () => {
manager.renameFile(id);
}
}, {
text: LANG['grid']['contextmenu']['modify'],
icon: 'fa fa-clock-o',
disabled: !id || ids.length > 1,
action: () => {
// manager.retimeFile(id, this.rowsAr[id]['cells'][2].innerText);
manager.retimeFile(id, this.getRowAttribute(_ids[0], 'data')[2]);
}
}, {
text: LANG['grid']['contextmenu']['chmod'],
icon: 'fa fa-users',
disabled: !id || ids.length > 1,
action: () => {
manager.chmodFile(id, this.getRowAttribute(_ids[0], 'data')[4]);
}
}, {
divider: true
}, {
text: LANG['grid']['contextmenu']['create']['title'],
icon: 'fa fa-plus-circle',
subMenu: [{
text: LANG['grid']['contextmenu']['create']['folder'],
icon: 'fa fa-folder-o',
action: manager
.createFolder
.bind(manager)
}, {
text: LANG['grid']['contextmenu']['create']['file'],
icon: 'fa fa-file-o',
action: manager
.createFile
.bind(manager)
}]
}, {
text: LANG['grid']['contextmenu']['terminal'],
icon: 'fa fa-terminal',
action: () => {
new Terminal(self.manager.opts, {
'path': self.manager.path
});
}
}];
bmenu(menu, event);
......@@ -554,7 +571,7 @@ class Files {
// 键盘按下事件
grid.attachEvent('onKeyPress', (code, cFlag, sFlag) => {
switch (true) {
case(code <= 90 && code >= 65) || (code <= 57 && code >= 48):
case (code <= 90 && code >= 65) || (code <= 57 && code >= 48):
// A-Z 0-9
var input = String.fromCharCode(code);
input = input.toLowerCase();
......@@ -572,7 +589,7 @@ class Files {
}
}
break
case(code == 38):
case (code == 38):
//up
var ids = grid
.getAllRowIds()
......@@ -580,12 +597,12 @@ class Files {
var sid = grid
.getSelectedRowId()
.toString();
var cid = ids.indexOf(sid) <= 0
? parseInt(ids[0]) - 1
: parseInt(ids[ids.indexOf(sid) - 1]) - 1;
var cid = ids.indexOf(sid) <= 0 ?
parseInt(ids[0]) - 1 :
parseInt(ids[ids.indexOf(sid) - 1]) - 1;
grid.selectRow(cid);
break;
case(code == 40):
case (code == 40):
//down
var ids = grid
.getAllRowIds()
......@@ -593,9 +610,9 @@ class Files {
var sid = grid
.getSelectedRowId()
.toString();
var cid = ids.indexOf(sid) >= ids.length - 1
? parseInt(ids[ids.length - 1]) - 1
: parseInt(ids[ids.indexOf(sid) + 1]) - 1;
var cid = ids.indexOf(sid) >= ids.length - 1 ?
parseInt(ids[ids.length - 1]) - 1 :
parseInt(ids[ids.indexOf(sid) + 1]) - 1;
grid.selectRow(cid);
break;
default:
......@@ -643,13 +660,13 @@ class Files {
// 可预览文件后缀
let isPreviewed = false;
'jpeg,jpg,png,gif,bmp,ico'
.split(',')
.split(',')
.map((e) => {
name
.toLowerCase()
.endsWith(`.${e}`)
? isPreviewed = true
: 0;
.endsWith(`.${e}`) ?
isPreviewed = true :
0;
});
return isPreviewed;
}
......@@ -713,9 +730,8 @@ class Files {
fname: file['name'],
fsize: parseInt(file['size']),
// 如果是可执行文件(exe、dll..),则设置为红色字体
style: /\.exe$|\.dll$|\.bat$|\.sh$|\.com$/.test(file['name'])
? 'color:red'
: '',
style: /\.exe$|\.dll$|\.bat$|\.sh$|\.com$/.test(file['name']) ?
'color:red' : '',
data: [
self.fileIcon(file['name']),
antSword.noxss(file['name'].replace(/\/$/, '')),
......@@ -763,12 +779,12 @@ class Files {
"Pb",
"Eb"
];
for (let q = 0; q < b.length; q++)
if (t > 1024)
for (let q = 0; q < b.length; q++)
if (t > 1024)
t = t / 1024;
else if (i === false)
i = q;
if (i === false)
else if (i === false)
i = q;
if (i === false)
i = b.length - 1;
return Math.round(t * 100) / 100 + " " + b[i];
}
......@@ -811,4 +827,4 @@ class Files {
}
// export default Files;
module.exports = Files;
module.exports = Files;
\ No newline at end of file
......@@ -43,7 +43,7 @@ class FileManager {
openfileintab: false,
bookmarks: {},
};
this.config = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(config)));
this.isWin = true;
this.path = '/';
......@@ -61,7 +61,7 @@ class FileManager {
const cache_info = this.cache.get('info');
if (cache_info) {
this.initUI(cache_info);
}else{
} else {
this.cell.progressOn();
this.core.request(
this.core.base.info()
......@@ -71,7 +71,7 @@ class FileManager {
}).catch((err) => {
this.cell.progressOff();
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.initUI(ret);
......@@ -98,7 +98,7 @@ class FileManager {
// 判断是否为linux
if (info_path.substr(0, 1) === '/') {
this.isWin = false;
}else{
} else {
// windows 盘符统一大写
info_path = `${info_path.substr(0,1).toUpperCase()}${info_path.substr(1)}`;
info_drive = info_drive.toUpperCase();
......@@ -106,7 +106,9 @@ class FileManager {
this.path = info_path;
this.home = info_path;
info_drive.split(':').map((_) => {
if (!_) { return };
if (!_) {
return
};
this.devices.push(_ === '/' ? _ : _ + ':/');
});
......@@ -141,17 +143,19 @@ class FileManager {
getFiles(p, callback) {
let self = this;
if(self.isWin) { // 处理输入为 f:\ 这种情况
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;
if (self.isWin) { // 处理输入为 f: 这种情况
path = path.substr(1, 2) == ":/" ? `${path.substr(0,1).toUpperCase()}${path.substr(1)}` : path;
}
let cache;
if (!path.endsWith('/')) { path += '/' };
if (!path.endsWith('/')) {
path += '/'
};
this.path = path;
let cache_tag = 'filemanager-files-' + Buffer.from(this.path).toString('base64');
......@@ -181,7 +185,7 @@ class FileManager {
let folders = [];
let files = [];
tmp.map( (t) => {
tmp.map((t) => {
let _ = t.split('\t');
let d = {
name: _[0],
......@@ -191,10 +195,10 @@ class FileManager {
}
if (_[0].endsWith('/')) {
folders.push(d);
}else{
} else {
files.push(d);
}
} );
});
let data = folders.concat(files);
callback(data);
......@@ -258,24 +262,24 @@ class FileManager {
// 如果是当前目录,返回
if (path === './') {
return this.path;
// 如果是上级目录,则判断是否为最后一级?返回最后一级:返回上一级
}else if (path === '../') {
// 如果是上级目录,则判断是否为最后一级?返回最后一级:返回上一级
} else if (path === '../') {
let _ = this.path.split('/');
if (_.length === 2) {
return _.join('/');
}else if (_.length > 2) {
} else if (_.length > 2) {
_.pop();
_.pop();
_.length === 1 ? _.push('') : 0;
return _.join('/');
}else{
} else {
return this.path;
}
// 如果是根目录,返回
}else if (path.startsWith('/') || path.substr(1, 2) === ':/') {
// 如果是根目录,返回
} else if (path.startsWith('/') || path.substr(1, 2) === ':/') {
return path;
// 如果是相对路径,返回绝对全路径
}else{
// 如果是相对路径,返回绝对全路径
} else {
return this.path + path;
}
}
......@@ -310,7 +314,7 @@ class FileManager {
if (ret === '1') {
toastr.success(LANG['delete']['success'](path), LANG_T['success']);
this.files.refreshPath();
}else{
} else {
toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -360,7 +364,7 @@ class FileManager {
// 删除缓存
delete this.files.Clipboard[name];
toastr.success(LANG['paste']['success'](name), LANG_T['success']);
}else{
} else {
toastr.error(LANG['paste']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -387,7 +391,7 @@ class FileManager {
if (ret === '1') {
this.files.refreshPath();
toastr.success(LANG['rename']['success'], LANG_T['success']);
}else{
} else {
toastr.error(LANG['rename']['error'](ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -414,7 +418,7 @@ class FileManager {
if (ret === '1') {
this.files.refreshPath();
toastr.success(LANG['createFolder']['success'](value), LANG_T['success']);
}else{
} else {
toastr.error(LANG['createFolder']['error'](value, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -444,7 +448,7 @@ class FileManager {
if (ret === '1') {
this.files.refreshPath();
toastr.success(LANG['createFile']['success'](value), LANG_T['success']);
}else{
} else {
toastr.error(LANG['createFile']['error'](value, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -464,7 +468,7 @@ class FileManager {
this.files.cell.progressOn();
let path = this.path;
if (this.isWin) {
path = path.replace(/\//g, '\\')
path = path.replace(/\//g, '\\')
}
// http request
this.core.request(
......@@ -479,7 +483,7 @@ class FileManager {
if (ret === '1') {
this.files.refreshPath();
toastr.success(LANG['retime']['success'](name), LANG_T['success']);
}else{
} else {
toastr.error(LANG['retime']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -495,7 +499,7 @@ class FileManager {
value: antSword.noxss(oldmod),
title: `<i class="fa fa-users"></i> ${LANG['chmod']['title']} (${antSword.noxss(name)})`,
}, (value, i, e) => {
if(!value.match(/^[0-7]{4}$/)){
if (!value.match(/^[0-7]{4}$/)) {
toastr.error(LANG['chmod']['check'], LANG_T['error']);
return
}
......@@ -516,7 +520,7 @@ class FileManager {
if (ret === '1') {
this.files.refreshPath();
toastr.success(LANG['chmod']['success'](name), LANG_T['success']);
}else{
} else {
toastr.error(LANG['chmod']['error'](name, ret === '0' ? false : ret), LANG_T['error']);
}
}).catch((err) => {
......@@ -536,15 +540,15 @@ class FileManager {
height: 600,
});
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']['textAlign'] = 'center';
let down_size = 0;
this.core.download(
savepath
,this.core.filemanager.download_file({path: remote_path})
, (_size) => {
savepath, this.core.filemanager.download_file({
path: remote_path
}), (_size) => {
down_size += _size;
let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100);
if (!(down_progress % 5)) {
......@@ -555,14 +559,14 @@ class FileManager {
if (_size === size) {
win.setText(`Preview File: ${antSword.noxss(remote_path)}`);
let buff = fs.readFileSync(savepath);
switch (filemime){
switch (filemime) {
default:
let data = Buffer.from(buff).toString('base64');
win.attachHTMLString(`<img style="width:100%" src="data:/${filemime};base64,${data}"/>`);
break;
}
fs.unlink(savepath);
}else{
} else {
fs.unlink(savepath);
throw Error(`Load Error: downsize ${_size} != ${size}`);
}
......@@ -574,13 +578,15 @@ class FileManager {
// 下载文件
downloadFile(name, size) {
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({
title: LANG['download']['title'],
defaultPath: name
}, (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']);
let down_size = 0;
// 删除旧文件(如果存在
......@@ -588,11 +594,9 @@ class FileManager {
fs.unlinkSync(filePath);
}
this.core.download(
filePath
, this.core.filemanager.download_file({
filePath, this.core.filemanager.download_file({
path: path
})
, (_size) => {
}), (_size) => {
// 计算进度百分比
down_size += _size;
let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100);
......@@ -605,9 +609,9 @@ class FileManager {
if (_size === 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{
// }else if (_size === 21) {
// task.failed('len=' + _size);
} else {
throw Error(`SizeErr: ${_size} != ${size}`);
// task.failed(LANG['download']['task']['error']())
}
......@@ -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文件
wgetFile() {
let self = this;
......@@ -658,7 +716,7 @@ class FileManager {
task.success(LANG['wget']['task']['success']);
let _ = path.substr(0, path.lastIndexOf('/') + 1);
this.files.refreshPath((_ === self.path) ? false : _);
}else{
} else {
task.failed(LANG['wget']['task']['failed'](ret));
}
}).catch((err) => {
......@@ -686,9 +744,11 @@ class FileManager {
return res(_filePaths);
}
dialog.showOpenDialog({
properties: [ 'openFile', 'multiSelections' ]
properties: ['openFile', 'multiSelections']
}, (_filePaths) => {
if (!_filePaths) { return };
if (!_filePaths) {
return
};
return res(_filePaths);
})
}).then((filePaths) => {
......@@ -713,7 +773,7 @@ class FileManager {
let buff = [];
// 分段上传大小,默认0.5M(jsp 超过1M响应会出错)
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;
}
let task = tasks[filePath];
......@@ -739,7 +799,7 @@ class FileManager {
let _b = _buff.shift();
if (_b) {
res(_b);
}else{
} else {
// 上传完毕
task.success(LANG['upload']['task']['success']);
toastr.success(LANG['upload']['success'](fileName), LANG_T['success']);
......@@ -771,15 +831,15 @@ class FileManager {
let errmsg = err;
if (err.hasOwnProperty('status') && err.hasOwnProperty('response')) {
errmsg = `${err.status} ${err.response.res.statusMessage}`;
switch(err.status) {
switch (err.status) {
case 413:
errmsg += `${LANG['upload']['task']['httperr_413']}`;
break;
default:
break;
}
}else if(err.hasOwnProperty('errno')) {
switch(err.errno) {
} else if (err.hasOwnProperty('errno')) {
switch (err.errno) {
case 'ETIME':
errmsg = `${LANG['upload']['task']['httperr_etime']}`;
break;
......@@ -804,20 +864,20 @@ class FileManager {
}
// 编辑文件
editFile(name, openfileintab=false) {
editFile(name, openfileintab = false) {
let self = this;
let path = this.path + name;
let editor = null;
let codes = '';
let win;
let hinttext = '';
if (openfileintab == false){
if (openfileintab == false) {
win = this.createWin({
title: LANG['editor']['title'](antSword.noxss(path)),
width: 800
});
win.maximize();
}else{
win.maximize();
} else {
let _id = String(Math.random()).substr(5, 10);
antSword['tabbar'].addTab(
`tab_file_${_id}`,
......@@ -833,15 +893,37 @@ class FileManager {
// 检测文件后缀
let ext = name.substr(name.lastIndexOf('.') + 1);
let ext_dict = {
'php': 'php', 'c': 'c_cpp', 'cpp': 'c_cpp', 'h': 'c_cpp',
'coffee': 'coffee', 'cfm': 'coldfusion', 'css': 'css',
'go': 'golang', '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'
'php': 'php',
'c': 'c_cpp',
'cpp': 'c_cpp',
'h': 'c_cpp',
'coffee': 'coffee',
'cfm': 'coldfusion',
'css': 'css',
'go': 'golang',
'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' };
if (!(ext in ext_dict)) {
ext = 'txt'
};
// 创建窗口工具栏
let toolbar = win.attachToolbar();
let _options = [];
......@@ -853,17 +935,34 @@ 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},
{ type: 'separator' },
{ type: 'spacer' },
{ id: 'save', type: 'button', icon: 'save', text: LANG['editor']['toolbar']['save'] },
{ type: 'separator' },
toolbar.loadStruct([{
id: 'hinttext',
type: 'text',
text: hinttext
},
{
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'],
options: (() => {
let ret = [];
......@@ -880,7 +979,10 @@ class FileManager {
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'],
options: _options
},
......@@ -901,19 +1003,19 @@ class FileManager {
toastr.success(LANG['editor']['success'](path), LANG_T['success']);
// 刷新目录(显示更改时间、大小等)
self.files.refreshPath();
}else{
} else {
toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br/>' + ret), LANG_T['error']);
}
}).catch((err) => {
});
}else if (id.startsWith('mode_')) {
} else if (id.startsWith('mode_')) {
let mode = id.split('_')[1];
editor.session.setMode(`ace/mode/${mode}`);
}else if (id.startsWith('encode_')) {
} else if (id.startsWith('encode_')) {
let encode = id.split('_')[1];
editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString());
}else{
} else {
console.info('toolbar.onClick', id);
}
});
......@@ -927,7 +1029,7 @@ class FileManager {
let ret = res['text'];
codes = res['buff'];
let encoding = res['encoding'] || this.opts['encode'];
if(encoding.toUpperCase() == "UTF-8") {
if (encoding.toUpperCase() == "UTF-8") {
encoding = "UTF8";
}
toolbar.setListOptionSelected('encode', `encode_${encoding}`);
......@@ -979,9 +1081,9 @@ class FileManager {
let _id = String(Math.random()).substr(5, 10);
// 默认配置
let opt = $.extend({
title: 'Window:' + _id,
width: 660,
height: 550
title: 'Window:' + _id,
width: 660,
height: 550
}, opts);
// 创建窗口
......@@ -998,4 +1100,4 @@ class FileManager {
}
// export default FileManager;
module.exports = FileManager;
module.exports = FileManager;
\ No newline at end of file
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