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
fabade03
Commit
fabade03
authored
Aug 16, 2018
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v2.0::Picture preview
parent
dc237eae
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
26 deletions
+63
-26
config.js
modules/config.js
+4
-0
files.js
source/modules/filemanager/files.js
+23
-12
index.js
source/modules/filemanager/index.js
+36
-14
No files found.
modules/config.js
View file @
fabade03
...
...
@@ -34,6 +34,10 @@ class Conf {
fs
.
readFileSync
(
_oldPath
)
)
}
// 初始化目录
this
.
tmpPath
;
this
.
cachePath
;
this
.
plugPath
;
}
/**
...
...
source/modules/filemanager/files.js
View file @
fabade03
...
...
@@ -283,13 +283,6 @@ class Files {
id
.
toLowerCase
().
endsWith
(
`.
${
e
}
`
)
?
isEdited
=
true
:
0
;
}
);
// 可预览文件后缀
let
isPreviewed
=
false
;
'jpg,png,gif,bmp,ico,mp4,mp3,wav,avi,rmvb'
.
split
(
','
).
map
(
(
e
)
=>
{
id
.
toLowerCase
().
endsWith
(
`.
${
e
}
`
)
?
isPreviewed
=
true
:
0
;
}
);
let
menu
=
[
{
text
:
LANG
[
'grid'
][
'contextmenu'
][
'refresh'
],
icon
:
'fa fa-refresh'
,
action
:
()
=>
{
self
.
refreshPath
();
}
},
...
...
@@ -313,9 +306,9 @@ class Files {
}
);
}
},
{
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 || !isPreviewed
, action: () => {
// manager.previewFile(id
);
//
} },
{
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'
],
icon
:
'fa fa-edit'
,
disabled
:
/*!isEdited || */
!
id
||
ids
.
length
>
1
||
isFolder
,
action
:
()
=>
{
manager
.
editFile
(
id
);
...
...
@@ -348,13 +341,20 @@ class Files {
});
// 双击文件
// :如果可预览并且小于 1MB,则进行预览
// :如果size < 100kb,则进行编辑,否则进行下载
grid
.
attachEvent
(
'onRowDblClicked'
,
(
id
,
lid
,
event
)
=>
{
const
fname
=
grid
.
getRowAttribute
(
id
,
'fname'
);
const
fsize
=
grid
.
getRowAttribute
(
id
,
'fsize'
);
if
(
!
fname
.
endsWith
(
'/'
))
{
if
(
self
.
checkPreview
(
fname
)
&&
fsize
<=
1000
*
1024
){
manager
.
previewFile
(
fname
,
fsize
);
}
else
if
(
fsize
<=
100
*
1024
){
// 双击编辑size < 100kb 文件
fsize
<=
100
*
1024
?
manager
.
editFile
(
fname
)
:
manager
.
downloadFile
(
fname
,
fsize
);
manager
.
editFile
(
fname
);
}
else
{
manager
.
downloadFile
(
fname
,
fsize
);
}
}
else
{
self
.
gotoPath
(
fname
);
}
...
...
@@ -388,6 +388,17 @@ class Files {
});
}
checkPreview
(
name
)
{
// 可预览文件后缀
let
isPreviewed
=
false
;
'jpg,png,gif,bmp,ico'
.
split
(
','
).
map
(
(
e
)
=>
{
name
.
toLowerCase
().
endsWith
(
`.
${
e
}
`
)
?
isPreviewed
=
true
:
0
;
}
);
return
isPreviewed
;
}
// 刷新当前目录
// 如果传递路径参数,则刷新该路径下的文件,不跳转,否则刷新&&跳转
refreshPath
(
p
)
{
...
...
source/modules/filemanager/index.js
View file @
fabade03
...
...
@@ -13,6 +13,8 @@ const ENCODES = require('../../base/encodes');
const
fs
=
require
(
'fs'
);
const
iconv
=
require
(
'iconv-lite'
);
const
crypto
=
require
(
'crypto'
);
const
mime
=
require
(
"mime"
);
const
PATH
=
require
(
"path"
);
const
dialog
=
antSword
.
remote
.
dialog
;
// 加载语言模板
...
...
@@ -468,25 +470,45 @@ class FileManager {
}
// 预览文件(图片、视频)
previewFile
(
name
)
{
const
path
=
this
.
path
+
name
;
const
win
=
this
.
createWin
({
title
:
'Preview File: '
+
path
previewFile
(
name
,
size
)
{
let
that
=
this
;
const
remote_path
=
this
.
path
+
name
;
const
win
=
that
.
createWin
({
title
:
'Loading File: '
+
remote_path
,
width
:
800
,
height
:
600
,
});
var
filemime
=
mime
.
lookup
(
name
);
let
savepath
=
PATH
.
join
(
process
.
env
.
AS_WORKDIR
,
`antData/.temp/`
,
new
Buffer
(
name
).
toString
(
"hex"
));
win
.
cell
.
lastChild
[
'style'
][
'overflow'
]
=
'scroll'
;
win
.
cell
.
lastChild
[
'style'
][
'textAlign'
]
=
'center'
;
let
data
=
'data:image/png;base64,'
;
let
buff
=
''
;
this
.
core
.
request
(
this
.
core
.
filemanager
.
download_file
()
,
(
chunk
)
=>
{
buff
+=
chunk
;
let
imgData
=
data
+
new
Buffer
(
buff
).
toString
(
'base64'
);
let
down_size
=
0
;
this
.
core
.
download
(
savepath
,
this
.
core
.
filemanager
.
read_file
({
path
:
remote_path
})
,
(
_size
)
=>
{
down_size
+=
_size
;
let
down_progress
=
parseInt
(
parseFloat
(
down_size
/
size
).
toFixed
(
2
)
*
100
);
if
(
!
(
down_progress
%
5
))
{
win
.
setText
(
`Preview File:
${
remote_path
}
${
down_progress
}
%`
);
};
}
).
then
((
_size
)
=>
{
if
(
_size
===
size
)
{
win
.
setText
(
`Preview File:
${
remote_path
}
`
);
let
buff
=
fs
.
readFileSync
(
savepath
);
switch
(
filemime
){
default
:
let
data
=
new
Buffer
(
buff
).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img style="width:100%" src="data:/
${
filemime
}
;base64,
${
data
}
"/>`
);
break
;
}
fs
.
unlink
(
savepath
);
}
else
{
fs
.
unlink
(
savepath
);
throw
Error
(
`Load Error: downsize
${
_size
}
!=
${
size
}
`
);
}
).
then
((
res
)
=>
{
let
imgData
=
new
Buffer
(
res
[
'buff'
]).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
}).
catch
((
err
)
=>
{
});
...
...
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