Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
a10727c3
Commit
a10727c3
authored
Jun 10, 2019
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Enhance:FileManager) 多文件下载
parent
22700479
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
473 additions
and
355 deletions
+473
-355
files.js
source/modules/filemanager/files.js
+288
-272
index.js
source/modules/filemanager/index.js
+185
-83
No files found.
source/modules/filemanager/files.js
View file @
a10727c3
...
...
@@ -19,18 +19,18 @@ class Files {
let
bookmark
=
JSON
.
parse
(
manager
.
storage
(
'bookmarks'
).
get
(
'{}'
));
// 重新加载书签
this
.
reloadToolbar
=
()
=>
{
let
bookmark_opts
=
[
{
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,19 +67,22 @@ 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
([
{
toolbar
.
loadStruct
([{
id
:
'new'
,
type
:
'buttonSelect'
,
icon
:
'plus-circle'
,
text
:
LANG
[
'toolbar'
][
'new'
],
openAll
:
true
,
options
:
[
{
options
:
[{
id
:
'new_folder'
,
icon
:
'folder-o'
,
type
:
'button'
,
...
...
@@ -97,8 +104,7 @@ class Files {
icon
:
'cloud-upload'
,
type
:
'button'
,
text
:
LANG
[
'toolbar'
][
'upload'
]
}
]
}]
},
{
type
:
'separator'
},
{
...
...
@@ -143,8 +149,7 @@ class Files {
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,6 +349,7 @@ 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'
...
...
@@ -345,13 +357,12 @@ class Files {
.
map
((
e
)
=>
{
id
.
toLowerCase
()
.
endsWith
(
`.
${
e
}
`
)
?
isEdited
=
true
:
0
;
.
endsWith
(
`.
${
e
}
`
)
?
isEdited
=
true
:
0
;
});
let
menu
=
[
{
let
menu
=
[{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'refresh'
],
icon
:
'fa fa-refresh'
,
action
:
()
=>
{
...
...
@@ -374,17 +385,27 @@ class Files {
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'download'
],
icon
:
'fa fa-download'
,
disabled
:
isFolder
||
!
id
||
ids
.
length
>
1
,
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
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'copy'
][
'title'
],
icon
:
'fa fa-copy'
,
subMenu
:
[
{
subMenu
:
[{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'copy'
][
'title'
],
icon
:
'fa fa-copy'
,
disabled
:
!
id
,
...
...
@@ -429,8 +450,7 @@ class Files {
toastr
.
error
(
LANG
[
'grid'
][
'contextmenu'
][
'copy'
][
'copyfail'
],
LANG_T
[
'error'
]);
}
}
}
]
}]
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'paste'
][
'title'
],
icon
:
'fa fa-paste'
,
...
...
@@ -448,10 +468,9 @@ class Files {
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'edit'
][
'title'
],
icon
:
'fa fa-edit'
,
disabled
:
/*!isEdited || */
disabled
:
/*!isEdited || */
!
id
||
ids
.
length
>
1
||
isFolder
,
subMenu
:
[
{
subMenu
:
[{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'edit'
][
'opentab'
],
icon
:
'fa fa-external-link'
,
action
:
()
=>
{
...
...
@@ -463,8 +482,7 @@ class Files {
action
:
()
=>
{
manager
.
editFile
(
id
,
false
);
}
}
]
}]
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'delete'
],
icon
:
'fa fa-trash-o'
,
...
...
@@ -499,8 +517,7 @@ class Files {
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'create'
][
'title'
],
icon
:
'fa fa-plus-circle'
,
subMenu
:
[
{
subMenu
:
[{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'create'
][
'folder'
],
icon
:
'fa fa-folder-o'
,
action
:
manager
...
...
@@ -512,16 +529,16 @@ class Files {
action
:
manager
.
createFile
.
bind
(
manager
)
}
]
}]
},
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'terminal'
],
icon
:
'fa fa-terminal'
,
action
:
()
=>
{
new
Terminal
(
self
.
manager
.
opts
,
{
'path'
:
self
.
manager
.
path
});
}
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
:
...
...
@@ -647,9 +664,9 @@ class Files {
.
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
(
/
\/
$/
,
''
)),
...
...
source/modules/filemanager/index.js
View file @
a10727c3
...
...
@@ -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
);
...
...
@@ -259,23 +263,23 @@ 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
)
=>
{
...
...
@@ -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);
...
...
@@ -607,7 +611,7 @@ class FileManager {
toastr.success(LANG['
download
']['
success
'](name), LANG_T['
success
']);
// }else if (_size === 21) {
// task.failed('
len
=
' + _size);
}
else
{
}
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
{
}
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
'
}
if (!(ext in ext_dict)) { ext = '
txt
' };
'
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
'
};
// 创建窗口工具栏
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}`);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment