refactor: 收敛Admin QQBot管理边界
This commit is contained in:
parent
c08aa84696
commit
b549e30dd5
@ -1,49 +1,28 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { getQqbotPluginOperationPage } from './index';
|
||||
const readApiFile = (name: string) =>
|
||||
readFileSync(new URL(name, import.meta.url), 'utf8');
|
||||
|
||||
vi.mock('#/api/request', () => ({
|
||||
requestClient: {
|
||||
get: vi.fn(),
|
||||
getBaseUrl: vi.fn(() => ''),
|
||||
},
|
||||
}));
|
||||
describe('qqbot core API caller boundary', () => {
|
||||
it('keeps plugin platform and NapCat scan routes out of the core caller', () => {
|
||||
const source = readApiFile('index.ts');
|
||||
|
||||
describe('qqbot plugin API wrappers', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
expect(source).not.toContain('/qqbot/plugin');
|
||||
expect(source).not.toContain('/qqbot/plugin-platform');
|
||||
expect(source).not.toContain('/qqbot/account/scan');
|
||||
});
|
||||
|
||||
it('uses the paged plugin operation endpoint for KtTable', async () => {
|
||||
const pageResult = {
|
||||
list: [],
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
total: 3,
|
||||
};
|
||||
vi.mocked(requestClient.get).mockResolvedValueOnce(pageResult);
|
||||
|
||||
await expect(
|
||||
getQqbotPluginOperationPage({
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
pluginKey: 'bangdream',
|
||||
triggerMode: 'command',
|
||||
}),
|
||||
).resolves.toBe(pageResult);
|
||||
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin/operation/page',
|
||||
{
|
||||
params: {
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
pluginKey: 'bangdream',
|
||||
triggerMode: 'command',
|
||||
},
|
||||
},
|
||||
it('keeps domain-specific caller routes in plugin and napcat callers', () => {
|
||||
expect(readApiFile('plugin.ts')).toEqual(
|
||||
expect.stringContaining('/qqbot/plugin/operation/page'),
|
||||
);
|
||||
expect(readApiFile('plugin.ts')).toEqual(
|
||||
expect.stringContaining('/qqbot/plugin-platform/runtime-events'),
|
||||
);
|
||||
expect(readApiFile('napcat.ts')).toEqual(
|
||||
expect.stringContaining('/qqbot/account/scan/events'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { NapcatLoginNewDeviceStatus } from './napcat';
|
||||
|
||||
import { encryptPassword } from '#/api/core/auth';
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
@ -93,39 +91,6 @@ export namespace QqbotApi {
|
||||
selfId: string;
|
||||
}
|
||||
|
||||
export interface AccountScanResult {
|
||||
accountId?: string;
|
||||
captchaUrl?: string;
|
||||
containerId?: string;
|
||||
containerName?: string;
|
||||
deviceVerifyUrl?: string;
|
||||
errorMessage?: string;
|
||||
expiresAt?: number;
|
||||
mode: 'create' | 'refresh';
|
||||
newDeviceQrcode?: string;
|
||||
newDeviceStatus?: NapcatLoginNewDeviceStatus;
|
||||
qrcode?: string;
|
||||
selfId?: string;
|
||||
sessionId?: string;
|
||||
status: 'error' | 'expired' | 'pending' | 'success';
|
||||
webuiPort?: null | number;
|
||||
}
|
||||
|
||||
export interface AccountScanEvent {
|
||||
createdAt: number;
|
||||
message: string;
|
||||
result?: AccountScanResult;
|
||||
status: 'error' | 'info' | 'processing' | 'success';
|
||||
step: string;
|
||||
}
|
||||
|
||||
export interface AccountScanCaptchaBody {
|
||||
randstr: string;
|
||||
sessionId: string;
|
||||
sid?: string;
|
||||
ticket: string;
|
||||
}
|
||||
|
||||
export interface Rule {
|
||||
cooldownMs: number;
|
||||
enabled: boolean;
|
||||
@ -391,62 +356,6 @@ export function kickQqbotAccount(selfId: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export function startQqbotAccountScanCreate() {
|
||||
return requestClient.post<QqbotApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/create',
|
||||
);
|
||||
}
|
||||
|
||||
export function startQqbotAccountScanRefresh(id: string) {
|
||||
return requestClient.post<QqbotApi.AccountScanResult>(
|
||||
`/qqbot/account/scan/refresh?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotAccountScanStatus(sessionId: string) {
|
||||
return requestClient.get<QqbotApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/status',
|
||||
{ params: { sessionId } },
|
||||
);
|
||||
}
|
||||
|
||||
export function refreshQqbotAccountScanQrcode(sessionId: string) {
|
||||
return requestClient.post<QqbotApi.AccountScanResult>(
|
||||
`/qqbot/account/scan/qrcode/refresh?sessionId=${sessionId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function submitQqbotAccountScanCaptcha(
|
||||
data: QqbotApi.AccountScanCaptchaBody,
|
||||
) {
|
||||
return requestClient.post<QqbotApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/captcha/submit',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export function cancelQqbotAccountScan(sessionId: string) {
|
||||
return requestClient.post<boolean>(
|
||||
`/qqbot/account/scan/cancel?sessionId=${sessionId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotAccountScanEventsUrl(sessionId: string) {
|
||||
return buildApiUrl(
|
||||
`/qqbot/account/scan/events?sessionId=${encodeURIComponent(sessionId)}`,
|
||||
);
|
||||
}
|
||||
|
||||
function buildApiUrl(path: string) {
|
||||
const baseUrl = requestClient.getBaseUrl() || '';
|
||||
if (!baseUrl) return path;
|
||||
if (/^https?:\/\//i.test(path)) return path;
|
||||
if (/^https?:\/\//i.test(baseUrl)) {
|
||||
return new URL(path, baseUrl).toString();
|
||||
}
|
||||
return `${baseUrl.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
||||
}
|
||||
|
||||
export function getQqbotRuleList(params: QqbotApi.Query) {
|
||||
return requestClient.get<QqbotApi.PageResult<QqbotApi.Rule>>(
|
||||
'/qqbot/rule/list',
|
||||
@ -595,57 +504,3 @@ export function testQqbotCommand(data: {
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginList(triggerMode?: QqbotApi.PluginTriggerMode) {
|
||||
return requestClient.get<QqbotApi.Plugin[]>('/qqbot/plugin/list', {
|
||||
params: { triggerMode },
|
||||
});
|
||||
}
|
||||
|
||||
export function getQqbotPluginOperationList(
|
||||
pluginKey?: string,
|
||||
triggerMode?: QqbotApi.PluginTriggerMode,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PluginOperation[]>(
|
||||
'/qqbot/plugin/operation/list',
|
||||
{ params: { pluginKey, triggerMode } },
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginOperationPage(
|
||||
params: QqbotApi.PluginOperationQuery,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PageResult<QqbotApi.PluginOperation>>(
|
||||
'/qqbot/plugin/operation/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginHealth(
|
||||
pluginKey?: string,
|
||||
triggerMode?: QqbotApi.PluginTriggerMode,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PluginHealth[]>('/qqbot/plugin/health', {
|
||||
params: { pluginKey, triggerMode },
|
||||
});
|
||||
}
|
||||
|
||||
export function getQqbotEventPluginList(params?: { selfId?: string }) {
|
||||
return requestClient.get<QqbotApi.EventPlugin[]>('/qqbot/plugin/event/list', {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
export function bindQqbotEventPlugin(selfId: string, pluginKey: string) {
|
||||
const params = new URLSearchParams({ pluginKey, selfId });
|
||||
return requestClient.post<QqbotApi.EventPlugin>(
|
||||
`/qqbot/plugin/event/bind?${params.toString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function unbindQqbotEventPlugin(selfId: string, pluginKey: string) {
|
||||
const params = new URLSearchParams({ pluginKey, selfId });
|
||||
return requestClient.post<boolean>(
|
||||
`/qqbot/plugin/event/unbind?${params.toString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,12 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import {
|
||||
cancelQqbotAccountScan,
|
||||
getNapcatNewDeviceStatusMessage,
|
||||
getQqbotAccountScanEventsUrl,
|
||||
getQqbotAccountScanStatus,
|
||||
NAPCAT_LOGIN_PROGRESS_LABELS,
|
||||
refreshQqbotAccountScanQrcode,
|
||||
resolveNapcatLoginDisplayQrcode,
|
||||
startQqbotAccountScanCreate,
|
||||
startQqbotAccountScanRefresh,
|
||||
submitQqbotAccountScanCaptcha,
|
||||
} from './napcat';
|
||||
|
||||
vi.mock('#/api/request', () => ({
|
||||
requestClient: {
|
||||
get: vi.fn(),
|
||||
getBaseUrl: vi.fn(() => '/api'),
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('napcat login display helpers', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('keeps all Chinese progress labels required by the login flow', () => {
|
||||
expect(NAPCAT_LOGIN_PROGRESS_LABELS).toMatchObject({
|
||||
'captcha-submit': '验证码已提交,等待确认',
|
||||
@ -55,4 +76,59 @@ describe('napcat login display helpers', () => {
|
||||
'new-device-verified',
|
||||
]);
|
||||
});
|
||||
|
||||
it('owns create, refresh, status, QR refresh, captcha, cancel, and SSE caller routes', async () => {
|
||||
const scanResult = {
|
||||
mode: 'refresh' as const,
|
||||
sessionId: 'scan-1',
|
||||
status: 'pending' as const,
|
||||
};
|
||||
vi.mocked(requestClient.post).mockResolvedValue(scanResult);
|
||||
vi.mocked(requestClient.get).mockResolvedValue(scanResult);
|
||||
|
||||
await expect(startQqbotAccountScanCreate()).resolves.toBe(scanResult);
|
||||
await expect(startQqbotAccountScanRefresh('account-1')).resolves.toBe(
|
||||
scanResult,
|
||||
);
|
||||
await expect(getQqbotAccountScanStatus('scan-1')).resolves.toBe(scanResult);
|
||||
await expect(refreshQqbotAccountScanQrcode('scan-1')).resolves.toBe(
|
||||
scanResult,
|
||||
);
|
||||
await expect(
|
||||
submitQqbotAccountScanCaptcha({
|
||||
randstr: '@rand',
|
||||
sessionId: 'scan-1',
|
||||
ticket: 'ticket',
|
||||
}),
|
||||
).resolves.toBe(scanResult);
|
||||
await expect(cancelQqbotAccountScan('scan-1')).resolves.toBe(scanResult);
|
||||
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/create',
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/refresh?id=account-1',
|
||||
);
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/status',
|
||||
{ params: { sessionId: 'scan-1' } },
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/qrcode/refresh?sessionId=scan-1',
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/captcha/submit',
|
||||
{
|
||||
randstr: '@rand',
|
||||
sessionId: 'scan-1',
|
||||
ticket: 'ticket',
|
||||
},
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/account/scan/cancel?sessionId=scan-1',
|
||||
);
|
||||
expect(getQqbotAccountScanEventsUrl('scan 1')).toBe(
|
||||
'/api/qqbot/account/scan/events?sessionId=scan%201',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export type NapcatLoginNewDeviceStatus =
|
||||
| 'confirming'
|
||||
| 'expired'
|
||||
@ -6,6 +8,41 @@ export type NapcatLoginNewDeviceStatus =
|
||||
| 'scanned'
|
||||
| 'verified';
|
||||
|
||||
export namespace QqbotNapcatApi {
|
||||
export interface AccountScanResult {
|
||||
accountId?: string;
|
||||
captchaUrl?: string;
|
||||
containerId?: string;
|
||||
containerName?: string;
|
||||
deviceVerifyUrl?: string;
|
||||
errorMessage?: string;
|
||||
expiresAt?: number;
|
||||
mode: 'create' | 'refresh';
|
||||
newDeviceQrcode?: string;
|
||||
newDeviceStatus?: NapcatLoginNewDeviceStatus;
|
||||
qrcode?: string;
|
||||
selfId?: string;
|
||||
sessionId?: string;
|
||||
status: 'error' | 'expired' | 'pending' | 'success';
|
||||
webuiPort?: null | number;
|
||||
}
|
||||
|
||||
export interface AccountScanEvent {
|
||||
createdAt: number;
|
||||
message: string;
|
||||
result?: AccountScanResult;
|
||||
status: 'error' | 'info' | 'processing' | 'success';
|
||||
step: string;
|
||||
}
|
||||
|
||||
export interface AccountScanCaptchaBody {
|
||||
randstr: string;
|
||||
sessionId: string;
|
||||
sid?: string;
|
||||
ticket: string;
|
||||
}
|
||||
}
|
||||
|
||||
export type NapcatLoginDisplayQrcodeSource = {
|
||||
captchaUrl?: string;
|
||||
newDeviceQrcode?: string;
|
||||
@ -48,3 +85,59 @@ export function getNapcatNewDeviceStatusMessage(
|
||||
if (status === 'failed') return '新设备验证失败';
|
||||
return '新设备二维码待扫码';
|
||||
}
|
||||
|
||||
export function startQqbotAccountScanCreate() {
|
||||
return requestClient.post<QqbotNapcatApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/create',
|
||||
);
|
||||
}
|
||||
|
||||
export function startQqbotAccountScanRefresh(id: string) {
|
||||
return requestClient.post<QqbotNapcatApi.AccountScanResult>(
|
||||
`/qqbot/account/scan/refresh?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotAccountScanStatus(sessionId: string) {
|
||||
return requestClient.get<QqbotNapcatApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/status',
|
||||
{ params: { sessionId } },
|
||||
);
|
||||
}
|
||||
|
||||
export function refreshQqbotAccountScanQrcode(sessionId: string) {
|
||||
return requestClient.post<QqbotNapcatApi.AccountScanResult>(
|
||||
`/qqbot/account/scan/qrcode/refresh?sessionId=${sessionId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function submitQqbotAccountScanCaptcha(
|
||||
data: QqbotNapcatApi.AccountScanCaptchaBody,
|
||||
) {
|
||||
return requestClient.post<QqbotNapcatApi.AccountScanResult>(
|
||||
'/qqbot/account/scan/captcha/submit',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export function cancelQqbotAccountScan(sessionId: string) {
|
||||
return requestClient.post<boolean>(
|
||||
`/qqbot/account/scan/cancel?sessionId=${sessionId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotAccountScanEventsUrl(sessionId: string) {
|
||||
return buildApiUrl(
|
||||
`/qqbot/account/scan/events?sessionId=${encodeURIComponent(sessionId)}`,
|
||||
);
|
||||
}
|
||||
|
||||
function buildApiUrl(path: string) {
|
||||
const baseUrl = requestClient.getBaseUrl() || '';
|
||||
if (!baseUrl) return path;
|
||||
if (/^https?:\/\//i.test(path)) return path;
|
||||
if (/^https?:\/\//i.test(baseUrl)) {
|
||||
return new URL(path, baseUrl).toString();
|
||||
}
|
||||
return `${baseUrl.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
||||
}
|
||||
|
||||
102
apps/web-antdv-next/src/api/qqbot/plugin.spec.ts
Normal file
102
apps/web-antdv-next/src/api/qqbot/plugin.spec.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import {
|
||||
enableQqbotPluginInstallation,
|
||||
getQqbotPluginAccountBindings,
|
||||
getQqbotPluginOperationPage,
|
||||
getQqbotPluginPlatformInstallations,
|
||||
getQqbotPluginRuntimeEvents,
|
||||
installLocalQqbotPluginPackage,
|
||||
uploadQqbotPluginPackage,
|
||||
validateQqbotPluginManifest,
|
||||
} from './plugin';
|
||||
|
||||
vi.mock('#/api/request', () => ({
|
||||
requestClient: {
|
||||
get: vi.fn(),
|
||||
getBaseUrl: vi.fn(() => ''),
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('qqbot plugin API wrappers', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('uses the paged plugin operation endpoint for KtTable', async () => {
|
||||
const pageResult = {
|
||||
list: [],
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
total: 3,
|
||||
};
|
||||
vi.mocked(requestClient.get).mockResolvedValueOnce(pageResult);
|
||||
|
||||
await expect(
|
||||
getQqbotPluginOperationPage({
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
pluginKey: 'bangdream',
|
||||
triggerMode: 'command',
|
||||
}),
|
||||
).resolves.toBe(pageResult);
|
||||
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin/operation/page',
|
||||
{
|
||||
params: {
|
||||
pageNo: 2,
|
||||
pageSize: 1,
|
||||
pluginKey: 'bangdream',
|
||||
triggerMode: 'command',
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('owns plugin-platform management caller routes', async () => {
|
||||
const manifest = { capabilities: [], key: 'demo' };
|
||||
const packageBody = { manifest, packagePath: '/tmp/demo.zip' };
|
||||
vi.mocked(requestClient.get).mockResolvedValue([]);
|
||||
vi.mocked(requestClient.post).mockResolvedValue({});
|
||||
|
||||
await getQqbotPluginPlatformInstallations();
|
||||
await uploadQqbotPluginPackage(packageBody);
|
||||
await validateQqbotPluginManifest(manifest);
|
||||
await installLocalQqbotPluginPackage(packageBody);
|
||||
await enableQqbotPluginInstallation('installation-1');
|
||||
await getQqbotPluginRuntimeEvents('demo');
|
||||
await getQqbotPluginAccountBindings('demo');
|
||||
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/installations',
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/upload',
|
||||
packageBody,
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/validate',
|
||||
{ manifest },
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/install-local',
|
||||
packageBody,
|
||||
);
|
||||
expect(requestClient.post).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/enable',
|
||||
{ id: 'installation-1' },
|
||||
);
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/runtime-events',
|
||||
{ params: { pluginId: 'demo' } },
|
||||
);
|
||||
expect(requestClient.get).toHaveBeenCalledWith(
|
||||
'/qqbot/plugin-platform/account-bindings',
|
||||
{ params: { pluginId: 'demo' } },
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -1,5 +1,7 @@
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { QqbotApi } from './index';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace QqbotPluginPlatformApi {
|
||||
@ -66,6 +68,60 @@ export namespace QqbotPluginPlatformApi {
|
||||
}
|
||||
}
|
||||
|
||||
export function getQqbotPluginList(triggerMode?: QqbotApi.PluginTriggerMode) {
|
||||
return requestClient.get<QqbotApi.Plugin[]>('/qqbot/plugin/list', {
|
||||
params: { triggerMode },
|
||||
});
|
||||
}
|
||||
|
||||
export function getQqbotPluginOperationList(
|
||||
pluginKey?: string,
|
||||
triggerMode?: QqbotApi.PluginTriggerMode,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PluginOperation[]>(
|
||||
'/qqbot/plugin/operation/list',
|
||||
{ params: { pluginKey, triggerMode } },
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginOperationPage(
|
||||
params: QqbotApi.PluginOperationQuery,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PageResult<QqbotApi.PluginOperation>>(
|
||||
'/qqbot/plugin/operation/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginHealth(
|
||||
pluginKey?: string,
|
||||
triggerMode?: QqbotApi.PluginTriggerMode,
|
||||
) {
|
||||
return requestClient.get<QqbotApi.PluginHealth[]>('/qqbot/plugin/health', {
|
||||
params: { pluginKey, triggerMode },
|
||||
});
|
||||
}
|
||||
|
||||
export function getQqbotEventPluginList(params?: { selfId?: string }) {
|
||||
return requestClient.get<QqbotApi.EventPlugin[]>('/qqbot/plugin/event/list', {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
export function bindQqbotEventPlugin(selfId: string, pluginKey: string) {
|
||||
const params = new URLSearchParams({ pluginKey, selfId });
|
||||
return requestClient.post<QqbotApi.EventPlugin>(
|
||||
`/qqbot/plugin/event/bind?${params.toString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function unbindQqbotEventPlugin(selfId: string, pluginKey: string) {
|
||||
const params = new URLSearchParams({ pluginKey, selfId });
|
||||
return requestClient.post<boolean>(
|
||||
`/qqbot/plugin/event/unbind?${params.toString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getQqbotPluginPlatformInstallations() {
|
||||
return requestClient.get<QqbotPluginPlatformApi.Installation[]>(
|
||||
'/qqbot/plugin-platform/installations',
|
||||
|
||||
@ -12,14 +12,16 @@ import { message, Spin, Tabs, Tag } from 'antdv-next';
|
||||
import {
|
||||
bindQqbotAccountCommand,
|
||||
bindQqbotAccountRule,
|
||||
bindQqbotEventPlugin,
|
||||
getQqbotCommandList,
|
||||
getQqbotEventPluginList,
|
||||
getQqbotRuleList,
|
||||
unbindQqbotAccountCommand,
|
||||
unbindQqbotAccountRule,
|
||||
unbindQqbotEventPlugin,
|
||||
} from '#/api/qqbot';
|
||||
import {
|
||||
bindQqbotEventPlugin,
|
||||
getQqbotEventPluginList,
|
||||
unbindQqbotEventPlugin,
|
||||
} from '#/api/qqbot/plugin';
|
||||
import { KtTable } from '#/components/ktTable';
|
||||
|
||||
import {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import type { TableColumnType } from 'antdv-next';
|
||||
|
||||
import type { QqbotApi } from '#/api/qqbot';
|
||||
import type { NapcatLoginNewDeviceStatus } from '#/api/qqbot/napcat';
|
||||
import type {
|
||||
NapcatLoginNewDeviceStatus,
|
||||
QqbotNapcatApi,
|
||||
} from '#/api/qqbot/napcat';
|
||||
import type {
|
||||
KtTableApi,
|
||||
KtTableButton,
|
||||
@ -27,22 +30,22 @@ import {
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
cancelQqbotAccountScan,
|
||||
createQqbotAccount,
|
||||
deleteQqbotAccount,
|
||||
getQqbotAccountList,
|
||||
getQqbotAccountScanEventsUrl,
|
||||
getQqbotAccountScanStatus,
|
||||
kickQqbotAccount,
|
||||
refreshQqbotAccountScanQrcode,
|
||||
startQqbotAccountScanCreate,
|
||||
startQqbotAccountScanRefresh,
|
||||
submitQqbotAccountScanCaptcha,
|
||||
updateQqbotAccount,
|
||||
} from '#/api/qqbot';
|
||||
import {
|
||||
cancelQqbotAccountScan,
|
||||
getNapcatNewDeviceStatusMessage,
|
||||
getQqbotAccountScanEventsUrl,
|
||||
getQqbotAccountScanStatus,
|
||||
refreshQqbotAccountScanQrcode,
|
||||
resolveNapcatLoginDisplayQrcode,
|
||||
startQqbotAccountScanCreate,
|
||||
startQqbotAccountScanRefresh,
|
||||
submitQqbotAccountScanCaptcha,
|
||||
} from '#/api/qqbot/napcat';
|
||||
import { KtTable, useKtTable } from '#/components/ktTable';
|
||||
|
||||
@ -87,7 +90,7 @@ export default defineComponent({
|
||||
const scanQrcodeImageFailed = ref(false);
|
||||
const scanQrcodeRevision = ref(0);
|
||||
const scanQrcodeText = ref('');
|
||||
const scanEvents = ref<QqbotApi.AccountScanEvent[]>([]);
|
||||
const scanEvents = ref<QqbotNapcatApi.AccountScanEvent[]>([]);
|
||||
const scanState = reactive<{
|
||||
captchaUrl?: string;
|
||||
containerId?: string;
|
||||
@ -434,7 +437,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function applyScanResult(
|
||||
result: QqbotApi.AccountScanResult,
|
||||
result: QqbotNapcatApi.AccountScanResult,
|
||||
options: { reloadQrcode?: boolean } = {},
|
||||
) {
|
||||
scanState.captchaUrl = result.captchaUrl;
|
||||
@ -572,7 +575,7 @@ export default defineComponent({
|
||||
|
||||
function handleScanEvent(payload: string) {
|
||||
try {
|
||||
const event = JSON.parse(payload) as QqbotApi.AccountScanEvent;
|
||||
const event = JSON.parse(payload) as QqbotNapcatApi.AccountScanEvent;
|
||||
const index = scanEvents.value.findIndex(
|
||||
(item) => item.step === event.step,
|
||||
);
|
||||
@ -666,7 +669,9 @@ export default defineComponent({
|
||||
return '扫码登录请求失败';
|
||||
}
|
||||
|
||||
function getScanStepStatus(status: QqbotApi.AccountScanEvent['status']) {
|
||||
function getScanStepStatus(
|
||||
status: QqbotNapcatApi.AccountScanEvent['status'],
|
||||
) {
|
||||
if (status === 'error') return 'error';
|
||||
if (status === 'processing') return 'process';
|
||||
if (status === 'success') return 'finish';
|
||||
@ -1192,7 +1197,7 @@ export default defineComponent({
|
||||
|
||||
function requestTencentCaptcha(
|
||||
proofWaterUrl: string,
|
||||
): Promise<Omit<QqbotApi.AccountScanCaptchaBody, 'sessionId'>> {
|
||||
): Promise<Omit<QqbotNapcatApi.AccountScanCaptchaBody, 'sessionId'>> {
|
||||
const params = parseUrlParams(proofWaterUrl);
|
||||
const appid = params.aid || '2081081773';
|
||||
const sid = params.sid || '';
|
||||
@ -1209,7 +1214,7 @@ function requestTencentCaptcha(
|
||||
let settled = false;
|
||||
const finish = (
|
||||
error?: Error,
|
||||
value?: Omit<QqbotApi.AccountScanCaptchaBody, 'sessionId'>,
|
||||
value?: Omit<QqbotNapcatApi.AccountScanCaptchaBody, 'sessionId'>,
|
||||
) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
|
||||
@ -19,12 +19,14 @@ import {
|
||||
createQqbotCommand,
|
||||
deleteQqbotCommand,
|
||||
getQqbotCommandList,
|
||||
getQqbotPluginList,
|
||||
getQqbotPluginOperationList,
|
||||
testQqbotCommand,
|
||||
toggleQqbotCommand,
|
||||
updateQqbotCommand,
|
||||
} from '#/api/qqbot';
|
||||
import {
|
||||
getQqbotPluginList,
|
||||
getQqbotPluginOperationList,
|
||||
} from '#/api/qqbot/plugin';
|
||||
import { KtTable, useKtTable } from '#/components/ktTable';
|
||||
|
||||
import {
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { Modal } from 'antdv-next';
|
||||
|
||||
const AModal = Modal as any;
|
||||
|
||||
export default defineComponent({
|
||||
name: 'QqBotPluginManifestModal',
|
||||
props: {
|
||||
loading: {
|
||||
default: false,
|
||||
type: Boolean,
|
||||
},
|
||||
open: {
|
||||
default: false,
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
default: '',
|
||||
type: String,
|
||||
},
|
||||
value: {
|
||||
default: '',
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
emits: ['close', 'submit', 'update:value'],
|
||||
setup(props, { emit }) {
|
||||
return () => (
|
||||
<AModal
|
||||
confirmLoading={props.loading}
|
||||
onCancel={() => emit('close')}
|
||||
onOk={() => emit('submit')}
|
||||
open={props.open}
|
||||
title={props.title}
|
||||
width={760}
|
||||
>
|
||||
<textarea
|
||||
class="w-full resize-y rounded border border-solid border-gray-200 p-3 font-mono text-sm outline-none"
|
||||
onInput={(event) => {
|
||||
emit('update:value', (event.target as HTMLTextAreaElement).value);
|
||||
}}
|
||||
rows={18}
|
||||
value={props.value}
|
||||
/>
|
||||
</AModal>
|
||||
);
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,155 @@
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
import type { QqbotPluginPlatformApi } from '#/api/qqbot/plugin';
|
||||
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { Drawer, Tag } from 'antdv-next';
|
||||
|
||||
import { renderQqbotActions } from '../../modules/actions';
|
||||
import { getQqbotStatusColor, getQqbotStatusLabel } from '../../modules/status';
|
||||
|
||||
const ADrawer = Drawer as any;
|
||||
|
||||
export type PluginPlatformDrawerMode = 'bindings' | 'events' | 'installations';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'QqBotPluginPlatformStateDrawer',
|
||||
props: {
|
||||
accountBindings: {
|
||||
default: () => [],
|
||||
type: Array as PropType<QqbotPluginPlatformApi.AccountBinding[]>,
|
||||
},
|
||||
installations: {
|
||||
default: () => [],
|
||||
type: Array as PropType<QqbotPluginPlatformApi.Installation[]>,
|
||||
},
|
||||
mode: {
|
||||
default: 'installations',
|
||||
type: String as PropType<PluginPlatformDrawerMode>,
|
||||
},
|
||||
open: {
|
||||
default: false,
|
||||
type: Boolean,
|
||||
},
|
||||
runtimeEvents: {
|
||||
default: () => [],
|
||||
type: Array as PropType<QqbotPluginPlatformApi.RuntimeEvent[]>,
|
||||
},
|
||||
title: {
|
||||
default: '',
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
emits: ['close', 'installationAction'],
|
||||
setup(props, { emit }) {
|
||||
const renderStatusTag = (status?: string) => {
|
||||
if (!status) return <Tag color="default">-</Tag>;
|
||||
const color =
|
||||
status === 'uninstalled' ? 'error' : getQqbotStatusColor(status);
|
||||
return <Tag color={color}>{getQqbotStatusLabel(status)}</Tag>;
|
||||
};
|
||||
|
||||
const renderEvents = () =>
|
||||
props.runtimeEvents.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{props.runtimeEvents.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
<div>
|
||||
<Tag color={item.level === 'error' ? 'error' : 'processing'}>
|
||||
{item.level}
|
||||
</Tag>
|
||||
<span>{item.eventType}</span>
|
||||
</div>
|
||||
<pre class="mt-2 whitespace-pre-wrap text-xs">
|
||||
{JSON.stringify(item.safeSummary || {}, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无运行事件</span>
|
||||
);
|
||||
|
||||
const renderBindings = () =>
|
||||
props.accountBindings.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{props.accountBindings.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
{renderStatusTag(item.enabled ? 'enabled' : 'disabled')}
|
||||
<span>
|
||||
插件 {item.pluginId} / 账号 {item.accountId}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无账号绑定</span>
|
||||
);
|
||||
|
||||
const renderInstallations = () =>
|
||||
props.installations.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{props.installations.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
<div class="mb-2 flex items-center gap-2">
|
||||
{renderStatusTag(item.status)}
|
||||
<Tag>{item.runtimeStatus || '-'}</Tag>
|
||||
<span>
|
||||
插件 {item.pluginId} / 版本 {item.versionId}
|
||||
</span>
|
||||
</div>
|
||||
{renderQqbotActions([
|
||||
{
|
||||
disabled: item.status === 'enabled',
|
||||
key: 'enable',
|
||||
label: '启用',
|
||||
onClick: () => emit('installationAction', item, 'enable'),
|
||||
},
|
||||
{
|
||||
disabled: item.status === 'disabled',
|
||||
key: 'disable',
|
||||
label: '禁用',
|
||||
onClick: () => emit('installationAction', item, 'disable'),
|
||||
},
|
||||
{
|
||||
danger: true,
|
||||
key: 'uninstall',
|
||||
label: '卸载',
|
||||
onClick: () => emit('installationAction', item, 'uninstall'),
|
||||
},
|
||||
])}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无安装记录</span>
|
||||
);
|
||||
|
||||
const renderContent = () => {
|
||||
if (props.mode === 'events') return renderEvents();
|
||||
if (props.mode === 'bindings') return renderBindings();
|
||||
return renderInstallations();
|
||||
};
|
||||
|
||||
return () => (
|
||||
<ADrawer
|
||||
onClose={() => emit('close')}
|
||||
open={props.open}
|
||||
size="large"
|
||||
title={props.title}
|
||||
>
|
||||
{renderContent()}
|
||||
</ADrawer>
|
||||
);
|
||||
},
|
||||
});
|
||||
@ -1,5 +1,7 @@
|
||||
import type { TableColumnType } from 'antdv-next';
|
||||
|
||||
import type { PluginPlatformDrawerMode } from './components/PluginPlatformStateDrawer';
|
||||
|
||||
import type { QqbotApi } from '#/api/qqbot';
|
||||
import type { QqbotPluginPlatformApi } from '#/api/qqbot/plugin';
|
||||
import type { KtTableApi, KtTableButton } from '#/components/ktTable';
|
||||
@ -9,17 +11,15 @@ import { computed, defineComponent, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Drawer, message, Modal, Tag } from 'antdv-next';
|
||||
import { message, Tag } from 'antdv-next';
|
||||
|
||||
import {
|
||||
getQqbotPluginHealth,
|
||||
getQqbotPluginList,
|
||||
getQqbotPluginOperationPage,
|
||||
} from '#/api/qqbot';
|
||||
import {
|
||||
disableQqbotPluginInstallation,
|
||||
enableQqbotPluginInstallation,
|
||||
getQqbotPluginAccountBindings,
|
||||
getQqbotPluginHealth,
|
||||
getQqbotPluginList,
|
||||
getQqbotPluginOperationPage,
|
||||
getQqbotPluginPlatformInstallations,
|
||||
getQqbotPluginRuntimeEvents,
|
||||
installLocalQqbotPluginPackage,
|
||||
@ -30,11 +30,9 @@ import {
|
||||
import { KtTable, useKtTable } from '#/components/ktTable';
|
||||
import { useDict } from '#/hooks/useDict';
|
||||
|
||||
import { renderQqbotActions } from '../modules/actions';
|
||||
import { getQqbotStatusColor, getQqbotStatusLabel } from '../modules/status';
|
||||
import PluginManifestModal from './components/PluginManifestModal';
|
||||
import PluginPlatformStateDrawer from './components/PluginPlatformStateDrawer';
|
||||
|
||||
const ADrawer = Drawer as any;
|
||||
const AModal = Modal as any;
|
||||
const AKtTable = KtTable as any;
|
||||
const QQBOT_PLUGIN_TRIGGER_MODE_DICT = 'QQBOT_PLUGIN_TRIGGER_MODE';
|
||||
const qqbotPluginTriggerModeFallback: Array<
|
||||
@ -74,9 +72,7 @@ export default defineComponent({
|
||||
name: 'QqBotPluginList',
|
||||
setup() {
|
||||
const accountBindings = ref<QqbotPluginPlatformApi.AccountBinding[]>([]);
|
||||
const drawerMode = ref<'bindings' | 'events' | 'installations'>(
|
||||
'installations',
|
||||
);
|
||||
const drawerMode = ref<PluginPlatformDrawerMode>('installations');
|
||||
const drawerOpen = ref(false);
|
||||
const installations = ref<QqbotPluginPlatformApi.Installation[]>([]);
|
||||
const manifestMode = ref<'install' | 'upload' | 'validate'>('validate');
|
||||
@ -300,101 +296,6 @@ export default defineComponent({
|
||||
await loadInstallations(false);
|
||||
}
|
||||
|
||||
const renderStatusTag = (status?: string) => {
|
||||
if (!status) return <Tag color="default">-</Tag>;
|
||||
const color =
|
||||
status === 'uninstalled' ? 'error' : getQqbotStatusColor(status);
|
||||
return <Tag color={color}>{getQqbotStatusLabel(status)}</Tag>;
|
||||
};
|
||||
|
||||
const renderDrawerContent = () => {
|
||||
if (drawerMode.value === 'events') {
|
||||
return runtimeEvents.value.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{runtimeEvents.value.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
<div>
|
||||
<Tag color={item.level === 'error' ? 'error' : 'processing'}>
|
||||
{item.level}
|
||||
</Tag>
|
||||
<span>{item.eventType}</span>
|
||||
</div>
|
||||
<pre class="mt-2 whitespace-pre-wrap text-xs">
|
||||
{JSON.stringify(item.safeSummary || {}, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无运行事件</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (drawerMode.value === 'bindings') {
|
||||
return accountBindings.value.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{accountBindings.value.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
{renderStatusTag(item.enabled ? 'enabled' : 'disabled')}
|
||||
<span>
|
||||
插件 {item.pluginId} / 账号 {item.accountId}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无账号绑定</span>
|
||||
);
|
||||
}
|
||||
|
||||
return installations.value.length > 0 ? (
|
||||
<div class="space-y-3">
|
||||
{installations.value.map((item) => (
|
||||
<div
|
||||
class="border-b border-solid border-gray-100 pb-3"
|
||||
key={item.id}
|
||||
>
|
||||
<div class="mb-2 flex items-center gap-2">
|
||||
{renderStatusTag(item.status)}
|
||||
<Tag>{item.runtimeStatus || '-'}</Tag>
|
||||
<span>
|
||||
插件 {item.pluginId} / 版本 {item.versionId}
|
||||
</span>
|
||||
</div>
|
||||
{renderQqbotActions([
|
||||
{
|
||||
disabled: item.status === 'enabled',
|
||||
key: 'enable',
|
||||
label: '启用',
|
||||
onClick: () => updateInstallationStatus(item, 'enable'),
|
||||
},
|
||||
{
|
||||
disabled: item.status === 'disabled',
|
||||
key: 'disable',
|
||||
label: '禁用',
|
||||
onClick: () => updateInstallationStatus(item, 'disable'),
|
||||
},
|
||||
{
|
||||
danger: true,
|
||||
key: 'uninstall',
|
||||
label: '卸载',
|
||||
onClick: () => updateInstallationStatus(item, 'uninstall'),
|
||||
},
|
||||
])}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span>暂无安装记录</span>
|
||||
);
|
||||
};
|
||||
|
||||
return () => (
|
||||
<Page autoContentHeight>
|
||||
<AKtTable
|
||||
@ -426,35 +327,34 @@ export default defineComponent({
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<AModal
|
||||
confirmLoading={platformLoading.value}
|
||||
onCancel={() => {
|
||||
<PluginManifestModal
|
||||
loading={platformLoading.value}
|
||||
onClose={() => {
|
||||
manifestModalOpen.value = false;
|
||||
}}
|
||||
onOk={() => void submitManifest()}
|
||||
onSubmit={() => void submitManifest()}
|
||||
onUpdate:value={(value: string) => {
|
||||
manifestText.value = value;
|
||||
}}
|
||||
open={manifestModalOpen.value}
|
||||
title={manifestModalTitle.value}
|
||||
width={760}
|
||||
>
|
||||
<textarea
|
||||
class="w-full resize-y rounded border border-solid border-gray-200 p-3 font-mono text-sm outline-none"
|
||||
onInput={(event) => {
|
||||
manifestText.value = (event.target as HTMLTextAreaElement).value;
|
||||
}}
|
||||
rows={18}
|
||||
value={manifestText.value}
|
||||
/>
|
||||
</AModal>
|
||||
<ADrawer
|
||||
<PluginPlatformStateDrawer
|
||||
accountBindings={accountBindings.value}
|
||||
installations={installations.value}
|
||||
mode={drawerMode.value}
|
||||
onClose={() => {
|
||||
drawerOpen.value = false;
|
||||
}}
|
||||
onInstallationAction={(
|
||||
row: QqbotPluginPlatformApi.Installation,
|
||||
action: 'disable' | 'enable' | 'uninstall',
|
||||
) => void updateInstallationStatus(row, action)}
|
||||
open={drawerOpen.value}
|
||||
runtimeEvents={runtimeEvents.value}
|
||||
title={drawerTitle.value}
|
||||
width={760}
|
||||
>
|
||||
{renderDrawerContent()}
|
||||
</ADrawer>
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user