beervid-app-cli 0.1.0 → 0.2.0
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/SKILL.md +19 -1
- package/dist/cli.mjs +72 -6
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -291,9 +291,13 @@ OAuth 回调
|
|
|
291
291
|
|
|
292
292
|
统一使用已安装的 `beervid` 命令;
|
|
293
293
|
|
|
294
|
-
**前置条件:**
|
|
294
|
+
**前置条件:** 设置 APP_KEY 后即可使用(任选一种方式):
|
|
295
295
|
|
|
296
296
|
```bash
|
|
297
|
+
# 方式一:通过 config 命令持久化(推荐,设置一次永久生效)
|
|
298
|
+
beervid config --app-key "your-api-key"
|
|
299
|
+
|
|
300
|
+
# 方式二:通过环境变量(优先级高于 config)
|
|
297
301
|
export BEERVID_APP_KEY="your-api-key"
|
|
298
302
|
export BEERVID_APP_BASE_URL="https://open.beervid.ai" # 可选,有默认值
|
|
299
303
|
```
|
|
@@ -302,6 +306,7 @@ export BEERVID_APP_BASE_URL="https://open.beervid.ai" # 可选,有默认值
|
|
|
302
306
|
|
|
303
307
|
| 命令 | 功能 | 核心参数 |
|
|
304
308
|
| -------------------------- | ------------------------------ | --------------------------------------------------- |
|
|
309
|
+
| `beervid config` | 设置/查看全局配置 | `--app-key <key> [--base-url <url>] [--show]` |
|
|
305
310
|
| `beervid get-oauth-url` | 获取 OAuth 授权链接 | `--type tt\|tts` |
|
|
306
311
|
| `beervid get-account-info` | 查询账号信息 | `--type TT\|TTS --account-id <id>` |
|
|
307
312
|
| `beervid upload` | 上传视频(支持本地文件和 URL) | `--file <路径或URL> [--type tts --creator-id <id>]` |
|
|
@@ -314,6 +319,19 @@ export BEERVID_APP_BASE_URL="https://open.beervid.ai" # 可选,有默认值
|
|
|
314
319
|
|
|
315
320
|
### 使用示例
|
|
316
321
|
|
|
322
|
+
#### 设置全局配置
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# 设置 APP_KEY(持久化到 ~/.beervid/config.json)
|
|
326
|
+
beervid config --app-key k9aqh41e...
|
|
327
|
+
|
|
328
|
+
# 设置自定义 API 地址
|
|
329
|
+
beervid config --base-url https://custom.api.com
|
|
330
|
+
|
|
331
|
+
# 查看当前配置(APP_KEY 脱敏显示)
|
|
332
|
+
beervid config --show
|
|
333
|
+
```
|
|
334
|
+
|
|
317
335
|
#### 获取授权链接
|
|
318
336
|
|
|
319
337
|
```bash
|
package/dist/cli.mjs
CHANGED
|
@@ -4,18 +4,44 @@
|
|
|
4
4
|
import cac from "cac";
|
|
5
5
|
|
|
6
6
|
// src/client/index.ts
|
|
7
|
-
import { readFileSync, existsSync } from "fs";
|
|
7
|
+
import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
|
|
8
8
|
import { resolve, basename } from "path";
|
|
9
|
+
|
|
10
|
+
// src/config.ts
|
|
11
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
import { homedir } from "os";
|
|
14
|
+
var CONFIG_DIR = join(homedir(), ".beervid");
|
|
15
|
+
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
16
|
+
function loadConfig() {
|
|
17
|
+
if (!existsSync(CONFIG_FILE)) return {};
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function saveConfig(config) {
|
|
25
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
26
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
27
|
+
}
|
|
28
|
+
function getConfigPath() {
|
|
29
|
+
return CONFIG_FILE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/client/index.ts
|
|
9
33
|
function getApiKey() {
|
|
10
|
-
const key = process.env["BEERVID_APP_KEY"];
|
|
34
|
+
const key = process.env["BEERVID_APP_KEY"] || loadConfig().appKey;
|
|
11
35
|
if (!key) {
|
|
12
|
-
console.error("\u9519\u8BEF: \u8BF7\u8BBE\u7F6E\
|
|
36
|
+
console.error("\u9519\u8BEF: \u8BF7\u5148\u8BBE\u7F6E APP_KEY\uFF0C\u4EFB\u9009\u4E00\u79CD\u65B9\u5F0F:");
|
|
37
|
+
console.error(" 1. beervid config --app-key <your-key>");
|
|
38
|
+
console.error(" 2. export BEERVID_APP_KEY=<your-key>");
|
|
13
39
|
process.exit(1);
|
|
14
40
|
}
|
|
15
41
|
return key;
|
|
16
42
|
}
|
|
17
43
|
function getBaseUrl() {
|
|
18
|
-
return process.env["BEERVID_APP_BASE_URL"]
|
|
44
|
+
return process.env["BEERVID_APP_BASE_URL"] || loadConfig().baseUrl || "https://open.beervid.ai";
|
|
19
45
|
}
|
|
20
46
|
async function handleResponse(res, path) {
|
|
21
47
|
if (!res.ok && res.status >= 500) {
|
|
@@ -79,11 +105,11 @@ function detectInputType(input2) {
|
|
|
79
105
|
}
|
|
80
106
|
function localFileToFile(filePath) {
|
|
81
107
|
const absPath = resolve(filePath);
|
|
82
|
-
if (!
|
|
108
|
+
if (!existsSync2(absPath)) {
|
|
83
109
|
console.error(`\u9519\u8BEF: \u6587\u4EF6\u4E0D\u5B58\u5728 \u2014 ${absPath}`);
|
|
84
110
|
process.exit(1);
|
|
85
111
|
}
|
|
86
|
-
const buffer =
|
|
112
|
+
const buffer = readFileSync2(absPath);
|
|
87
113
|
const fileName = basename(absPath);
|
|
88
114
|
const ext = fileName.split(".").pop()?.toLowerCase();
|
|
89
115
|
const mimeMap = {
|
|
@@ -1105,8 +1131,48 @@ function register9(cli2) {
|
|
|
1105
1131
|
);
|
|
1106
1132
|
}
|
|
1107
1133
|
|
|
1134
|
+
// src/commands/config.ts
|
|
1135
|
+
function register10(cli2) {
|
|
1136
|
+
cli2.command("config", "\u8BBE\u7F6E BEERVID_APP_KEY \u7B49\u5168\u5C40\u914D\u7F6E").option("--app-key <key>", "\u8BBE\u7F6E APP_KEY\uFF08\u6301\u4E45\u5316\u5230 ~/.beervid/config.json\uFF09").option("--base-url <url>", "\u8BBE\u7F6E API \u57FA\u7840 URL").option("--show", "\u663E\u793A\u5F53\u524D\u914D\u7F6E").action((options) => {
|
|
1137
|
+
if (options.show) {
|
|
1138
|
+
const config2 = loadConfig();
|
|
1139
|
+
console.log(`\u914D\u7F6E\u6587\u4EF6: ${getConfigPath()}
|
|
1140
|
+
`);
|
|
1141
|
+
if (!config2.appKey && !config2.baseUrl) {
|
|
1142
|
+
console.log("\uFF08\u6682\u65E0\u914D\u7F6E\uFF09");
|
|
1143
|
+
} else {
|
|
1144
|
+
if (config2.appKey) {
|
|
1145
|
+
const masked = config2.appKey.length > 8 ? config2.appKey.slice(0, 4) + "****" + config2.appKey.slice(-4) : "****";
|
|
1146
|
+
console.log(`APP_KEY: ${masked}`);
|
|
1147
|
+
}
|
|
1148
|
+
if (config2.baseUrl) {
|
|
1149
|
+
console.log(`BASE_URL: ${config2.baseUrl}`);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
if (!options.appKey && !options.baseUrl) {
|
|
1155
|
+
console.error("\u8BF7\u6307\u5B9A\u8981\u8BBE\u7F6E\u7684\u914D\u7F6E\u9879\uFF0C\u4F8B\u5982:\n");
|
|
1156
|
+
console.error(" beervid config --app-key <your-key>");
|
|
1157
|
+
console.error(" beervid config --base-url <url>");
|
|
1158
|
+
console.error(" beervid config --show");
|
|
1159
|
+
process.exit(1);
|
|
1160
|
+
}
|
|
1161
|
+
const config = loadConfig();
|
|
1162
|
+
if (options.appKey) {
|
|
1163
|
+
config.appKey = options.appKey;
|
|
1164
|
+
}
|
|
1165
|
+
if (options.baseUrl) {
|
|
1166
|
+
config.baseUrl = options.baseUrl;
|
|
1167
|
+
}
|
|
1168
|
+
saveConfig(config);
|
|
1169
|
+
console.log("\u914D\u7F6E\u5DF2\u4FDD\u5B58\u5230", getConfigPath());
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1108
1173
|
// src/cli.ts
|
|
1109
1174
|
var cli = cac("beervid");
|
|
1175
|
+
register10(cli);
|
|
1110
1176
|
register(cli);
|
|
1111
1177
|
register2(cli);
|
|
1112
1178
|
register3(cli);
|