NapCatQQ/packages/napcat-webui-frontend/src/controllers/protocol_manager.ts
手瓜一十雪 506358e01a Refactor protocol management with napcat-protocol package
Introduced the new napcat-protocol package to unify protocol adapter management for OneBot and Satori. Updated napcat-framework and napcat-shell to use ProtocolManager instead of direct adapter instantiation. Added protocol info definitions to napcat-common, and integrated protocol configuration and management APIs into the web UI backend and frontend. This refactor improves maintainability, extensibility, and encapsulation of protocol logic, while maintaining backward compatibility.
2026-01-14 15:41:47 +08:00

46 lines
1.2 KiB
TypeScript

import { serverRequest } from '@/utils/request';
const ProtocolManager = {
async getSupportedProtocols (): Promise<ProtocolInfo[]> {
const res = await serverRequest.get<ServerResponse<ProtocolInfo[]>>(
'/ProtocolConfig/protocols'
);
if (res.data.code !== 0) {
throw new Error(res.data.message);
}
return res.data.data;
},
async getProtocolStatus (): Promise<Record<string, boolean>> {
const res = await serverRequest.get<ServerResponse<Record<string, boolean>>>(
'/ProtocolConfig/status'
);
if (res.data.code !== 0) {
throw new Error(res.data.message);
}
return res.data.data;
},
async getSatoriConfig (): Promise<SatoriConfig> {
const res = await serverRequest.get<ServerResponse<SatoriConfig>>(
'/ProtocolConfig/satori'
);
if (res.data.code !== 0) {
throw new Error(res.data.message);
}
return res.data.data;
},
async setSatoriConfig (config: SatoriConfig): Promise<void> {
const res = await serverRequest.post<ServerResponse<null>>(
'/ProtocolConfig/satori',
{ config: JSON.stringify(config) }
);
if (res.data.code !== 0) {
throw new Error(res.data.message);
}
},
};
export default ProtocolManager;