mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 22:51:13 +00:00
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.
46 lines
1.2 KiB
TypeScript
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;
|