refactor: 整体重构 (#1381)

* feat: pnpm new

* Refactor build and release workflows, update dependencies

Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
This commit is contained in:
手瓜一十雪 authored and GitHub committed 2025-11-13 15:39:42 +08:00
1 parent c3d1892545
commit ed19c52f25
778 files changed
+2356 -26391

No files matched your search

@@ -0,0 +1,23 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName, BaseCheckResult } from '@/napcat-onebot/action/router';
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
protected override async check (payload: PT): Promise<BaseCheckResult> {
if (!this.core.apis.PacketApi.packetStatus) {
return {
valid: false,
message: 'packetBackend不可用,请参照文档 https://napneko.github.io/config/advanced 和启动日志检查packetBackend状态或进行配置!' +
'错误堆栈信息:' + this.core.apis.PacketApi.clientLogStack,
};
}
return await super.check(payload);
}
}
export class GetPacketStatus extends GetPacketStatusDepends<void, void> {
override actionName = ActionName.GetPacketStatus;
async _handle () {
}
}
@@ -0,0 +1,18 @@
import { ActionName } from '@/napcat-onebot/action/router';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
export class GetRkeyEx extends GetPacketStatusDepends<void, unknown> {
override actionName = ActionName.GetRkeyEx;
async _handle () {
const rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
return rkeys.map(rkey => {
return {
type: rkey.type === 10 ? 'private' : 'group',
rkey: rkey.rkey,
created_at: rkey.time,
ttl: rkey.ttl,
};
});
}
}
@@ -0,0 +1,39 @@
import { ActionName } from '@/napcat-onebot/action/router';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
export class GetRkeyServer extends GetPacketStatusDepends<void, { private_rkey?: string; group_rkey?: string; expired_time?: number; name: string }> {
override actionName = ActionName.GetRkeyServer;
private rkeyCache: {
private_rkey?: string;
group_rkey?: string;
expired_time?: number;
name: string;
} | null = null;
private expiryTime: number | null = null;
async _handle () {
// 检查缓存是否有效
if (this.expiryTime && this.expiryTime > Math.floor(Date.now() / 1000) && this.rkeyCache) {
return this.rkeyCache;
}
// 获取新的 Rkey
const rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
const privateRkeyItem = rkeys.filter(rkey => rkey.type === 10)[0];
const groupRkeyItem = rkeys.filter(rkey => rkey.type === 20)[0];
this.expiryTime = Math.floor(Date.now() / 1000) + Math.min(+groupRkeyItem!.ttl.toString(), +privateRkeyItem!.ttl.toString());
// 更新缓存
this.rkeyCache = {
private_rkey: privateRkeyItem ? privateRkeyItem.rkey : undefined,
group_rkey: groupRkeyItem ? groupRkeyItem.rkey : undefined,
expired_time: this.expiryTime,
name: 'NapCat 4',
};
return this.rkeyCache;
}
}
@@ -0,0 +1,37 @@
import { ActionName } from '@/napcat-onebot/action/router';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Optional(Type.String()),
user_id: Type.Optional(Type.String()),
target_id: Type.Optional(Type.String()),
});
type Payload = Static<typeof SchemaData>;
export class SendPokeBase extends GetPacketStatusDepends<Payload, void> {
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// 这里的 !! 可以传入空字符串 忽略这些数据有利用接口统一接口
const target_id = payload.target_id ? payload.target_id : payload.user_id;
const peer_id = payload.group_id ? payload.group_id : payload.user_id;
const is_group = !!payload.group_id;
if (!target_id || !peer_id) {
throw new Error('请检查参数,缺少 user_id 或 group_id');
}
await this.core.apis.PacketApi.pkt.operation.SendPoke(is_group, +peer_id, +target_id);
}
}
export class SendPoke extends SendPokeBase {
override actionName = ActionName.SendPoke;
}
export class GroupPoke extends SendPokeBase {
override actionName = ActionName.GroupPoke;
}
export class FriendPoke extends SendPokeBase {
override actionName = ActionName.FriendPoke;
}
@@ -0,0 +1,30 @@
import { MessageUnique } from 'napcat-common/src/message-unique';
import { ChatType, Peer } from 'napcat-core';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
import { ActionName } from '../router';
const SchemaData = Type.Object({
group_id: Type.String(),
message_id: Type.String(),
message_seq: Type.Optional(Type.String()),
});
type Payload = Static<typeof SchemaData>;
export class SetGroupTodo extends GetPacketStatusDepends<Payload, void> {
override payloadSchema = SchemaData;
override actionName = ActionName.SetGroupTodo;
async _handle (payload: Payload) {
if (payload.message_seq) {
return await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, payload.message_seq);
}
const peer: Peer = {
chatType: ChatType.KCHATTYPEGROUP,
peerUid: payload.group_id,
};
const { MsgId, Peer } = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) ?? { Peer: peer, MsgId: payload.message_id };
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(Peer, [MsgId])).msgList[0];
if (!msg) throw new Error('消息不存在');
await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, msg.msgSeq);
}
}