electerm-data-tool 2.1.8 → 2.1.9
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/README.md +85 -63
- package/README.zh-CN.md +89 -66
- package/package.json +1 -1
- package/src/common/app-props.js +13 -0
- package/src/index.js +13 -0
- package/src/migrate/migrate-1-to-2.js +11 -2
- package/src/nedb.js +11 -2
- package/src/sqlite.js +20 -4
package/README.md
CHANGED
|
@@ -51,39 +51,13 @@ Available commands:
|
|
|
51
51
|
- `--help` - Show help information
|
|
52
52
|
- `--version` - Show version number
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
### Global Options
|
|
55
55
|
|
|
56
|
+
- `--app-type <type>` - Specify application type (`desktop` or `web`)
|
|
57
|
+
- `desktop` (default): Standard Electerm desktop application
|
|
58
|
+
- `web`: Electerm web application with different path structure
|
|
56
59
|
- `-d, --data-path <path>` - Custom path to electerm data directory (for portable installations)
|
|
57
60
|
|
|
58
|
-
### Custom Data Path (Portable Support)
|
|
59
|
-
|
|
60
|
-
For portable installations where Electerm data is stored in a custom location, use the `--data-path` option:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# Export data from custom location
|
|
64
|
-
electerm-data-tool --data-path /path/to/portable/electerm export backup.json
|
|
65
|
-
|
|
66
|
-
# Migrate data in custom location
|
|
67
|
-
electerm-data-tool --data-path /path/to/portable/electerm migrate
|
|
68
|
-
|
|
69
|
-
# Check info for custom location
|
|
70
|
-
electerm-data-tool --data-path /path/to/portable/electerm info
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Examples:**
|
|
74
|
-
```bash
|
|
75
|
-
# Windows portable installation
|
|
76
|
-
electerm-data-tool --data-path "C:\PortableApps\Electerm\Data" export backup.json
|
|
77
|
-
|
|
78
|
-
# macOS custom installation
|
|
79
|
-
electerm-data-tool --data-path "/Volumes/USB/electerm-data" migrate
|
|
80
|
-
|
|
81
|
-
# Linux custom installation
|
|
82
|
-
electerm-data-tool --data-path "/opt/electerm/data" info
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
The tool will validate that the specified path exists before proceeding.
|
|
86
|
-
|
|
87
61
|
### 1. Database Migration
|
|
88
62
|
|
|
89
63
|
Migrate your Electerm database from v1 (NeDB) to v2 (SQLite):
|
|
@@ -133,10 +107,91 @@ electerm-data-tool info
|
|
|
133
107
|
```
|
|
134
108
|
|
|
135
109
|
This will show:
|
|
110
|
+
|
|
136
111
|
- Database type (v1 NeDB or v2 SQLite)
|
|
137
112
|
- Number of records in each table
|
|
138
113
|
- Migration recommendations if applicable
|
|
139
114
|
|
|
115
|
+
## Application Types
|
|
116
|
+
|
|
117
|
+
The tool supports two application types with different path structures:
|
|
118
|
+
|
|
119
|
+
### Desktop Application (Default)
|
|
120
|
+
|
|
121
|
+
Standard Electerm desktop application using the default path structure:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
electerm-data-tool info
|
|
125
|
+
# or explicitly specify desktop type
|
|
126
|
+
electerm-data-tool info --app-type desktop
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Default paths:**
|
|
130
|
+
- NeDB files: `{APP_PATH}/electerm/users/default_user/electerm.*.nedb`
|
|
131
|
+
- SQLite files: `{APP_PATH}/electerm/users/default_user/electerm*.db`
|
|
132
|
+
|
|
133
|
+
### Web Application
|
|
134
|
+
|
|
135
|
+
Electerm web application with customized path structure:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
electerm-data-tool info --app-type web
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Web paths:**
|
|
142
|
+
- NeDB files: `{APP_PATH}/nedb-database/users/default_user/electerm.*.nedb`
|
|
143
|
+
- SQLite files: `{APP_PATH}/sqlite/electerm*.db`
|
|
144
|
+
|
|
145
|
+
### Custom Data Directory
|
|
146
|
+
|
|
147
|
+
You can specify a custom data directory using the `APP_PATH` environment variable:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Example for web application
|
|
151
|
+
export APP_PATH="/path/to/your/data"
|
|
152
|
+
electerm-data-tool migrate --app-type web
|
|
153
|
+
|
|
154
|
+
# Example for desktop application
|
|
155
|
+
export APP_PATH="/custom/path"
|
|
156
|
+
electerm-data-tool export backup.json --app-type desktop
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Complete web application example:**
|
|
160
|
+
```bash
|
|
161
|
+
# Set custom data directory
|
|
162
|
+
export APP_PATH="/Users/username/my-electerm-data"
|
|
163
|
+
|
|
164
|
+
# Check database status
|
|
165
|
+
electerm-data-tool info --app-type web
|
|
166
|
+
|
|
167
|
+
# Export data
|
|
168
|
+
electerm-data-tool export backup.json --app-type web
|
|
169
|
+
|
|
170
|
+
# Migrate from NeDB to SQLite
|
|
171
|
+
electerm-data-tool migrate --app-type web
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Portable Installations
|
|
175
|
+
|
|
176
|
+
For portable installations or custom data directories, use the `--data-path` option:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Using --data-path option (recommended for portable installations)
|
|
180
|
+
electerm-data-tool info --data-path "/path/to/portable/electerm" --app-type desktop
|
|
181
|
+
electerm-data-tool export backup.json --data-path "/path/to/portable/electerm" --app-type desktop
|
|
182
|
+
electerm-data-tool migrate --data-path "/path/to/portable/electerm" --app-type desktop
|
|
183
|
+
|
|
184
|
+
# Web application with custom data path
|
|
185
|
+
electerm-data-tool info --data-path "/custom/data/directory" --app-type web
|
|
186
|
+
electerm-data-tool export backup.json --data-path "/custom/data/directory" --app-type web
|
|
187
|
+
electerm-data-tool migrate --data-path "/custom/data/directory" --app-type web
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Path Priority:**
|
|
191
|
+
1. `--data-path` option (highest priority)
|
|
192
|
+
2. `APP_PATH` environment variable
|
|
193
|
+
3. Default system-specific path (lowest priority)
|
|
194
|
+
|
|
140
195
|
## Database Detection
|
|
141
196
|
|
|
142
197
|
The tool automatically detects whether you're using:
|
|
@@ -178,39 +233,6 @@ The exported JSON follows this structure:
|
|
|
178
233
|
- The `passwordEncrypted` flag is removed from exported data
|
|
179
234
|
- Exported passwords are human-readable for backup purposes
|
|
180
235
|
|
|
181
|
-
## Environment Variables
|
|
182
|
-
|
|
183
|
-
The tool supports the following environment variables for configuration:
|
|
184
|
-
|
|
185
|
-
### `APP_PATH` (Legacy)
|
|
186
|
-
|
|
187
|
-
Sets the base application data directory. This is the legacy method still supported for backward compatibility.
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
APP_PATH=/custom/path electerm-data-tool info
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Data Path Priority
|
|
194
|
-
|
|
195
|
-
The tool uses the following priority order for determining the data path:
|
|
196
|
-
|
|
197
|
-
1. **`--data-path` option** (highest priority) - Command-line argument
|
|
198
|
-
2. **`APP_PATH` environment variable** - Legacy support
|
|
199
|
-
3. **Default platform path** (lowest priority) - System default
|
|
200
|
-
|
|
201
|
-
**Examples:**
|
|
202
|
-
```bash
|
|
203
|
-
# Using command-line option (recommended)
|
|
204
|
-
electerm-data-tool --data-path /path/to/data info
|
|
205
|
-
|
|
206
|
-
# Using environment variable (legacy)
|
|
207
|
-
APP_PATH=/path/to/data electerm-data-tool info
|
|
208
|
-
|
|
209
|
-
# Command-line option overrides environment variable
|
|
210
|
-
APP_PATH=/path/one electerm-data-tool --data-path /path/two info
|
|
211
|
-
# Will use /path/two
|
|
212
|
-
```
|
|
213
|
-
|
|
214
236
|
## Requirements
|
|
215
237
|
|
|
216
238
|
- **Node.js**: 16.0.0 or higher
|
package/README.zh-CN.md
CHANGED
|
@@ -51,38 +51,12 @@ electerm-data-tool [command] [options]
|
|
|
51
51
|
- `--help` - 显示帮助信息
|
|
52
52
|
- `--version` - 显示版本号
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
### 全局选项
|
|
55
55
|
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
对于便携版或 Electerm 数据存储在自定义位置的情况,可通过 `--data-path` 选项指定数据目录:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# 从自定义目录导出数据
|
|
64
|
-
electerm-data-tool --data-path /path/to/portable/electerm export backup.json
|
|
65
|
-
|
|
66
|
-
# 迁移自定义目录数据
|
|
67
|
-
electerm-data-tool --data-path /path/to/portable/electerm migrate
|
|
68
|
-
|
|
69
|
-
# 查看自定义目录信息
|
|
70
|
-
electerm-data-tool --data-path /path/to/portable/electerm info
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**示例:**
|
|
74
|
-
```bash
|
|
75
|
-
# Windows 便携版
|
|
76
|
-
electerm-data-tool --data-path "C:\\PortableApps\\Electerm\\Data" export backup.json
|
|
77
|
-
|
|
78
|
-
# macOS U 盘
|
|
79
|
-
electerm-data-tool --data-path "/Volumes/USB/electerm-data" migrate
|
|
80
|
-
|
|
81
|
-
# Linux 自定义安装
|
|
82
|
-
electerm-data-tool --data-path "/opt/electerm/data" info
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
工具会校验指定路径是否存在。
|
|
56
|
+
- `--app-type <type>` - 指定应用类型(`desktop` 或 `web`)
|
|
57
|
+
- `desktop`(默认):标准 Electerm 桌面应用
|
|
58
|
+
- `web`:Electerm Web 应用,使用不同的路径结构
|
|
59
|
+
- `-d, --data-path <path>` - 自定义 Electerm 数据目录路径(用于便携安装)
|
|
86
60
|
|
|
87
61
|
### 1. 数据库迁移
|
|
88
62
|
|
|
@@ -122,10 +96,94 @@ electerm-data-tool info
|
|
|
122
96
|
```
|
|
123
97
|
|
|
124
98
|
将显示:
|
|
99
|
+
|
|
125
100
|
- 数据库类型(v1 NeDB 或 v2 SQLite)
|
|
126
101
|
- 各表数据条数
|
|
127
102
|
- 如需迁移会有提示
|
|
128
103
|
|
|
104
|
+
## 应用类型
|
|
105
|
+
|
|
106
|
+
工具支持两种应用类型,使用不同的路径结构:
|
|
107
|
+
|
|
108
|
+
### 桌面应用(默认)
|
|
109
|
+
|
|
110
|
+
标准 Electerm 桌面应用使用默认路径结构:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
electerm-data-tool info
|
|
114
|
+
# 或明确指定桌面类型
|
|
115
|
+
electerm-data-tool info --app-type desktop
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**默认路径:**
|
|
119
|
+
|
|
120
|
+
- NeDB 文件:`{APP_PATH}/electerm/users/default_user/electerm.*.nedb`
|
|
121
|
+
- SQLite 文件:`{APP_PATH}/electerm/users/default_user/electerm*.db`
|
|
122
|
+
|
|
123
|
+
### Web 应用
|
|
124
|
+
|
|
125
|
+
Electerm Web 应用使用自定义路径结构:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
electerm-data-tool info --app-type web
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Web 路径:**
|
|
132
|
+
|
|
133
|
+
- NeDB 文件:`{APP_PATH}/nedb-database/users/default_user/electerm.*.nedb`
|
|
134
|
+
- SQLite 文件:`{APP_PATH}/sqlite/electerm*.db`
|
|
135
|
+
|
|
136
|
+
### 自定义数据目录
|
|
137
|
+
|
|
138
|
+
可以使用 `APP_PATH` 环境变量指定自定义数据目录:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Web 应用示例
|
|
142
|
+
export APP_PATH="/path/to/your/data"
|
|
143
|
+
electerm-data-tool migrate --app-type web
|
|
144
|
+
|
|
145
|
+
# 桌面应用示例
|
|
146
|
+
export APP_PATH="/custom/path"
|
|
147
|
+
electerm-data-tool export backup.json --app-type desktop
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**完整 Web 应用示例:**
|
|
151
|
+
```bash
|
|
152
|
+
# 设置自定义数据目录
|
|
153
|
+
export APP_PATH="/Users/username/my-electerm-data"
|
|
154
|
+
|
|
155
|
+
# 检查数据库状态
|
|
156
|
+
electerm-data-tool info --app-type web
|
|
157
|
+
|
|
158
|
+
# 导出数据
|
|
159
|
+
electerm-data-tool export backup.json --app-type web
|
|
160
|
+
|
|
161
|
+
# 从 NeDB 迁移到 SQLite
|
|
162
|
+
electerm-data-tool migrate --app-type web
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 便携安装
|
|
166
|
+
|
|
167
|
+
对于便携安装或自定义数据目录,使用 `--data-path` 选项:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# 使用 --data-path 选项(推荐用于便携安装)
|
|
171
|
+
electerm-data-tool info --data-path "/path/to/portable/electerm" --app-type desktop
|
|
172
|
+
electerm-data-tool export backup.json --data-path "/path/to/portable/electerm" --app-type desktop
|
|
173
|
+
electerm-data-tool migrate --data-path "/path/to/portable/electerm" --app-type desktop
|
|
174
|
+
|
|
175
|
+
# Web 应用自定义数据路径
|
|
176
|
+
electerm-data-tool info --data-path "/custom/data/directory" --app-type web
|
|
177
|
+
electerm-data-tool export backup.json --data-path "/custom/data/directory" --app-type web
|
|
178
|
+
electerm-data-tool migrate --data-path "/custom/data/directory" --app-type web
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**路径优先级:**
|
|
182
|
+
|
|
183
|
+
1. `--data-path` 选项(最高优先级)
|
|
184
|
+
2. `APP_PATH` 环境变量
|
|
185
|
+
3. 默认系统路径(最低优先级)
|
|
186
|
+
|
|
129
187
|
## 数据库自动检测
|
|
130
188
|
|
|
131
189
|
工具会自动检测当前数据库类型:
|
|
@@ -181,41 +239,6 @@ electerm-data-tool info
|
|
|
181
239
|
迁移时 NeDB 文件会自动备份为:
|
|
182
240
|
- `electerm.bookmarks.nedb-{timestamp}.bak`
|
|
183
241
|
|
|
184
|
-
### 数据路径优先级
|
|
185
|
-
|
|
186
|
-
Electerm 数据工具会按如下优先级查找数据目录:
|
|
187
|
-
|
|
188
|
-
1. `--data-path` 命令行参数(最高优先级)
|
|
189
|
-
2. `APP_PATH` 环境变量(兼容旧用法)
|
|
190
|
-
3. 默认平台路径(最低优先级)
|
|
191
|
-
|
|
192
|
-
**示例:**
|
|
193
|
-
```bash
|
|
194
|
-
# 推荐:命令行参数
|
|
195
|
-
electerm-data-tool --data-path /path/to/data info
|
|
196
|
-
|
|
197
|
-
# 兼容旧用法:环境变量
|
|
198
|
-
APP_PATH=/path/to/data electerm-data-tool info
|
|
199
|
-
|
|
200
|
-
# 命令行参数优先生效
|
|
201
|
-
APP_PATH=/path/one electerm-data-tool --data-path /path/two info
|
|
202
|
-
# 实际使用 /path/two
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## 环境变量
|
|
206
|
-
|
|
207
|
-
工具支持如下环境变量进行配置:
|
|
208
|
-
|
|
209
|
-
### `APP_PATH`(兼容旧用法)
|
|
210
|
-
|
|
211
|
-
设置应用数据目录(旧用法,仍然兼容):
|
|
212
|
-
|
|
213
|
-
```bash
|
|
214
|
-
APP_PATH=/custom/path electerm-data-tool info
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
如需便携/自定义目录,推荐使用 `--data-path` 选项。
|
|
218
|
-
|
|
219
242
|
## 示例流程
|
|
220
243
|
|
|
221
244
|
```bash
|
package/package.json
CHANGED
package/src/common/app-props.js
CHANGED
|
@@ -28,12 +28,25 @@ function getElectermDataPath () {
|
|
|
28
28
|
return process.env.APP_PATH || getAppPath()
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// Global appType variable to store the application type
|
|
32
|
+
let globalAppType = 'desktop'
|
|
33
|
+
|
|
34
|
+
function setAppType (appType) {
|
|
35
|
+
globalAppType = appType || 'desktop'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getAppType () {
|
|
39
|
+
return globalAppType
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
// Use a getter to ensure we always get the current path
|
|
32
43
|
Object.defineProperty(exports, 'appPath', {
|
|
33
44
|
get: getElectermDataPath
|
|
34
45
|
})
|
|
35
46
|
|
|
36
47
|
exports.defaultUserName = 'default_user'
|
|
48
|
+
exports.setAppType = setAppType
|
|
49
|
+
exports.getAppType = getAppType
|
|
37
50
|
exports.packInfo = {
|
|
38
51
|
version
|
|
39
52
|
}
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ program
|
|
|
27
27
|
.name('electerm-data-tool')
|
|
28
28
|
.description('CLI tool for electerm data migration and export')
|
|
29
29
|
.version(pkg.version)
|
|
30
|
+
.option('--app-type <type>', 'Application type (desktop or web)', 'desktop')
|
|
30
31
|
.option('-d, --data-path <path>', 'Custom path to electerm data directory (for portable installations)')
|
|
31
32
|
.hook('preAction', (thisCommand) => {
|
|
32
33
|
// Set custom data path if provided
|
|
@@ -56,6 +57,10 @@ program
|
|
|
56
57
|
.description('Migrate electerm database from v1 (NeDB) to v2 (SQLite)')
|
|
57
58
|
.action(async () => {
|
|
58
59
|
try {
|
|
60
|
+
// Set appType from command line options
|
|
61
|
+
const { setAppType } = require('./common/app-props')
|
|
62
|
+
setAppType(program.opts().appType)
|
|
63
|
+
|
|
59
64
|
// Check Node.js version requirement for SQLite
|
|
60
65
|
const majorVersion = getNodeMajorVersion()
|
|
61
66
|
|
|
@@ -92,6 +97,10 @@ program
|
|
|
92
97
|
.argument('<output-path>', 'Path to the output JSON file')
|
|
93
98
|
.action(async (outputPath) => {
|
|
94
99
|
try {
|
|
100
|
+
// Set appType from command line options
|
|
101
|
+
const { setAppType } = require('./common/app-props')
|
|
102
|
+
setAppType(program.opts().appType)
|
|
103
|
+
|
|
95
104
|
log.info('Starting data export...')
|
|
96
105
|
|
|
97
106
|
// Show the data path being used
|
|
@@ -201,6 +210,10 @@ program
|
|
|
201
210
|
.description('Display information about the current electerm data')
|
|
202
211
|
.action(async () => {
|
|
203
212
|
try {
|
|
213
|
+
// Set appType from command line options
|
|
214
|
+
const { setAppType } = require('./common/app-props')
|
|
215
|
+
setAppType(program.opts().appType)
|
|
216
|
+
|
|
204
217
|
// Show the data path being used
|
|
205
218
|
const { appPath } = require('./common/app-props')
|
|
206
219
|
console.log('📊 Electerm Data Information')
|
|
@@ -4,11 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
const { resolve } = require('path')
|
|
6
6
|
const { existsSync, renameSync } = require('fs')
|
|
7
|
-
const { appPath, defaultUserName } = require('../common/app-props')
|
|
7
|
+
const { appPath, defaultUserName, getAppType } = require('../common/app-props')
|
|
8
8
|
const log = require('../common/log')
|
|
9
9
|
|
|
10
10
|
const reso = (name) => {
|
|
11
|
-
|
|
11
|
+
const appType = getAppType()
|
|
12
|
+
let basePath
|
|
13
|
+
|
|
14
|
+
if (appType === 'web') {
|
|
15
|
+
basePath = resolve(appPath, 'nedb-database', 'users', defaultUserName)
|
|
16
|
+
} else {
|
|
17
|
+
basePath = resolve(appPath, 'electerm', 'users', defaultUserName)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return resolve(basePath, `electerm.${name}.nedb`)
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
const tables = [
|
package/src/nedb.js
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
* nedb api wrapper
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const { appPath, defaultUserName } = require('./common/app-props')
|
|
5
|
+
const { appPath, defaultUserName, getAppType } = require('./common/app-props')
|
|
6
6
|
const { resolve } = require('path')
|
|
7
7
|
const Datastore = require('@yetzt/nedb')
|
|
8
8
|
const db = {}
|
|
9
9
|
|
|
10
10
|
const reso = (name) => {
|
|
11
|
-
|
|
11
|
+
const appType = getAppType()
|
|
12
|
+
let basePath
|
|
13
|
+
|
|
14
|
+
if (appType === 'web') {
|
|
15
|
+
basePath = resolve(appPath, 'nedb-database', 'users', defaultUserName)
|
|
16
|
+
} else {
|
|
17
|
+
basePath = resolve(appPath, 'electerm', 'users', defaultUserName)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return resolve(basePath, `electerm.${name}.nedb`)
|
|
12
21
|
}
|
|
13
22
|
const tables = [
|
|
14
23
|
'bookmarks',
|
package/src/sqlite.js
CHANGED
|
@@ -3,14 +3,30 @@
|
|
|
3
3
|
* Updated to use two database files: one for 'data' table, one for others
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { appPath, defaultUserName } = require('./common/app-props')
|
|
6
|
+
const { appPath, defaultUserName, getAppType } = require('./common/app-props')
|
|
7
7
|
const { resolve } = require('path')
|
|
8
8
|
const uid = require('./common/uid')
|
|
9
9
|
const { DatabaseSync } = require('node:sqlite')
|
|
10
10
|
|
|
11
|
-
// Define paths for two database files
|
|
12
|
-
|
|
13
|
-
const
|
|
11
|
+
// Define paths for two database files based on appType
|
|
12
|
+
function getDbPaths () {
|
|
13
|
+
const appType = getAppType()
|
|
14
|
+
let basePath
|
|
15
|
+
|
|
16
|
+
if (appType === 'web') {
|
|
17
|
+
// For web type, SQLite files go directly in sqlite folder
|
|
18
|
+
basePath = resolve(appPath, 'sqlite')
|
|
19
|
+
} else {
|
|
20
|
+
basePath = resolve(appPath, 'electerm', 'users', defaultUserName)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
mainDbPath: resolve(basePath, 'electerm.db'),
|
|
25
|
+
dataDbPath: resolve(basePath, 'electerm_data.db')
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { mainDbPath, dataDbPath } = getDbPaths()
|
|
14
30
|
|
|
15
31
|
// Create two database instances
|
|
16
32
|
const mainDb = new DatabaseSync(mainDbPath)
|