exflower-license-server 1.0.2 → 1.0.4

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.
Files changed (4) hide show
  1. package/README.md +15 -1
  2. package/db.js +23 -1
  3. package/package.json +1 -1
  4. package/routes.js +2 -2
package/README.md CHANGED
@@ -123,9 +123,23 @@ sudo systemctl enable --now exflower-license-server
123
123
  |------|--------|------|
124
124
  | `PORT` | `4001` | 服务端口 |
125
125
  | `ADMIN_TOKEN` | `exflower-admin-2026` | 管理后台鉴权 Token |
126
- | `LICENSE_DATA_DIR` | `./data` | 数据库持久化目录 |
126
+ | `LICENSE_DATA_DIR` | 见下方 | 数据库持久化目录 |
127
127
  | `NODE_ENV` | `production` | 运行环境 |
128
128
 
129
+ ### 数据持久化目录
130
+
131
+ 数据库文件 `license.db` 默认存储在以下位置(按优先级):
132
+
133
+ 1. **`LICENSE_DATA_DIR` 环境变量** — 如果设置,直接使用该路径
134
+ 2. **系统级目录**(推荐生产环境)
135
+ - Linux: `/var/lib/exflower/license-server/`
136
+ - Windows: `C:\ProgramData\exflower\license-server\`
137
+ - 需要进程对该目录有写入权限
138
+ 3. **用户目录 fallback**(无系统权限时自动使用)
139
+ - `~/.exflower/license-server/`
140
+
141
+ **⚠️ 重要**:npm 全局安装(`npm install -g`)或更新时,安装目录会被完全替换。默认不再将数据存放在包安装目录内,升级不会丢失已有数据。
142
+
129
143
  ## 管理后台
130
144
 
131
145
  启动后访问 `http://localhost:4001/admin`,使用 `ADMIN_TOKEN` 登录。
package/db.js CHANGED
@@ -6,8 +6,30 @@
6
6
  const Database = require('better-sqlite3');
7
7
  const path = require('path');
8
8
  const fs = require('fs');
9
+ const os = require('os');
9
10
 
10
- const DATA_DIR = process.env.LICENSE_DATA_DIR || path.join(__dirname, 'data');
11
+ function getDataDir() {
12
+ // 1. 环境变量优先
13
+ if (process.env.LICENSE_DATA_DIR) return process.env.LICENSE_DATA_DIR;
14
+
15
+ // 2. 尝试系统级持久化目录
16
+ const sysDir = process.platform === 'win32'
17
+ ? path.join(process.env.PROGRAMDATA || 'C:\\ProgramData', 'exflower', 'license-server')
18
+ : '/var/lib/exflower/license-server';
19
+
20
+ try {
21
+ if (!fs.existsSync(sysDir)) {
22
+ fs.mkdirSync(sysDir, { recursive: true });
23
+ }
24
+ fs.accessSync(sysDir, fs.constants.W_OK);
25
+ return sysDir;
26
+ } catch {
27
+ // 3. 无权限时 fallback 到用户目录
28
+ return path.join(os.homedir(), '.exflower', 'license-server');
29
+ }
30
+ }
31
+
32
+ const DATA_DIR = getDataDir();
11
33
  const DB_FILE = path.join(DATA_DIR, 'license.db');
12
34
 
13
35
  if (!fs.existsSync(DATA_DIR)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exflower-license-server",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "ExFlower License Server - 在线授权验证服务",
5
5
  "main": "index.js",
6
6
  "bin": {
package/routes.js CHANGED
@@ -332,8 +332,8 @@ function setupRoutes(app) {
332
332
  if (!type || !name || !content_json) {
333
333
  return res.status(400).json({ success: false, message: 'type, name, content_json are required' });
334
334
  }
335
- if (!['agent', 'crew', 'excard', 'workflow'].includes(type)) {
336
- return res.status(400).json({ success: false, message: 'type must be agent, crew, excard, or workflow' });
335
+ if (!['agent', 'crew', 'excard', 'workflow', 'doc'].includes(type)) {
336
+ return res.status(400).json({ success: false, message: 'type must be agent, crew, excard, workflow, or doc' });
337
337
  }
338
338
 
339
339
  // If company_id is provided, verify it exists