@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) since 2017~ ZHAO Xudong <zxdong@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<h1 align="center" style="padding-top: 60px;padding-bottom: 40px;">
|
|
2
|
+
<a href="https://electerm.github.io/electerm">
|
|
3
|
+
<img src="https://github.com/electerm/electerm-resource/raw/master/static/images/electerm.png", alt="" />
|
|
4
|
+
</a>
|
|
5
|
+
</h1>
|
|
6
|
+
|
|
7
|
+
# electerm [](https://twitter.com/intent/tweet?text=Open%20sourced%20terminal%2Fssh%2Fsftp%20client(linux%2C%20mac%2C%20win)&url=https%3A%2F%2Fgithub.com%2Felecterm%2Felecterm&hashtags=electerm,ssh,terminal,sftp)
|
|
8
|
+
|
|
9
|
+
[](https://github.com/electerm/electerm/releases)
|
|
10
|
+
[](https://github.com/electerm/electerm/actions)
|
|
11
|
+
[](https://github.com/electerm/electerm/blob/master/LICENSE)
|
|
12
|
+
[](https://standardjs.com)
|
|
13
|
+
[](https://snapcraft.io/electerm)
|
|
14
|
+
[](https://www.microsoft.com/store/apps/9NCN7272GTFF)
|
|
15
|
+
[](https://github.com/sponsors/electerm)
|
|
16
|
+
|
|
17
|
+
Open-sourced terminal/ssh/telnet/serialport/sftp client(linux, mac, win).
|
|
18
|
+
|
|
19
|
+
This is react components src for electerm
|
|
20
|
+
|
|
21
|
+
## Use
|
|
22
|
+
|
|
23
|
+
todo
|
|
24
|
+
|
|
25
|
+
## Change log
|
|
26
|
+
|
|
27
|
+
Visit [Releases](https://github.com/electerm/electerm/releases).
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function formatBytes (sizeInKB) {
|
|
2
|
+
if (!sizeInKB) {
|
|
3
|
+
return ''
|
|
4
|
+
}
|
|
5
|
+
const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
6
|
+
let index = 0
|
|
7
|
+
|
|
8
|
+
while (sizeInKB >= 1024 && index < units.length - 1) {
|
|
9
|
+
sizeInKB /= 1024
|
|
10
|
+
index++
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return `${sizeInKB.toFixed(2)} ${units[index]}`
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// dom class方法
|
|
2
|
+
/**
|
|
3
|
+
* add css class
|
|
4
|
+
* @param elem
|
|
5
|
+
* @param _classes
|
|
6
|
+
*/
|
|
7
|
+
export function addClass (elem, ..._classes) {
|
|
8
|
+
const cls = elem.className || ''
|
|
9
|
+
const classes = _classes.filter(c => {
|
|
10
|
+
return !cls.includes(c)
|
|
11
|
+
})
|
|
12
|
+
if (!classes.length) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
elem.className = cls + (cls ? ' ' : '') + classes.join(' ')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* has css class
|
|
20
|
+
* @param elem
|
|
21
|
+
* @param clst
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
export function hasClass (elem, clst) {
|
|
25
|
+
let cls = elem.className || ''
|
|
26
|
+
if (!cls || typeof cls !== 'string') {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
cls = ' ' + cls.split(/\s+/).join(' ') + ' '
|
|
30
|
+
const reg = new RegExp(' ' + clst + ' ')
|
|
31
|
+
return reg.test(cls)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* remove css class
|
|
36
|
+
* @param elem
|
|
37
|
+
* @param classes
|
|
38
|
+
*/
|
|
39
|
+
export function removeClass (elem, ...classes) {
|
|
40
|
+
let cls = elem.className || ''
|
|
41
|
+
if (!cls || typeof cls !== 'string') {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
cls = ' ' + cls.split(/\s+/).join(' ') + ' '
|
|
45
|
+
const clst = classes.join(' ').split(/\s+/)
|
|
46
|
+
const reg = new RegExp(' ' + clst.join(' | ') + ' ', 'g')
|
|
47
|
+
cls = cls.replace(reg, '')
|
|
48
|
+
.replace(/^\s+|\s+$/g, '')
|
|
49
|
+
.replace(/ {2,}/g, ' ')
|
|
50
|
+
|
|
51
|
+
elem.className = cls
|
|
52
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* clipboard related
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { message } from 'antd'
|
|
6
|
+
import {
|
|
7
|
+
copyBookmarkItemPrefix
|
|
8
|
+
} from './constants'
|
|
9
|
+
|
|
10
|
+
const fileRegWin = /^(remote:)?\w:\\.+/
|
|
11
|
+
const fileReg = /^(remote:)?\/.+/
|
|
12
|
+
|
|
13
|
+
export const readClipboard = () => {
|
|
14
|
+
return window.pre.readClipboard()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const copy = (str) => {
|
|
18
|
+
message.success({
|
|
19
|
+
content: 'Copied',
|
|
20
|
+
duation: 2,
|
|
21
|
+
key: 'copy-message'
|
|
22
|
+
})
|
|
23
|
+
window.pre.writeClipboard(str)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const cut = (str, itemTitle = '') => {
|
|
27
|
+
message.success('Cutted ' + itemTitle, 2)
|
|
28
|
+
window.pre.writeClipboard(str)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const hasFileInClipboardText = (
|
|
32
|
+
text = readClipboard()
|
|
33
|
+
) => {
|
|
34
|
+
const arr = text.split('\n')
|
|
35
|
+
return arr.reduce((prev, t) => {
|
|
36
|
+
return prev &&
|
|
37
|
+
(fileReg.test(t) || fileRegWin.test(t))
|
|
38
|
+
}, true)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const hasBookmarkOrGroupInClipboardText = (
|
|
42
|
+
text = readClipboard()
|
|
43
|
+
) => {
|
|
44
|
+
const arr = text.split('\n')
|
|
45
|
+
return arr.reduce((prev, t = '') => {
|
|
46
|
+
return prev &&
|
|
47
|
+
t.startsWith(copyBookmarkItemPrefix)
|
|
48
|
+
}, true)
|
|
49
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* constants
|
|
3
|
+
*/
|
|
4
|
+
import { getUiThemeConfig } from './ui-theme'
|
|
5
|
+
import logoPath1Ref from '@electerm/electerm-resource/res/imgs/electerm-round-128x128.png'
|
|
6
|
+
import logoPath2Ref from '@electerm/electerm-resource/res/imgs/electerm.png'
|
|
7
|
+
import logoPath3Ref from '@electerm/electerm-resource/res/imgs/electerm-watermark.png'
|
|
8
|
+
import dbDefaults from '../../app/upgrade/db-defaults'
|
|
9
|
+
import { get as _get } from 'lodash-es'
|
|
10
|
+
export const packInfo = typeof window.et.packInfo === 'undefined' ? window.pre.packInfo : window.et.packInfo
|
|
11
|
+
const buildConst = (props) => {
|
|
12
|
+
return props.reduce((prev, key) => {
|
|
13
|
+
return {
|
|
14
|
+
...prev,
|
|
15
|
+
[key]: key
|
|
16
|
+
}
|
|
17
|
+
}, {})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const logoPath1 = logoPath1Ref.replace(/^\//, '')
|
|
21
|
+
export const logoPath2 = logoPath2Ref.replace(/^\//, '')
|
|
22
|
+
export const logoPath3 = logoPath3Ref.replace(/^\//, '')
|
|
23
|
+
export const maxEditFileSize = 1024 * 30
|
|
24
|
+
export const defaultBookmarkGroupId = 'default'
|
|
25
|
+
export const newBookmarkIdPrefix = 'new-bookmark'
|
|
26
|
+
export const unexpectedPacketErrorDesc = 'Unexpected packet'
|
|
27
|
+
export const noTerminalBgValue = 'no-termimal-bg'
|
|
28
|
+
export const sftpRetryInterval = 3000
|
|
29
|
+
export const maxBookmarkGroupTitleLength = 33
|
|
30
|
+
export const termControlHeight = 32
|
|
31
|
+
export const maxDragMove = 30
|
|
32
|
+
export const splitDraggerWidth = 5
|
|
33
|
+
export const minTerminalWidth = 90
|
|
34
|
+
export const filePropMinWidth = 1
|
|
35
|
+
export const contextMenuHeight = 28
|
|
36
|
+
export const contextMenuWidth = 220
|
|
37
|
+
export const contextMenuPaddingTop = 10
|
|
38
|
+
export const sftpControlHeight = 28 + 42 + 33 + 56
|
|
39
|
+
export const sidebarWidth = 43
|
|
40
|
+
export const sidebarPanelWidth = 300
|
|
41
|
+
export const maxHistory = 50
|
|
42
|
+
export const maxTransport = 5
|
|
43
|
+
export const maxSftpHistory = 20
|
|
44
|
+
export const maxZoom = 8
|
|
45
|
+
export const minZoom = 0.25
|
|
46
|
+
export const extraTabWidth = 113
|
|
47
|
+
// export const maxTabs = 20
|
|
48
|
+
|
|
49
|
+
export const tabWidth = 160
|
|
50
|
+
|
|
51
|
+
export const tabMargin = 1
|
|
52
|
+
|
|
53
|
+
export const fileTypeMap = {
|
|
54
|
+
link: 'l',
|
|
55
|
+
directory: 'd'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const statusMap = buildConst([
|
|
59
|
+
'default',
|
|
60
|
+
'success',
|
|
61
|
+
'error',
|
|
62
|
+
'processing',
|
|
63
|
+
'warning'
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
export const connectionMap = buildConst([
|
|
67
|
+
'ssh',
|
|
68
|
+
'telnet',
|
|
69
|
+
'serial',
|
|
70
|
+
'local'
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
export const authTypeMap = buildConst([
|
|
74
|
+
'password',
|
|
75
|
+
'privateKey'
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
export const maxTransferHistory = 100
|
|
79
|
+
export const footerHeight = 36
|
|
80
|
+
export const quickCommandBoxHeight = 180
|
|
81
|
+
export const isWin = typeof window.et.isWin === 'undefined' ? window.pre.isWin : window.et.isWin
|
|
82
|
+
export const isMac = typeof window.et.isMac === 'undefined' ? window.pre.isMac : window.et.isMac
|
|
83
|
+
export const ctrlOrCmd = isMac ? 'cmd' : 'ctrl'
|
|
84
|
+
export const typeMap = buildConst([
|
|
85
|
+
'remote',
|
|
86
|
+
'local'
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
export const paneMap = buildConst([
|
|
90
|
+
'ssh',
|
|
91
|
+
'sftp',
|
|
92
|
+
'terminal',
|
|
93
|
+
'fileManager'
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
export const settingMap = buildConst([
|
|
97
|
+
'setting',
|
|
98
|
+
'bookmarks',
|
|
99
|
+
'history',
|
|
100
|
+
'terminalThemes',
|
|
101
|
+
'bookmarkGroups',
|
|
102
|
+
'quickCommands',
|
|
103
|
+
'addressBookmarks'
|
|
104
|
+
])
|
|
105
|
+
|
|
106
|
+
export const infoTabs = buildConst([
|
|
107
|
+
'info',
|
|
108
|
+
'deps',
|
|
109
|
+
'env',
|
|
110
|
+
'os',
|
|
111
|
+
'log',
|
|
112
|
+
'cmd'
|
|
113
|
+
])
|
|
114
|
+
|
|
115
|
+
export const transferTypeMap = buildConst([
|
|
116
|
+
'download',
|
|
117
|
+
'upload',
|
|
118
|
+
'remote',
|
|
119
|
+
'local',
|
|
120
|
+
'compressAndDownload',
|
|
121
|
+
'compressAndUpload'
|
|
122
|
+
])
|
|
123
|
+
|
|
124
|
+
export const fileOperationsMap = buildConst([
|
|
125
|
+
'cp',
|
|
126
|
+
'mv'
|
|
127
|
+
])
|
|
128
|
+
|
|
129
|
+
export const terminalSplitDirectionMap = buildConst([
|
|
130
|
+
'horizontal',
|
|
131
|
+
'vertical'
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
export const terminalSshConfigType = 'ssh-config'
|
|
135
|
+
export const terminalSerialType = 'serial'
|
|
136
|
+
export const terminalTelnetType = 'telnet'
|
|
137
|
+
export const terminalLocalType = 'local'
|
|
138
|
+
export const openedSidebarKey = 'opened-sidebar'
|
|
139
|
+
export const sidebarPinnedKey = 'sidebar-pinned'
|
|
140
|
+
export const sftpDefaultSortSettingKey = 'sftp-default-sort'
|
|
141
|
+
// https://github.com/tinkertrain/panda-syntax-vscode/blob/master/themes/workbench.yaml
|
|
142
|
+
export const defaultTheme = {
|
|
143
|
+
id: 'default',
|
|
144
|
+
name: 'default',
|
|
145
|
+
themeConfig: {
|
|
146
|
+
foreground: '#bbbbbb',
|
|
147
|
+
background: '#141314',
|
|
148
|
+
cursor: '#b5bd68',
|
|
149
|
+
cursorAccent: '#1d1f21',
|
|
150
|
+
selectionBackground: 'rgba(255, 255, 255, 0.3)',
|
|
151
|
+
black: '#575757',
|
|
152
|
+
red: '#FF2C6D',
|
|
153
|
+
green: '#19f9d8',
|
|
154
|
+
yellow: '#FFB86C',
|
|
155
|
+
blue: '#45A9F9',
|
|
156
|
+
magenta: '#FF75B5',
|
|
157
|
+
cyan: '#B084EB',
|
|
158
|
+
white: '#CDCDCD',
|
|
159
|
+
brightBlack: '#757575',
|
|
160
|
+
brightRed: '#FF2C6D',
|
|
161
|
+
brightGreen: '#19f9d8',
|
|
162
|
+
brightYellow: '#FFCC95',
|
|
163
|
+
brightBlue: '#6FC1FF',
|
|
164
|
+
brightMagenta: '#FF9AC1',
|
|
165
|
+
brightCyan: '#BCAAFE',
|
|
166
|
+
brightWhite: '#E6E6E6'
|
|
167
|
+
},
|
|
168
|
+
uiThemeConfig: getUiThemeConfig(window.et.stylus)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const eventTypes = {
|
|
172
|
+
resetFileListTable: 'reset-file-list-table'
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const commonBaudRates = [
|
|
176
|
+
110,
|
|
177
|
+
300,
|
|
178
|
+
1200,
|
|
179
|
+
2400,
|
|
180
|
+
4800,
|
|
181
|
+
9600,
|
|
182
|
+
14400,
|
|
183
|
+
19200,
|
|
184
|
+
38400,
|
|
185
|
+
57600,
|
|
186
|
+
115200
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
export const commonDataBits = [
|
|
190
|
+
8, 7, 6, 5
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
export const commonStopBits = [
|
|
194
|
+
1, 2
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
export const commonParities = [
|
|
198
|
+
'none', 'even', 'mark', 'odd', 'space'
|
|
199
|
+
]
|
|
200
|
+
|
|
201
|
+
export const maxBatchInput = 30
|
|
202
|
+
export const windowControlWidth = 94
|
|
203
|
+
export const baseUpdateCheckUrls = [
|
|
204
|
+
packInfo.homepage,
|
|
205
|
+
'https://gitee.com/github-zxdong262/electerm/raw/gh-pages'
|
|
206
|
+
]
|
|
207
|
+
export const syncTypes = buildConst([
|
|
208
|
+
'github',
|
|
209
|
+
'gitee',
|
|
210
|
+
'custom'
|
|
211
|
+
])
|
|
212
|
+
export const syncTokenCreateUrls = {
|
|
213
|
+
gitee: 'https://gitee.com/github-zxdong262/electerm/wikis/Create%20personal%20access%20token?sort_id=3028409',
|
|
214
|
+
github: 'https://github.com/electerm/electerm/wiki/Create-personal-access-token',
|
|
215
|
+
custom: 'https://github.com/electerm/electerm/wiki/Custom-sync-server'
|
|
216
|
+
}
|
|
217
|
+
export const settingSyncId = 'setting-sync'
|
|
218
|
+
export const settingCommonId = 'setting-common'
|
|
219
|
+
export const defaultEnvLang = 'en_US.UTF-8'
|
|
220
|
+
const defaultThemeLightConf = _get(
|
|
221
|
+
dbDefaults, '[0].data[1]'
|
|
222
|
+
)
|
|
223
|
+
defaultThemeLightConf.id = defaultThemeLightConf._id
|
|
224
|
+
export const defaultThemeLight = defaultThemeLightConf
|
|
225
|
+
export const terminalActions = {
|
|
226
|
+
showInfoPanel: 'show-info-panel',
|
|
227
|
+
changeEncode: 'change-encode',
|
|
228
|
+
batchInput: 'batch-input',
|
|
229
|
+
quickCommand: 'quick-command',
|
|
230
|
+
openTerminalSearch: 'open-terminal-search',
|
|
231
|
+
doSearchNext: 'do-search-next',
|
|
232
|
+
doSearchPrev: 'do-search-prev',
|
|
233
|
+
zoom: 'zoom-terminal'
|
|
234
|
+
}
|
|
235
|
+
export const fileActions = {
|
|
236
|
+
cancel: 'cancel',
|
|
237
|
+
skip: 'skip',
|
|
238
|
+
skipAll: 'skipAll',
|
|
239
|
+
mergeOrOverwrite: 'mergeOrOverwrite',
|
|
240
|
+
rename: 'rename',
|
|
241
|
+
mergeOrOverwriteAll: 'mergeOrOverwriteAll',
|
|
242
|
+
renameAll: 'renameAll'
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const tabActions = {
|
|
246
|
+
updateTabsStatus: 'update-tabs-status',
|
|
247
|
+
setAllTabOffline: 'set-all-tab-offline',
|
|
248
|
+
changeCurrentTabId: 'changeCurrentTabId',
|
|
249
|
+
onDuplicateTab: 'on-duplicate-tab',
|
|
250
|
+
reloadTab: 'reload-tab',
|
|
251
|
+
initFirstTab: 'init-first-tab',
|
|
252
|
+
delTab: 'del-tab',
|
|
253
|
+
addTab: 'add-tab',
|
|
254
|
+
updateTabs: 'update-tabs'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const commonActions = {
|
|
258
|
+
batchOp: 'batch-op',
|
|
259
|
+
updateStore: 'update-store',
|
|
260
|
+
editWithSystemEditorDone: 'edit-with-system-editor-done',
|
|
261
|
+
editWithSystemEditor: 'edit-with-system-editor',
|
|
262
|
+
onCloseTextEditor: 'on-close-text-editor',
|
|
263
|
+
submitTextEditorText: 'submit-text-editor-text',
|
|
264
|
+
fetchTextEditorText: 'fetch-text-editor-text',
|
|
265
|
+
loadTextEditorText: 'load-text-editor-text',
|
|
266
|
+
openTextEditor: 'open-text-editor',
|
|
267
|
+
submitFileModeEdit: 'submit-file-mode-edit',
|
|
268
|
+
showFileModeModal: 'show-file-mode-modal',
|
|
269
|
+
showFileInfoModal: 'show-file-info-modal',
|
|
270
|
+
appUpdateCheck: 'check-app-update',
|
|
271
|
+
closeContextMenu: 'close-context-menu',
|
|
272
|
+
clickContextMenu: 'click-context-menu',
|
|
273
|
+
openContextMenu: 'open-context-menu',
|
|
274
|
+
addTransfer: 'add-transfer'
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export const srcsSkipUpgradeCheck = [
|
|
278
|
+
'.appx',
|
|
279
|
+
'.snap',
|
|
280
|
+
'skip-upgrade-check'
|
|
281
|
+
]
|
|
282
|
+
export const termLSPrefix = 'term:sess:'
|
|
283
|
+
export const termInitId = 'electerm-init-term'
|
|
284
|
+
export const batchInputLsKey = 'batch-inputs'
|
|
285
|
+
export const copyBookmarkItemPrefix = 'bookmark:'
|
|
286
|
+
export const copyBookmarkGroupItemPrefix = 'bookmarkGroup:'
|
|
287
|
+
export const rendererTypes = {
|
|
288
|
+
dom: 'dom',
|
|
289
|
+
canvas: 'canvas',
|
|
290
|
+
webGL: 'webGL'
|
|
291
|
+
}
|
|
292
|
+
export const mirrors = {
|
|
293
|
+
github: 'github',
|
|
294
|
+
sourceforge: 'sourceforge'
|
|
295
|
+
}
|
|
296
|
+
export const downloadUpgradeTimeout = 20000
|
|
297
|
+
export const expandedKeysLsKey = 'expanded-keys'
|
|
298
|
+
export const checkedKeysLsKey = 'checked-keys'
|
|
299
|
+
export const quickCommandLabelsLsKey = 'quick-command-labels'
|
|
300
|
+
export const localAddrBookmarkLsKey = 'local-addr-bookmark-keys'
|
|
301
|
+
export const sshTunnelHelpLink = 'https://github.com/electerm/electerm/wiki/How-to-use-ssh-tunnel'
|
|
302
|
+
export const batchOpHelpLink = 'https://github.com/electerm/electerm/wiki/batch-operation'
|
|
303
|
+
export const proxyHelpLink = 'https://github.com/electerm/electerm/wiki/proxy-format'
|
|
304
|
+
export const modals = {
|
|
305
|
+
hide: 0,
|
|
306
|
+
setting: 1,
|
|
307
|
+
batchOps: 2
|
|
308
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tab title create rule
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
terminalLocalType
|
|
7
|
+
} from './constants'
|
|
8
|
+
|
|
9
|
+
const { prefix } = window
|
|
10
|
+
const p = prefix('sftp')
|
|
11
|
+
|
|
12
|
+
export default (res = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
host, port, username, title, type,
|
|
15
|
+
path, connectionHoppings
|
|
16
|
+
} = res
|
|
17
|
+
const fixTitle = `${username || ''}@${host}:${port}`
|
|
18
|
+
const extra = host || path ? (path || fixTitle) : ''
|
|
19
|
+
let f = title
|
|
20
|
+
? `${title}` + (extra ? ` - ${extra}` : '')
|
|
21
|
+
: extra
|
|
22
|
+
if (connectionHoppings && connectionHoppings.length) {
|
|
23
|
+
f = `[⋙]${f}`
|
|
24
|
+
}
|
|
25
|
+
if (type) {
|
|
26
|
+
f = `[${type}]${f}`
|
|
27
|
+
}
|
|
28
|
+
return f || p(terminalLocalType)
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// make old data imported compatible
|
|
2
|
+
import { buildProxyString } from '../../app/lib/build-proxy.js'
|
|
3
|
+
import { buildSshTunnels } from '../../app/common/build-ssh-tunnel.js'
|
|
4
|
+
import { buildRunScripts } from '../../app/common/build-run-scripts.js'
|
|
5
|
+
|
|
6
|
+
export function fixBookmarks (arr) {
|
|
7
|
+
return arr.map(bookmark => {
|
|
8
|
+
if (typeof bookmark.proxy !== 'string') {
|
|
9
|
+
bookmark.proxy = buildProxyString(bookmark.proxy || {})
|
|
10
|
+
}
|
|
11
|
+
if (bookmark.sshTunnel) {
|
|
12
|
+
bookmark.sshTunnels = buildSshTunnels(bookmark.sshTunnel)
|
|
13
|
+
delete bookmark.sshTunnel
|
|
14
|
+
delete bookmark.sshTunnelRemotePort
|
|
15
|
+
delete bookmark.sshTunnelLocalPort
|
|
16
|
+
}
|
|
17
|
+
if (bookmark.loginScript) {
|
|
18
|
+
bookmark.runScripts = buildRunScripts(bookmark)
|
|
19
|
+
delete bookmark.loginScript
|
|
20
|
+
delete bookmark.loginScriptDelay
|
|
21
|
+
}
|
|
22
|
+
return bookmark
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db common methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
settingMap
|
|
7
|
+
} from '../common/constants'
|
|
8
|
+
import { without, isArray, findIndex } from 'lodash-es'
|
|
9
|
+
import handleError from './error-handler'
|
|
10
|
+
import generate from './uid'
|
|
11
|
+
import safeParse from './to-simple-obj'
|
|
12
|
+
import { encObj, decObj } from './pass-enc'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* db action, never direct use it
|
|
16
|
+
* @param {...any} args
|
|
17
|
+
*/
|
|
18
|
+
const dbAction = (...args) => {
|
|
19
|
+
return window.pre.runGlobalAsync('dbAction', ...args)
|
|
20
|
+
.catch(handleError)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* standalone db names
|
|
25
|
+
*/
|
|
26
|
+
export const dbNames = without(
|
|
27
|
+
Object.keys(settingMap),
|
|
28
|
+
settingMap.setting
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
export const dbNamesForWatch = without(
|
|
32
|
+
Object.keys(settingMap),
|
|
33
|
+
settingMap.setting,
|
|
34
|
+
settingMap.history
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* db insert
|
|
39
|
+
* @param {string} dbName
|
|
40
|
+
* @param {object or array} inst
|
|
41
|
+
*/
|
|
42
|
+
export function insert (dbName, inst) {
|
|
43
|
+
let arr = isArray(inst) ? inst : [inst]
|
|
44
|
+
arr = arr.map(obj => {
|
|
45
|
+
const { id, _id, ...rest } = obj
|
|
46
|
+
return {
|
|
47
|
+
_id: _id || id || generate(),
|
|
48
|
+
...encObj(rest)
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
return dbAction(dbName, 'insert', safeParse(arr))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* db delete
|
|
56
|
+
* @param {string} dbName
|
|
57
|
+
* @param {string} id
|
|
58
|
+
*/
|
|
59
|
+
export async function remove (dbName, id) {
|
|
60
|
+
const q = id
|
|
61
|
+
? {
|
|
62
|
+
_id: id
|
|
63
|
+
}
|
|
64
|
+
: {}
|
|
65
|
+
const multi = !id
|
|
66
|
+
await dbAction(dbName, 'remove', q, { multi })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* upsert single data in db
|
|
71
|
+
* @param {string} _id
|
|
72
|
+
* @param {any} value
|
|
73
|
+
* @param {string} db default is 'data'
|
|
74
|
+
*/
|
|
75
|
+
export function update (_id, value, db = 'data', upsert = true) {
|
|
76
|
+
const updates = dbNames.includes(db)
|
|
77
|
+
? {
|
|
78
|
+
$set: {
|
|
79
|
+
...encObj(value)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
: {
|
|
83
|
+
$set: {
|
|
84
|
+
value
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return dbAction(db, 'update', {
|
|
88
|
+
_id
|
|
89
|
+
}, safeParse(updates), {
|
|
90
|
+
upsert
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* get doc from db
|
|
96
|
+
* @param {string} dbName
|
|
97
|
+
* @param {string} id
|
|
98
|
+
* @return any
|
|
99
|
+
*/
|
|
100
|
+
export async function findOne (dbName, id) {
|
|
101
|
+
const res = await dbAction(dbName, 'findOne', {
|
|
102
|
+
_id: id
|
|
103
|
+
})
|
|
104
|
+
if (!res) {
|
|
105
|
+
return res
|
|
106
|
+
}
|
|
107
|
+
const { _id, ...rest } = res
|
|
108
|
+
return {
|
|
109
|
+
id: _id,
|
|
110
|
+
...decObj(rest)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* get all data as array from databse
|
|
116
|
+
* @param {string} dbName
|
|
117
|
+
*/
|
|
118
|
+
export async function find (dbName) {
|
|
119
|
+
const res = await dbAction(dbName, 'find', {}) || []
|
|
120
|
+
return res.map(r => {
|
|
121
|
+
const { _id, ...rest } = r
|
|
122
|
+
return {
|
|
123
|
+
id: _id,
|
|
124
|
+
...decObj(rest)
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* get value from database: data
|
|
131
|
+
* @param {string} name
|
|
132
|
+
* @return any
|
|
133
|
+
*/
|
|
134
|
+
export async function getData (name) {
|
|
135
|
+
const res = await dbAction('data', 'findOne', {
|
|
136
|
+
_id: name
|
|
137
|
+
})
|
|
138
|
+
return res ? res.value : undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* get sorted data from db
|
|
143
|
+
* @param {string} dbName
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
export async function fetchInitData (dbName) {
|
|
147
|
+
const res = await find(dbName)
|
|
148
|
+
const order = await getData(`${dbName}:order`)
|
|
149
|
+
const r = res.sort((a, b) => {
|
|
150
|
+
const ai = findIndex(order, r => r === a.id)
|
|
151
|
+
const bi = findIndex(order, r => r === b.id)
|
|
152
|
+
return ai - bi
|
|
153
|
+
})
|
|
154
|
+
return JSON.stringify(r)
|
|
155
|
+
}
|