Skip to content

Commit 1db60c0

Browse files
author
while
committed
helper
1 parent 423b0a1 commit 1db60c0

35 files changed

Lines changed: 6006 additions & 6 deletions

‎package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
"debug:desktop": "pnpm run assets && pnpm --filter @sbot/app run dev",
2727

28+
"debug:helper": "pnpm --filter @sbot/helper run dev",
29+
"build:helper:macos": "pnpm --filter @sbot/helper run macos:build",
30+
"build:helper:windows": "pnpm --filter @sbot/helper run windows:build",
31+
"build:helper:linux": "pnpm --filter @sbot/helper run linux:build",
32+
2833
"build:macos": "pnpm run build:deps && pnpm run assets && pnpm --filter @sbot/app run macos:build",
2934
"build:windows": "pnpm run build:deps && pnpm run assets && pnpm --filter @sbot/app run windows:build",
3035
"build:linux": "pnpm run build:deps && pnpm run assets && pnpm --filter @sbot/app run linux:build",

‎packages/admin/src/views/chat/ChannelsView.vue‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,32 @@ const passwordVisible = ref<Record<string, boolean>>({})
459459
460460
const actionState = ref<Record<string, { loading: boolean; qrUrl?: string; qrLink?: string; qrType?: 'image' | 'link'; status?: string; error?: string }>>({})
461461
462+
const pasteJson = ref('')
463+
const pasteError = ref('')
464+
465+
function applyPasteJson() {
466+
pasteError.value = ''
467+
const raw = pasteJson.value.trim()
468+
if (!raw) { pasteError.value = '请粘贴 JSON 后再点击'; return }
469+
let obj: any
470+
try { obj = JSON.parse(raw) } catch (e: any) { pasteError.value = `JSON 解析失败: ${e.message}`; return }
471+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { pasteError.value = '需要一个 JSON 对象'; return }
472+
const schema = currentSchema.value
473+
let applied = 0
474+
const skipped: string[] = []
475+
for (const [k, v] of Object.entries(obj)) {
476+
if (k in schema) {
477+
form.value.config[k] = v as any
478+
applied++
479+
} else {
480+
skipped.push(k)
481+
}
482+
}
483+
if (applied === 0) { pasteError.value = `无可用字段(schema 内不存在: ${skipped.join(', ')})`; return }
484+
pasteJson.value = ''
485+
show(`已填入 ${applied} 个字段${skipped.length ? `(忽略 ${skipped.join(', ')})` : ''}`)
486+
}
487+
462488
function clearActionState() {
463489
actionState.value = {}
464490
}
@@ -859,6 +885,16 @@ async function refresh() {
859885
</SFormSection>
860886

861887
<SFormSection v-if="Object.keys(currentSchema).length > 0" :title="t('channels.section_plugin')">
888+
<SFormItem label="粘贴凭据 JSON">
889+
<details class="paste-json-block">
890+
<summary>从辅助工具导入</summary>
891+
<STextarea v-model="pasteJson" :rows="6" placeholder='{"userId":"...","passToken":"...","deviceId":"...","device":"客厅小爱"}' />
892+
<div class="paste-json-actions">
893+
<SButton type="outline" size="sm" @click="applyPasteJson">解析并填入</SButton>
894+
<span v-if="pasteError" class="qr-msg qr-msg-error">{{ pasteError }}</span>
895+
</div>
896+
</details>
897+
</SFormItem>
862898
<template v-for="(field, key) in currentSchema" :key="key">
863899
<SFormItem v-if="field.type === 'qrcode'" :label="field.label">
864900
<div class="qrcode-block">
@@ -1117,6 +1153,10 @@ async function refresh() {
11171153
.qr-msg-success { color: var(--sui-success); }
11181154
.qr-msg-error { color: var(--sui-danger); }
11191155
1156+
.paste-json-block summary { cursor: pointer; font-size: var(--sui-fs-sm); color: var(--sui-fg-muted); margin-bottom: var(--sui-sp-2); }
1157+
.paste-json-block[open] summary { color: var(--sui-fg); }
1158+
.paste-json-actions { display: flex; align-items: center; gap: var(--sui-sp-3); margin-top: var(--sui-sp-2); }
1159+
11201160
.session-avatar {
11211161
width: 28px;
11221162
height: 28px;

‎packages/channel.xiaoai/src/XiaoaiService.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export interface XiaoaiMessageArgs extends ChannelMessageArgs {
1717

1818
export interface XiaoaiServiceOptions {
1919
userId: string;
20-
password: string;
20+
password?: string;
21+
passToken?: string;
22+
deviceId?: string;
2123
device: string;
2224
heartbeat: number;
2325
textChunkLimit: number;
@@ -64,10 +66,10 @@ export class XiaoaiService implements IChannelService {
6466
}
6567

6668
async start(): Promise<void> {
67-
const { userId, password, device } = this.options;
69+
const { userId, password, passToken, deviceId, device } = this.options;
6870

6971
this.logger?.info(`XiaoAi logging in: ${userId}`);
70-
this.authed = await login({ userId, password });
72+
this.authed = await login({ userId, password: password ?? '', passToken, deviceId });
7173
this.logger?.info(`XiaoAi logged in: ${userId}`);
7274

7375
const allDevices = await getDeviceList(this.authed);

‎packages/channel.xiaoai/src/plugin.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ export const xiaoaiPlugin: ChannelPlugin = {
1919
password: {
2020
label: '密码',
2121
type: ConfigFieldType.Password,
22-
required: true,
23-
description: '小米账号密码',
22+
description: '小米账号密码(推荐用辅助工具登录,免填密码)',
23+
},
24+
passToken: {
25+
label: 'passToken',
26+
type: ConfigFieldType.Password,
27+
description: '小米 passToken,由辅助工具登录后导出',
28+
},
29+
deviceId: {
30+
label: 'deviceId',
31+
type: ConfigFieldType.String,
32+
description: 'PassportSDK 设备 ID,由辅助工具一并导出',
2433
},
2534
device: {
2635
label: '设备名称',
@@ -52,12 +61,16 @@ export const xiaoaiPlugin: ChannelPlugin = {
5261

5362
const userId = config.userId?.trim();
5463
const password = config.password?.trim();
64+
const passToken = config.passToken?.trim();
65+
const deviceId = config.deviceId?.trim();
5566
const device = config.device?.trim();
56-
if (!userId || !password || !device) return undefined;
67+
if (!userId || !device || (!password && !passToken)) return undefined;
5768

5869
const service = new XiaoaiService({
5970
userId,
6071
password,
72+
passToken,
73+
deviceId,
6174
device,
6275
heartbeat: Number(config.heartbeat) || 1000,
6376
textChunkLimit: Number(config.textChunkLimit) || 200,

‎packages/helper/.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
src-tauri/target/
4+
src-tauri/gen/

‎packages/helper/index.html‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>sbot 辅助工具</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="module" src="/src/main.ts"></script>
11+
</body>
12+
</html>

‎packages/helper/package.json‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@sbot/helper",
3+
"version": "0.0.1",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "tauri dev",
8+
"macos:build": "tauri build",
9+
"windows:build": "tauri build",
10+
"linux:build": "tauri build"
11+
},
12+
"dependencies": {
13+
"@tauri-apps/api": "^2",
14+
"vue": "^3.5.33",
15+
"vue-router": "^4.4.5"
16+
},
17+
"devDependencies": {
18+
"@tauri-apps/cli": "^2",
19+
"@vitejs/plugin-vue": "^6.0.6",
20+
"typescript": "catalog:",
21+
"vite": "^8.0.9"
22+
}
23+
}

0 commit comments

Comments
 (0)