@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,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ui theme related
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function getUiThemeConfig (stylus) {
|
|
6
|
+
const reg = /[^\n]+ = [^\n]+\n/g
|
|
7
|
+
const arr = stylus.match(reg)
|
|
8
|
+
const sep = ' = '
|
|
9
|
+
return arr.reduce((p, x) => {
|
|
10
|
+
if (!x.includes(sep)) {
|
|
11
|
+
return p
|
|
12
|
+
}
|
|
13
|
+
const [k, v] = x.split(sep)
|
|
14
|
+
return {
|
|
15
|
+
...p,
|
|
16
|
+
[k.trim()]: v.trim()
|
|
17
|
+
}
|
|
18
|
+
}, {})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* convert themeText to themeConfig object
|
|
23
|
+
* @param {string} themeTxt
|
|
24
|
+
* @return {object}
|
|
25
|
+
*/
|
|
26
|
+
export const convertTheme = (themeTxt) => {
|
|
27
|
+
return themeTxt.split('\n').reduce((prev, line) => {
|
|
28
|
+
let [key = '', value = ''] = line.split('=')
|
|
29
|
+
key = key.trim()
|
|
30
|
+
value = value.trim()
|
|
31
|
+
if (!key || !value) {
|
|
32
|
+
return prev
|
|
33
|
+
}
|
|
34
|
+
if (key === 'themeName') {
|
|
35
|
+
prev.name = value.slice(0, 50)
|
|
36
|
+
} else {
|
|
37
|
+
prev.themeConfig[key] = value
|
|
38
|
+
}
|
|
39
|
+
return prev
|
|
40
|
+
}, {
|
|
41
|
+
name: 'unnamed theme',
|
|
42
|
+
themeConfig: {}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check latest release for update warn
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fetch from './fetch-from-server'
|
|
6
|
+
import {
|
|
7
|
+
baseUpdateCheckUrls, packInfo
|
|
8
|
+
} from './constants'
|
|
9
|
+
|
|
10
|
+
async function fetchData (url, options) {
|
|
11
|
+
const data = {
|
|
12
|
+
action: 'fetch',
|
|
13
|
+
options: {
|
|
14
|
+
...options,
|
|
15
|
+
url,
|
|
16
|
+
timeout: 15000
|
|
17
|
+
},
|
|
18
|
+
proxy: window.store.getProxySetting()
|
|
19
|
+
}
|
|
20
|
+
return fetch(data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getInfo (url) {
|
|
24
|
+
const n = Date.now()
|
|
25
|
+
const tail = url.includes('?') ? '' : '?_=' + n
|
|
26
|
+
return fetchData(url + tail, {
|
|
27
|
+
action: 'get-update-info',
|
|
28
|
+
headers: {
|
|
29
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
|
|
30
|
+
},
|
|
31
|
+
timeout: 1000 * 60 * 5
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
return null
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function getLatestReleaseVersion (n) {
|
|
39
|
+
let q = ''
|
|
40
|
+
if (n) {
|
|
41
|
+
const { store } = window
|
|
42
|
+
const info = {
|
|
43
|
+
load_time: store.loadTime,
|
|
44
|
+
bookmark_count: store.bookmarks.length,
|
|
45
|
+
lang: store.config.language,
|
|
46
|
+
sync_with_github: !!store.config.syncSetting?.githubGistId,
|
|
47
|
+
sync_with_gitee: !!store.config.syncSetting?.giteeGistId,
|
|
48
|
+
version: packInfo.version,
|
|
49
|
+
installSrc: store.installSrc,
|
|
50
|
+
n: Date.now()
|
|
51
|
+
}
|
|
52
|
+
q = Object.keys(info).reduce((p, k, i) => {
|
|
53
|
+
const pre = i ? '&' : '?'
|
|
54
|
+
return p + pre + k + '=' + encodeURIComponent(info[k])
|
|
55
|
+
}, '')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let url = `${baseUpdateCheckUrls[0]}/version.html${q}`
|
|
59
|
+
let tagName = await getInfo(url)
|
|
60
|
+
if (!tagName) {
|
|
61
|
+
url = `${baseUpdateCheckUrls[1]}/version.html${q}`
|
|
62
|
+
tagName = await getInfo(url)
|
|
63
|
+
}
|
|
64
|
+
if (tagName) {
|
|
65
|
+
return {
|
|
66
|
+
tag_name: tagName
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getLatestReleaseInfo () {
|
|
72
|
+
let url = `${baseUpdateCheckUrls[0]}/data/electerm-github-release.json`
|
|
73
|
+
let res = await getInfo(url)
|
|
74
|
+
if (!res?.release?.body) {
|
|
75
|
+
url = `${baseUpdateCheckUrls[1]}/data/electerm-github-release.json`
|
|
76
|
+
res = await getInfo(url)
|
|
77
|
+
}
|
|
78
|
+
return res?.release?.body
|
|
79
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* upgrade through ws
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import generate from './uid'
|
|
6
|
+
import initWs from './ws'
|
|
7
|
+
|
|
8
|
+
const keys = window.pre.transferKeys
|
|
9
|
+
|
|
10
|
+
class Upgrade {
|
|
11
|
+
async init ({
|
|
12
|
+
onData,
|
|
13
|
+
onEnd,
|
|
14
|
+
onError,
|
|
15
|
+
...rest
|
|
16
|
+
}) {
|
|
17
|
+
const id = generate()
|
|
18
|
+
this.id = id
|
|
19
|
+
const th = this
|
|
20
|
+
const ws = await initWs('upgrade', id)
|
|
21
|
+
ws.s({
|
|
22
|
+
action: 'upgrade-new',
|
|
23
|
+
...rest,
|
|
24
|
+
id
|
|
25
|
+
})
|
|
26
|
+
keys.forEach(func => {
|
|
27
|
+
th[func] = (...args) => {
|
|
28
|
+
ws.s({
|
|
29
|
+
action: 'upgrade-func',
|
|
30
|
+
id: th.id,
|
|
31
|
+
func,
|
|
32
|
+
args
|
|
33
|
+
})
|
|
34
|
+
if (func === 'destroy') {
|
|
35
|
+
th.onDestroy(ws)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const did = 'upgrade:data:' + id
|
|
41
|
+
this.onData = (evt) => {
|
|
42
|
+
const arg = JSON.parse(evt.data)
|
|
43
|
+
if (did === arg.id) {
|
|
44
|
+
onData(arg.data)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
ws.addEventListener('message', this.onData)
|
|
48
|
+
ws.once((arg) => {
|
|
49
|
+
onEnd(arg)
|
|
50
|
+
}, 'upgrade:end:' + id)
|
|
51
|
+
ws.once((arg) => {
|
|
52
|
+
log.debug('upgrade error')
|
|
53
|
+
log.debug(arg.error.stack)
|
|
54
|
+
onError(new Error(arg.error.message))
|
|
55
|
+
}, 'upgrade:err:' + id)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onDestroy (ws) {
|
|
59
|
+
ws.removeEventListener('message', this.onData)
|
|
60
|
+
ws.close()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default async (props) => {
|
|
65
|
+
const upgrade = new Upgrade()
|
|
66
|
+
await upgrade.init(props)
|
|
67
|
+
return upgrade
|
|
68
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ws function for sftp/file transfer communication
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import generate from './uid'
|
|
6
|
+
import wait from './wait'
|
|
7
|
+
import copy from 'json-deep-copy'
|
|
8
|
+
|
|
9
|
+
const onces = {}
|
|
10
|
+
const wss = {}
|
|
11
|
+
const persists = {}
|
|
12
|
+
|
|
13
|
+
function send (data) {
|
|
14
|
+
window.worker.postMessage(data)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class Ws {
|
|
18
|
+
constructor (id, persist) {
|
|
19
|
+
this.id = id
|
|
20
|
+
this.persist = !!persist
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onceIds = []
|
|
24
|
+
|
|
25
|
+
s (data) {
|
|
26
|
+
send({
|
|
27
|
+
action: 's',
|
|
28
|
+
args: [data],
|
|
29
|
+
wsId: this.id
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async once (func, id) {
|
|
34
|
+
while (this.closed) {
|
|
35
|
+
await wait(100)
|
|
36
|
+
}
|
|
37
|
+
this.onceIds.push(id)
|
|
38
|
+
onces[id] = {
|
|
39
|
+
resolve: (...args) => {
|
|
40
|
+
func(...args)
|
|
41
|
+
delete onces[id]
|
|
42
|
+
this.onceIds = this.onceIds.filter(d => d !== id)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
send({
|
|
46
|
+
id,
|
|
47
|
+
wsId: this.id,
|
|
48
|
+
action: 'once'
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addEventListener (type = 'message', cb = this.cb) {
|
|
53
|
+
this.cb = cb
|
|
54
|
+
const id = this.eid || generate()
|
|
55
|
+
this.eid = id
|
|
56
|
+
persists[id] = {
|
|
57
|
+
resolve: cb
|
|
58
|
+
}
|
|
59
|
+
send({
|
|
60
|
+
id,
|
|
61
|
+
wsId: this.id,
|
|
62
|
+
type,
|
|
63
|
+
action: 'addEventListener'
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
removeEventListener (type, cb) {
|
|
68
|
+
delete persists[this.eid]
|
|
69
|
+
send({
|
|
70
|
+
id: this.eid,
|
|
71
|
+
wsId: this.id,
|
|
72
|
+
type,
|
|
73
|
+
action: 'removeEventListener'
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onclose () {
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
clearOnces () {
|
|
82
|
+
if (this.eid) {
|
|
83
|
+
delete persists[this.eid]
|
|
84
|
+
}
|
|
85
|
+
const ids = copy(this.onceIds)
|
|
86
|
+
ids.forEach(k => {
|
|
87
|
+
delete onces[k]
|
|
88
|
+
})
|
|
89
|
+
this.onceIds = []
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
close () {
|
|
93
|
+
this.onclose()
|
|
94
|
+
if (this.persist) {
|
|
95
|
+
this.closed = true
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
this.clearOnces()
|
|
99
|
+
send({
|
|
100
|
+
action: 'close',
|
|
101
|
+
wsId: this.id
|
|
102
|
+
})
|
|
103
|
+
delete wss[this.id]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onEvent (e) {
|
|
108
|
+
if (!e || !e.data) {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
const {
|
|
112
|
+
id,
|
|
113
|
+
data,
|
|
114
|
+
action,
|
|
115
|
+
persist
|
|
116
|
+
} = e.data
|
|
117
|
+
if (wss[id]) {
|
|
118
|
+
if (action === 'close') {
|
|
119
|
+
wss[id].close && wss[id].close()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (persists[id]) {
|
|
123
|
+
persists[id].resolve(data)
|
|
124
|
+
} else if (onces[id]) {
|
|
125
|
+
if (action === 'create') {
|
|
126
|
+
if (!wss[id]) {
|
|
127
|
+
wss[id] = new Ws(id, persist)
|
|
128
|
+
} else {
|
|
129
|
+
wss[id].addEventListener()
|
|
130
|
+
wss[id].closed = false
|
|
131
|
+
}
|
|
132
|
+
onces[id].resolve(wss[id])
|
|
133
|
+
} else {
|
|
134
|
+
onces[id].resolve(data)
|
|
135
|
+
}
|
|
136
|
+
delete onces[id]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
window.worker.addEventListener('message', onEvent)
|
|
141
|
+
|
|
142
|
+
export default (type, id, sessionId = '', sftpId = '', persist) => {
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
send({
|
|
145
|
+
id,
|
|
146
|
+
action: 'create',
|
|
147
|
+
persist,
|
|
148
|
+
type,
|
|
149
|
+
args: [
|
|
150
|
+
type,
|
|
151
|
+
id,
|
|
152
|
+
sessionId,
|
|
153
|
+
sftpId,
|
|
154
|
+
window.store.config
|
|
155
|
+
]
|
|
156
|
+
})
|
|
157
|
+
onces[id] = {
|
|
158
|
+
resolve
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
}
|