@electerm/electerm-react 1.34.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/client/common/auto-complete-data-mapper.js +6 -0
- package/client/common/byte-format.js +14 -0
- package/client/common/class.js +52 -0
- package/client/common/clipboard.js +49 -0
- package/client/common/constants.js +308 -0
- package/client/common/create-lang-edit-link.js +7 -0
- package/client/common/create-title.js +29 -0
- package/client/common/db-fix.js +24 -0
- package/client/common/db.js +155 -0
- package/client/common/download-mirrors.js +10 -0
- package/client/common/download.js +16 -0
- package/client/common/error-handler.jsx +27 -0
- package/client/common/fetch-from-server.js +47 -0
- package/client/common/fetch.jsx +71 -0
- package/client/common/find-bookmark-group-id.js +15 -0
- package/client/common/find-parent.js +30 -0
- package/client/common/form-layout.js +27 -0
- package/client/common/fs.js +21 -0
- package/client/common/get-proxy.js +8 -0
- package/client/common/id-with-stamp.js +10 -0
- package/client/common/index-sorter.js +4 -0
- package/client/common/init-setting-item.js +32 -0
- package/client/common/is-absolute-path.js +3 -0
- package/client/common/is-ip.js +16 -0
- package/client/common/is-valid-path.js +7 -0
- package/client/common/key-control-pressed.js +13 -0
- package/client/common/key-pressed.js +13 -0
- package/client/common/key-shift-pressed.js +7 -0
- package/client/common/mode2permission.js +81 -0
- package/client/common/new-terminal.js +31 -0
- package/client/common/parse-int10.js +3 -0
- package/client/common/parse-json-safe.js +11 -0
- package/client/common/pass-enc.js +25 -0
- package/client/common/post-msg.js +3 -0
- package/client/common/pre.js +156 -0
- package/client/common/promise-timeout.js +27 -0
- package/client/common/resolve.js +31 -0
- package/client/common/run-idle.js +1 -0
- package/client/common/safe-local-storage.js +35 -0
- package/client/common/safe-name.js +19 -0
- package/client/common/sftp.js +74 -0
- package/client/common/terminal-theme.js +158 -0
- package/client/common/test-connection.js +12 -0
- package/client/common/time.js +30 -0
- package/client/common/to-simple-obj.js +5 -0
- package/client/common/track.js +7 -0
- package/client/common/transfer.js +76 -0
- package/client/common/trzsz.js +62 -0
- package/client/common/ui-theme.js +44 -0
- package/client/common/uid.js +5 -0
- package/client/common/update-check.js +79 -0
- package/client/common/upgrade.js +68 -0
- package/client/common/wait.js +8 -0
- package/client/common/ws.js +161 -0
- package/client/components/batch-op/batch-op.jsx +650 -0
- package/client/components/bookmark-form/bookmark-form.styl +8 -0
- package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
- package/client/components/bookmark-form/encodes.js +44 -0
- package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
- package/client/components/bookmark-form/form-tabs.jsx +69 -0
- package/client/components/bookmark-form/index.jsx +159 -0
- package/client/components/bookmark-form/local-form-ui.jsx +152 -0
- package/client/components/bookmark-form/local-form.jsx +16 -0
- package/client/components/bookmark-form/proxy.jsx +49 -0
- package/client/components/bookmark-form/quick-command-list.jsx +31 -0
- package/client/components/bookmark-form/quick-command.jsx +228 -0
- package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
- package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
- package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
- package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
- package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
- package/client/components/bookmark-form/serial-form.jsx +20 -0
- package/client/components/bookmark-form/sftp-enable.jsx +33 -0
- package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
- package/client/components/bookmark-form/ssh-form.jsx +348 -0
- package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
- package/client/components/bookmark-form/telnet-form.jsx +16 -0
- package/client/components/bookmark-form/tree-delete.jsx +87 -0
- package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
- package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
- package/client/components/bookmark-form/use-submit.jsx +77 -0
- package/client/components/bookmark-form/use-ui.jsx +82 -0
- package/client/components/bookmark-form/x11.jsx +23 -0
- package/client/components/common/animate-text.jsx +37 -0
- package/client/components/common/animate-text.styl +54 -0
- package/client/components/common/external-link.jsx +28 -0
- package/client/components/common/help-icon.jsx +25 -0
- package/client/components/common/highlight.jsx +23 -0
- package/client/components/common/highlight.styl +3 -0
- package/client/components/common/input-auto-focus.jsx +68 -0
- package/client/components/common/input-confirm.jsx +66 -0
- package/client/components/common/logo-elem.jsx +22 -0
- package/client/components/common/markdown.jsx +27 -0
- package/client/components/common/react-subx.jsx +1 -0
- package/client/components/common/resize-wrap.jsx +222 -0
- package/client/components/common/resize-wrap.styl +9 -0
- package/client/components/common/search.jsx +9 -0
- package/client/components/common/show-item.jsx +27 -0
- package/client/components/context-menu/boomarks.jsx +15 -0
- package/client/components/context-menu/context-menu.jsx +340 -0
- package/client/components/context-menu/context-menu.styl +90 -0
- package/client/components/context-menu/history.jsx +27 -0
- package/client/components/context-menu/icon-holder.jsx +5 -0
- package/client/components/context-menu/menu-btn.jsx +224 -0
- package/client/components/context-menu/sub-tab-menu.jsx +23 -0
- package/client/components/context-menu/tabs.jsx +22 -0
- package/client/components/context-menu/zoom.jsx +40 -0
- package/client/components/footer/batch-input.jsx +177 -0
- package/client/components/footer/footer-entry.jsx +141 -0
- package/client/components/footer/footer.styl +47 -0
- package/client/components/icons/match-case.jsx +10 -0
- package/client/components/icons/match-whole-word.jsx +13 -0
- package/client/components/icons/regular-exp.jsx +10 -0
- package/client/components/main/css-overwrite.jsx +92 -0
- package/client/components/main/error-wrapper.jsx +59 -0
- package/client/components/main/index.jsx +11 -0
- package/client/components/main/loading.jsx +25 -0
- package/client/components/main/main.jsx +149 -0
- package/client/components/main/term-fullscreen-control.jsx +21 -0
- package/client/components/main/term-fullscreen.styl +27 -0
- package/client/components/main/ui-theme.jsx +31 -0
- package/client/components/main/upgrade.jsx +351 -0
- package/client/components/main/upgrade.styl +27 -0
- package/client/components/main/wrapper.styl +41 -0
- package/client/components/quick-commands/qm.styl +29 -0
- package/client/components/quick-commands/quick-command-item.jsx +36 -0
- package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
- package/client/components/quick-commands/quick-command-transport.jsx +12 -0
- package/client/components/quick-commands/quick-commands-box.jsx +233 -0
- package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
- package/client/components/quick-commands/quick-commands-form.jsx +33 -0
- package/client/components/quick-commands/quick-commands-list.jsx +128 -0
- package/client/components/quick-commands/quick-commands-select.jsx +38 -0
- package/client/components/session/session.jsx +533 -0
- package/client/components/session/session.styl +53 -0
- package/client/components/session/sessions.jsx +445 -0
- package/client/components/setting-panel/bookmark-transport.jsx +148 -0
- package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
- package/client/components/setting-panel/col.jsx +18 -0
- package/client/components/setting-panel/list.jsx +186 -0
- package/client/components/setting-panel/list.styl +33 -0
- package/client/components/setting-panel/on-tree-drop.js +222 -0
- package/client/components/setting-panel/setting-modal.jsx +163 -0
- package/client/components/setting-panel/setting-wrap.jsx +37 -0
- package/client/components/setting-panel/setting-wrap.styl +52 -0
- package/client/components/setting-panel/setting.jsx +858 -0
- package/client/components/setting-panel/setting.styl +4 -0
- package/client/components/setting-panel/start-session-select.jsx +91 -0
- package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
- package/client/components/setting-panel/tab-history.jsx +44 -0
- package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
- package/client/components/setting-panel/tab-settings.jsx +42 -0
- package/client/components/setting-panel/tab-themes.jsx +34 -0
- package/client/components/setting-panel/tree-list.jsx +978 -0
- package/client/components/setting-panel/tree-list.styl +57 -0
- package/client/components/setting-sync/data-import.jsx +65 -0
- package/client/components/setting-sync/setting-sync-form.jsx +271 -0
- package/client/components/setting-sync/setting-sync.jsx +81 -0
- package/client/components/setting-sync/sync.styl +7 -0
- package/client/components/sftp/address-bar.jsx +139 -0
- package/client/components/sftp/address-bookmark-item.jsx +47 -0
- package/client/components/sftp/address-bookmark.jsx +81 -0
- package/client/components/sftp/address-bookmark.styl +8 -0
- package/client/components/sftp/confirm-modal.jsx +184 -0
- package/client/components/sftp/file-icon.jsx +22 -0
- package/client/components/sftp/file-item.jsx +1226 -0
- package/client/components/sftp/file-mode-modal.jsx +205 -0
- package/client/components/sftp/file-props-modal.jsx +211 -0
- package/client/components/sftp/file-read.js +81 -0
- package/client/components/sftp/list-table-ui.jsx +547 -0
- package/client/components/sftp/owner-list.js +97 -0
- package/client/components/sftp/paged-list.jsx +60 -0
- package/client/components/sftp/permission-render.jsx +42 -0
- package/client/components/sftp/sftp-entry.jsx +1069 -0
- package/client/components/sftp/sftp.styl +217 -0
- package/client/components/sftp/transfer-common.js +9 -0
- package/client/components/sftp/transfer-conflict.jsx +315 -0
- package/client/components/sftp/transfer-speed-format.js +60 -0
- package/client/components/sftp/transfer-tag.jsx +40 -0
- package/client/components/sftp/transfer-tag.styl +11 -0
- package/client/components/sftp/transfer.styl +55 -0
- package/client/components/sftp/transport-action.jsx +410 -0
- package/client/components/sftp/transport-entry.jsx +108 -0
- package/client/components/sftp/transport-types.js +8 -0
- package/client/components/sftp/transports-action.jsx +111 -0
- package/client/components/sftp/transports-ui.jsx +93 -0
- package/client/components/sftp/zip.js +42 -0
- package/client/components/sidebar/bookmark-select.jsx +48 -0
- package/client/components/sidebar/bookmark.jsx +82 -0
- package/client/components/sidebar/history.jsx +66 -0
- package/client/components/sidebar/index.jsx +230 -0
- package/client/components/sidebar/info-modal.jsx +250 -0
- package/client/components/sidebar/info.styl +27 -0
- package/client/components/sidebar/side-icon.jsx +25 -0
- package/client/components/sidebar/sidebar.styl +128 -0
- package/client/components/sidebar/transfer-history-modal.jsx +110 -0
- package/client/components/sidebar/transfer-history.styl +3 -0
- package/client/components/sidebar/transfer-list-control.jsx +205 -0
- package/client/components/sidebar/transfer-list.jsx +55 -0
- package/client/components/sidebar/transfer-modal.jsx +76 -0
- package/client/components/sidebar/transfer.styl +8 -0
- package/client/components/sidebar/transport-ui.jsx +109 -0
- package/client/components/tabs/index.jsx +320 -0
- package/client/components/tabs/tab.jsx +427 -0
- package/client/components/tabs/tabs.styl +220 -0
- package/client/components/tabs/window-control.jsx +55 -0
- package/client/components/terminal/attach-addon-custom.js +70 -0
- package/client/components/terminal/build-ls-term-id.js +5 -0
- package/client/components/terminal/index.jsx +1358 -0
- package/client/components/terminal/normal-buffer.jsx +33 -0
- package/client/components/terminal/term-search.jsx +224 -0
- package/client/components/terminal/term-search.styl +15 -0
- package/client/components/terminal/terminal-apis.js +31 -0
- package/client/components/terminal/terminal-interactive.jsx +148 -0
- package/client/components/terminal/terminal.styl +96 -0
- package/client/components/terminal/xterm-zmodem.js +48 -0
- package/client/components/terminal/zmodem-transfer.jsx +98 -0
- package/client/components/terminal/zmodem.styl +14 -0
- package/client/components/terminal-info/activity.jsx +54 -0
- package/client/components/terminal-info/base.jsx +25 -0
- package/client/components/terminal-info/content.jsx +101 -0
- package/client/components/terminal-info/data-cols-parser.jsx +50 -0
- package/client/components/terminal-info/disk.jsx +29 -0
- package/client/components/terminal-info/index.jsx +25 -0
- package/client/components/terminal-info/network.jsx +114 -0
- package/client/components/terminal-info/resource.jsx +80 -0
- package/client/components/terminal-info/run-cmd.jsx +273 -0
- package/client/components/terminal-info/terminal-info.styl +29 -0
- package/client/components/terminal-info/up.jsx +15 -0
- package/client/components/terminal-theme/index.jsx +264 -0
- package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
- package/client/components/terminal-theme/theme-list.jsx +146 -0
- package/client/components/text-editor/text-editor-form.jsx +97 -0
- package/client/components/text-editor/text-editor.jsx +182 -0
- package/client/css/antd-overwrite.styl +14 -0
- package/client/css/basic.styl +38 -0
- package/client/css/includes/box.styl +154 -0
- package/client/css/includes/font-size.styl +6 -0
- package/client/css/includes/index.styl +3 -0
- package/client/css/includes/text.styl +31 -0
- package/client/css/includes/theme-default.styl +20 -0
- package/client/entry/basic.js +58 -0
- package/client/entry/index.jsx +15 -0
- package/client/entry/worker.js +137 -0
- package/client/store/address-bookmark.js +25 -0
- package/client/store/app-upgrade.js +23 -0
- package/client/store/batch-input-history.js +26 -0
- package/client/store/bookmark-group.js +128 -0
- package/client/store/bookmark.js +22 -0
- package/client/store/common.js +140 -0
- package/client/store/context-menu.js +23 -0
- package/client/store/db-upgrade.js +43 -0
- package/client/store/event.js +70 -0
- package/client/store/index.js +335 -0
- package/client/store/init-state.js +191 -0
- package/client/store/item.js +120 -0
- package/client/store/load-data.js +198 -0
- package/client/store/quick-command.js +43 -0
- package/client/store/session.js +54 -0
- package/client/store/setting.js +208 -0
- package/client/store/sidebar.js +48 -0
- package/client/store/sync.js +390 -0
- package/client/store/system-menu.js +120 -0
- package/client/store/tab.js +74 -0
- package/client/store/terminal-theme.js +116 -0
- package/client/store/transfer-history.js +27 -0
- package/client/store/transfer-list.js +20 -0
- package/client/store/ui-theme.js +71 -0
- package/client/store/watch.js +116 -0
- package/client/views/index.pug +58 -0
- package/package.json +34 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* file props
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { Modal, Button } from 'antd'
|
|
7
|
+
import resolve from '../../common/resolve'
|
|
8
|
+
import time from '../../../app/common/time'
|
|
9
|
+
import { findIndex, update } from 'lodash-es'
|
|
10
|
+
import { mode2permission, permission2mode } from '../../common/mode2permission'
|
|
11
|
+
import { commonActions } from '../../common/constants'
|
|
12
|
+
import renderPermission from './permission-render'
|
|
13
|
+
import postMessage from '../../common/post-msg'
|
|
14
|
+
import FileIcon from './file-icon'
|
|
15
|
+
|
|
16
|
+
const { prefix } = window
|
|
17
|
+
const e = prefix('sftp')
|
|
18
|
+
const formatTime = time
|
|
19
|
+
|
|
20
|
+
export default class FileMode extends React.PureComponent {
|
|
21
|
+
state = {
|
|
22
|
+
data: {},
|
|
23
|
+
file: {}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
componentDidMount () {
|
|
27
|
+
window.addEventListener('message', this.onEvent)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setStateProxy = (state, cb) => {
|
|
31
|
+
if (state && typeof state.file !== 'undefined') {
|
|
32
|
+
postMessage({
|
|
33
|
+
action: commonActions.updateStore,
|
|
34
|
+
value: !!state.file.id,
|
|
35
|
+
prop: 'showFileModal'
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
return this.setState(state, cb)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onEvent = (e) => {
|
|
42
|
+
const {
|
|
43
|
+
action,
|
|
44
|
+
data,
|
|
45
|
+
file
|
|
46
|
+
} = e.data || {}
|
|
47
|
+
if (action === commonActions.showFileModeModal) {
|
|
48
|
+
this.setStateProxy({
|
|
49
|
+
data,
|
|
50
|
+
file
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
addPermission = file => {
|
|
56
|
+
const perms = mode2permission(file.mode)
|
|
57
|
+
const permission = permission2mode(perms)
|
|
58
|
+
const mode = Number('0o' + '10' + permission)
|
|
59
|
+
return {
|
|
60
|
+
...file,
|
|
61
|
+
permission,
|
|
62
|
+
mode
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onChangePermission = (name, permName) => {
|
|
67
|
+
const { file } = this.state
|
|
68
|
+
const perms = mode2permission(file.mode)
|
|
69
|
+
const i = findIndex(perms, p => p.name === name)
|
|
70
|
+
update(
|
|
71
|
+
perms,
|
|
72
|
+
`[${i}].permission.${permName}`,
|
|
73
|
+
b => !b
|
|
74
|
+
)
|
|
75
|
+
const permission = permission2mode(perms)
|
|
76
|
+
const mode = Number('0o' + '10' + permission)
|
|
77
|
+
this.setStateProxy({
|
|
78
|
+
file: {
|
|
79
|
+
...file,
|
|
80
|
+
permission,
|
|
81
|
+
mode
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
onClose = () => {
|
|
87
|
+
this.setStateProxy({
|
|
88
|
+
file: {},
|
|
89
|
+
data: {}
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
handleSubmit = () => {
|
|
94
|
+
postMessage({
|
|
95
|
+
action: commonActions.submitFileModeEdit,
|
|
96
|
+
file: this.state.file
|
|
97
|
+
})
|
|
98
|
+
this.onClose()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
renderFooter () {
|
|
102
|
+
return (
|
|
103
|
+
<Button
|
|
104
|
+
type='primary'
|
|
105
|
+
onClick={this.handleSubmit}
|
|
106
|
+
>
|
|
107
|
+
{e('submit')}
|
|
108
|
+
</Button>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render () {
|
|
113
|
+
const {
|
|
114
|
+
visible,
|
|
115
|
+
tab,
|
|
116
|
+
uidTree,
|
|
117
|
+
gidTree
|
|
118
|
+
} = this.state.data
|
|
119
|
+
if (!visible) {
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
const { file } = this.state
|
|
123
|
+
const {
|
|
124
|
+
name,
|
|
125
|
+
size,
|
|
126
|
+
accessTime,
|
|
127
|
+
modifyTime,
|
|
128
|
+
isDirectory,
|
|
129
|
+
isSymbolicLink,
|
|
130
|
+
path,
|
|
131
|
+
mode,
|
|
132
|
+
type,
|
|
133
|
+
owner,
|
|
134
|
+
group
|
|
135
|
+
} = file
|
|
136
|
+
const {
|
|
137
|
+
host,
|
|
138
|
+
port,
|
|
139
|
+
username
|
|
140
|
+
} = tab
|
|
141
|
+
const iconType = isDirectory ? 'folder' : 'file'
|
|
142
|
+
const ps = {
|
|
143
|
+
open: visible,
|
|
144
|
+
width: 500,
|
|
145
|
+
title: `${e('edit')} ` + e(iconType) + ` ${e('permission')}`,
|
|
146
|
+
footer: this.renderFooter(),
|
|
147
|
+
onCancel: this.onClose
|
|
148
|
+
}
|
|
149
|
+
const fp = resolve(path, name)
|
|
150
|
+
const ffp = type === 'local'
|
|
151
|
+
? fp
|
|
152
|
+
: `${username}@${host}:${port}:${fp}`
|
|
153
|
+
|
|
154
|
+
const perms = mode2permission(mode)
|
|
155
|
+
const permission = permission2mode(perms)
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Modal
|
|
159
|
+
{...ps}
|
|
160
|
+
>
|
|
161
|
+
<div className='file-props-wrap relative'>
|
|
162
|
+
<FileIcon
|
|
163
|
+
className='file-icon'
|
|
164
|
+
file={file}
|
|
165
|
+
height={50}
|
|
166
|
+
/>
|
|
167
|
+
<div className='file-props'>
|
|
168
|
+
<p className='bold'>{e(iconType)} {e('name')}:</p>
|
|
169
|
+
<p className='pd1b'>
|
|
170
|
+
{
|
|
171
|
+
isSymbolicLink
|
|
172
|
+
? <sup className='color-blue symbolic-link-icon'>*</sup>
|
|
173
|
+
: null
|
|
174
|
+
}
|
|
175
|
+
{name}
|
|
176
|
+
</p>
|
|
177
|
+
<p className='bold'>{e('mode')}: ({permission})</p>
|
|
178
|
+
<div className='pd1b'>
|
|
179
|
+
{
|
|
180
|
+
perms.map((perm) => {
|
|
181
|
+
return renderPermission(
|
|
182
|
+
perm,
|
|
183
|
+
this.onChangePermission
|
|
184
|
+
)
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
</div>
|
|
188
|
+
<p className='bold'>{e('fullPath')}:</p>
|
|
189
|
+
<p className='pd1b'>{ffp}</p>
|
|
190
|
+
<p className='bold'>{e('owner')}</p>
|
|
191
|
+
<p className='pd1b'>{uidTree['' + owner]}</p>
|
|
192
|
+
<p className='bold'>{e('group')}</p>
|
|
193
|
+
<p className='pd1b'>{gidTree['' + group]}</p>
|
|
194
|
+
<p className='bold'>{e('size')}:</p>
|
|
195
|
+
<p className='pd1b'>{size}</p>
|
|
196
|
+
<p className='bold'>{e('accessTime')}:</p>
|
|
197
|
+
<p className='pd1b'>{formatTime(accessTime)}</p>
|
|
198
|
+
<p className='bold'>{e('modifyTime')}:</p>
|
|
199
|
+
<p className='pd1b'>{formatTime(modifyTime)}</p>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
</Modal>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* file props
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useState, useEffect } from 'react'
|
|
6
|
+
import {
|
|
7
|
+
Modal,
|
|
8
|
+
Button
|
|
9
|
+
} from 'antd'
|
|
10
|
+
import {
|
|
11
|
+
commonActions,
|
|
12
|
+
isWin,
|
|
13
|
+
typeMap
|
|
14
|
+
} from '../../common/constants'
|
|
15
|
+
import resolve from '../../common/resolve'
|
|
16
|
+
import { mode2permission } from '../../common/mode2permission'
|
|
17
|
+
import time from '../../../app/common/time'
|
|
18
|
+
import renderPermission from './permission-render'
|
|
19
|
+
import FileIcon from './file-icon'
|
|
20
|
+
import fs from '../../common/fs'
|
|
21
|
+
import postMsg from '../../common/post-msg'
|
|
22
|
+
import { filesize } from 'filesize'
|
|
23
|
+
import { runCmd } from '../terminal/terminal-apis'
|
|
24
|
+
|
|
25
|
+
const { prefix } = window
|
|
26
|
+
const e = prefix('sftp')
|
|
27
|
+
const formatTime = time
|
|
28
|
+
|
|
29
|
+
export default function FileInfoModal () {
|
|
30
|
+
const [state, setState] = useState({
|
|
31
|
+
loading: false
|
|
32
|
+
})
|
|
33
|
+
function onClose () {
|
|
34
|
+
setState({})
|
|
35
|
+
}
|
|
36
|
+
function onEvent (e) {
|
|
37
|
+
const {
|
|
38
|
+
action,
|
|
39
|
+
data
|
|
40
|
+
} = e.data || {}
|
|
41
|
+
if (action === commonActions.showFileInfoModal) {
|
|
42
|
+
setState(old => {
|
|
43
|
+
return {
|
|
44
|
+
...old,
|
|
45
|
+
...data,
|
|
46
|
+
size: 0
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
window.addEventListener('message', onEvent)
|
|
53
|
+
}, [])
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
postMsg({
|
|
56
|
+
action: commonActions.updateStore,
|
|
57
|
+
value: !!state.visible,
|
|
58
|
+
prop: 'showEditor'
|
|
59
|
+
})
|
|
60
|
+
}, [state.visible])
|
|
61
|
+
const {
|
|
62
|
+
visible,
|
|
63
|
+
file,
|
|
64
|
+
tab,
|
|
65
|
+
uidTree = {},
|
|
66
|
+
gidTree = {},
|
|
67
|
+
loading
|
|
68
|
+
} = state
|
|
69
|
+
if (!visible) {
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
const {
|
|
73
|
+
name,
|
|
74
|
+
size,
|
|
75
|
+
owner,
|
|
76
|
+
group,
|
|
77
|
+
accessTime,
|
|
78
|
+
modifyTime,
|
|
79
|
+
isDirectory,
|
|
80
|
+
isSymbolicLink,
|
|
81
|
+
path,
|
|
82
|
+
mode,
|
|
83
|
+
type
|
|
84
|
+
} = file
|
|
85
|
+
const {
|
|
86
|
+
host,
|
|
87
|
+
port,
|
|
88
|
+
username
|
|
89
|
+
} = tab
|
|
90
|
+
const iconType = isDirectory ? 'folder' : 'file'
|
|
91
|
+
const ps = {
|
|
92
|
+
open: visible,
|
|
93
|
+
width: 500,
|
|
94
|
+
title: e(iconType) + ` ${e('attributes')}`,
|
|
95
|
+
footer: null,
|
|
96
|
+
onCancel: onClose
|
|
97
|
+
}
|
|
98
|
+
const fp = resolve(path, name)
|
|
99
|
+
const ffp = type === typeMap.local
|
|
100
|
+
? fp
|
|
101
|
+
: `${username}@${host}:${port}:${fp}`
|
|
102
|
+
const perms = mode2permission(mode)
|
|
103
|
+
function setLoading (loading) {
|
|
104
|
+
setState(old => {
|
|
105
|
+
return {
|
|
106
|
+
...old,
|
|
107
|
+
loading
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
function renderSize () {
|
|
112
|
+
if (isDirectory) {
|
|
113
|
+
return state.size || 0
|
|
114
|
+
}
|
|
115
|
+
return size
|
|
116
|
+
}
|
|
117
|
+
function getSize (str = '') {
|
|
118
|
+
if (isWin) {
|
|
119
|
+
const s = str.split('\n').find(s => s.trim().startsWith('Sum'))
|
|
120
|
+
return s ? filesize(parseInt((s.split(':')[1]).trim(), 10)) : 0
|
|
121
|
+
} else {
|
|
122
|
+
return str.split(/\s+/)[0]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function calcLocal (folder) {
|
|
126
|
+
const cmd = isWin
|
|
127
|
+
? `Get-ChildItem -Recurse '${folder}' | Measure-Object -Property Length -Sum`
|
|
128
|
+
: `du -sh '${folder}'`
|
|
129
|
+
const func = isWin ? 'runWinCmd' : 'run'
|
|
130
|
+
const res = await fs[func](cmd).catch(window.store.onError)
|
|
131
|
+
return getSize(res)
|
|
132
|
+
}
|
|
133
|
+
async function calcRemote (folder) {
|
|
134
|
+
const cmd = `du -sh '${folder}'`
|
|
135
|
+
const r = await runCmd(
|
|
136
|
+
state.pid,
|
|
137
|
+
state.sessionId,
|
|
138
|
+
cmd
|
|
139
|
+
).catch(window.store.onError)
|
|
140
|
+
return r ? r.split(/\s+/)[0] : 0
|
|
141
|
+
}
|
|
142
|
+
async function calc () {
|
|
143
|
+
setLoading(true)
|
|
144
|
+
const size = type === typeMap.local
|
|
145
|
+
? await calcLocal(fp)
|
|
146
|
+
: await calcRemote(fp)
|
|
147
|
+
setState(old => {
|
|
148
|
+
return {
|
|
149
|
+
...old,
|
|
150
|
+
loading: false,
|
|
151
|
+
size
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
function renderCalc () {
|
|
156
|
+
if (isDirectory) {
|
|
157
|
+
return (
|
|
158
|
+
<Button
|
|
159
|
+
onClick={calc}
|
|
160
|
+
loading={loading}
|
|
161
|
+
disabled={loading}
|
|
162
|
+
className='mg1l'
|
|
163
|
+
>
|
|
164
|
+
{e('calculate')}
|
|
165
|
+
</Button>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return (
|
|
170
|
+
<Modal
|
|
171
|
+
{...ps}
|
|
172
|
+
>
|
|
173
|
+
<div className='file-props-wrap relative'>
|
|
174
|
+
<FileIcon
|
|
175
|
+
className='file-icon'
|
|
176
|
+
file={file}
|
|
177
|
+
height={50}
|
|
178
|
+
/>
|
|
179
|
+
<div className='file-props'>
|
|
180
|
+
<p className='bold'>{e(iconType)} {e('name')}:</p>
|
|
181
|
+
<p className='pd1b'>
|
|
182
|
+
{
|
|
183
|
+
isSymbolicLink
|
|
184
|
+
? <sup className='color-blue symbolic-link-icon'>*</sup>
|
|
185
|
+
: null
|
|
186
|
+
}
|
|
187
|
+
{name}
|
|
188
|
+
</p>
|
|
189
|
+
<p className='bold'>{e('fullPath')}:</p>
|
|
190
|
+
<p className='pd1b'>{ffp}</p>
|
|
191
|
+
<p className='bold'>{e('size')}:</p>
|
|
192
|
+
<p className='pd1b'>{renderSize()}{renderCalc()}</p>
|
|
193
|
+
<p className='bold'>{e('accessTime')}:</p>
|
|
194
|
+
<p className='pd1b'>{formatTime(accessTime)}</p>
|
|
195
|
+
<p className='bold'>{e('modifyTime')}:</p>
|
|
196
|
+
<p className='pd1b'>{formatTime(modifyTime)}</p>
|
|
197
|
+
<p className='bold'>{e('owner')}</p>
|
|
198
|
+
<p className='pd1b'>{uidTree['' + owner]}</p>
|
|
199
|
+
<p className='bold'>{e('group')}</p>
|
|
200
|
+
<p className='pd1b'>{gidTree['' + group]}</p>
|
|
201
|
+
<p className='bold'>{e('mode')}:</p>
|
|
202
|
+
<div className='pd1b'>
|
|
203
|
+
{
|
|
204
|
+
perms.map(renderPermission)
|
|
205
|
+
}
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</Modal>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* file info related functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import generate from '../../common/uid'
|
|
6
|
+
import fs from '../../common/fs'
|
|
7
|
+
import { isWin } from '../../common/constants'
|
|
8
|
+
|
|
9
|
+
export const getFileExt = fileName => {
|
|
10
|
+
const sep = '.'
|
|
11
|
+
const arr = fileName.split(sep)
|
|
12
|
+
const len = arr.length
|
|
13
|
+
if (len === 1) {
|
|
14
|
+
return {
|
|
15
|
+
base: fileName,
|
|
16
|
+
ext: ''
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
base: arr.slice(0, len - 1).join(sep),
|
|
21
|
+
ext: arr[len - 1] || ''
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const getFolderFromFilePath = (filePath, isRemote) => {
|
|
26
|
+
const sep = isRemote ? '/' : window.pre.sep
|
|
27
|
+
const arr = filePath.split(sep)
|
|
28
|
+
const len = arr.length
|
|
29
|
+
const isWinDisk = isWin && filePath.endsWith(sep)
|
|
30
|
+
const path = isWinDisk
|
|
31
|
+
? '/'
|
|
32
|
+
: arr.slice(0, len - 1).join(sep)
|
|
33
|
+
const name = isWinDisk
|
|
34
|
+
? filePath.replace(sep, '')
|
|
35
|
+
: arr[len - 1]
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
path,
|
|
39
|
+
name,
|
|
40
|
+
...getFileExt(name)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const getLocalFileInfo = async (filePath) => {
|
|
45
|
+
try {
|
|
46
|
+
const statr = await fs.statAsync(filePath)
|
|
47
|
+
const stat = await fs.lstatAsync(filePath)
|
|
48
|
+
return {
|
|
49
|
+
size: stat.size,
|
|
50
|
+
accessTime: stat.atime,
|
|
51
|
+
modifyTime: stat.mtime,
|
|
52
|
+
mode: stat.mode,
|
|
53
|
+
owner: stat.uid,
|
|
54
|
+
group: stat.gid,
|
|
55
|
+
type: 'local',
|
|
56
|
+
...getFolderFromFilePath(filePath, false),
|
|
57
|
+
id: generate(),
|
|
58
|
+
isDirectory: statr.isDirectory,
|
|
59
|
+
isSymbolicLink: stat.isSymbolicLink
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
log.debug(e)
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const getRemoteFileInfo = async (sftp, filePath) => {
|
|
68
|
+
const stat = await sftp.stat(filePath)
|
|
69
|
+
return {
|
|
70
|
+
size: stat.size,
|
|
71
|
+
accessTime: stat.atime,
|
|
72
|
+
modifyTime: stat.mtime,
|
|
73
|
+
mode: stat.mode,
|
|
74
|
+
group: stat.gid,
|
|
75
|
+
owner: stat.uid,
|
|
76
|
+
type: 'remote',
|
|
77
|
+
...getFolderFromFilePath(filePath, true),
|
|
78
|
+
id: generate(),
|
|
79
|
+
isDirectory: stat.isDirectory
|
|
80
|
+
}
|
|
81
|
+
}
|