feat(onebot): implement rename_group_file (OIDB 0x6D6_4)
Add the file-rename slot to the group-file OIDB envelope (req/resp field 5), a RenameGroupFile service mirroring MoveGroupFile, a groupFile.rename() api method, and the rename_group_file action (params group_id/file_id/ current_parent_directory/new_name, NapCat-aligned), replacing the stub. Wire fields (busId=102, parentFolder=current dir, newFileName) verified against NapCat's Oidb.0x6D6 transformer; subCommand 4 cross-checked against the move op (sub 5 on both sides). Serialize + envelope round-trip test locks the pb tags.
This commit is contained in:
8 files changed
+178
-9
No files matched your search
@@ -263,6 +263,10 @@
|
||||
"types": "./src/oidb-services/group-file/move-group-file.ts",
|
||||
"default": "./src/oidb-services/group-file/move-group-file.ts"
|
||||
},
|
||||
"./oidb-services/group-file/rename-group-file": {
|
||||
"types": "./src/oidb-services/group-file/rename-group-file.ts",
|
||||
"default": "./src/oidb-services/group-file/rename-group-file.ts"
|
||||
},
|
||||
"./oidb-services/group-file/create-group-folder": {
|
||||
"types": "./src/oidb-services/group-file/create-group-folder.ts",
|
||||
"default": "./src/oidb-services/group-file/create-group-folder.ts"
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 0x6D6_4 — rename a group file (not a folder; that is 0x6D7_2). The
|
||||
// rename slot lives on the shared `OidbGroupFileReq` envelope at field 5.
|
||||
// Wire fields verified against NapCat's Oidb.0x6D6 transformer
|
||||
// (busId=102, parentFolder = the file's CURRENT parent directory).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace RenameGroupFile {
|
||||
export const command = 0x6D6;
|
||||
export const subCommand = 4;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params {
|
||||
groupId: number; fileId: string;
|
||||
parentDirectory: string; newFileName: string;
|
||||
}
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
rename: {
|
||||
groupUin: p.groupId,
|
||||
busId: 102,
|
||||
fileId: p.fileId,
|
||||
parentFolder: p.parentDirectory,
|
||||
newFileName: p.newFileName,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileResp): void => {
|
||||
const result = body.rename;
|
||||
if (!result) throw new Error('group file rename response missing');
|
||||
ensureRetCodeZero('group file rename', result.retCode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, RenameGroupFile, params);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupFileReq, OidbGroupFileResp } from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { RenameGroupFile } from '../../../src/oidb-services/group-file/rename-group-file';
|
||||
|
||||
// A success response the real server would send: command/sub echoed, rename
|
||||
// ret slot with retCode 0. Lets `invoke`'s deserialize pass so we can assert
|
||||
// the request wire (cmd name + body) without it throwing on an empty body.
|
||||
function okRenameResponse(): Buffer {
|
||||
const env: OidbBase<OidbGroupFileResp> = {
|
||||
command: 0x6D6, subCommand: 4, body: { rename: { retCode: 0 } },
|
||||
};
|
||||
return Buffer.from(protobuf_encode<OidbBase<OidbGroupFileResp>>(env));
|
||||
}
|
||||
|
||||
function makeSender() {
|
||||
const defaultResp: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: okRenameResponse(),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => defaultResp) };
|
||||
}
|
||||
|
||||
describe('RenameGroupFile namespace', () => {
|
||||
it('declares command 0x6D6 sub 4 (rename slot), uin form', () => {
|
||||
expect(RenameGroupFile.command).toBe(0x6D6);
|
||||
expect(RenameGroupFile.subCommand).toBe(4);
|
||||
expect(RenameGroupFile.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes into the rename slot with busId 102 and the current parent folder', () => {
|
||||
const out = RenameGroupFile.serialize({} as any, {
|
||||
groupId: 12345, fileId: '/abc', parentDirectory: '/sub', newFileName: 'new.txt',
|
||||
});
|
||||
expect(out).toEqual({
|
||||
rename: {
|
||||
groupUin: 12345, busId: 102, fileId: '/abc', parentFolder: '/sub', newFileName: 'new.txt',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips the rename body through the OIDB envelope (locks the pb field tags)', async () => {
|
||||
const sender = makeSender();
|
||||
await RenameGroupFile.invoke(sender, {
|
||||
groupId: 12345, fileId: '/abc', parentDirectory: '/', newFileName: 'new.txt',
|
||||
});
|
||||
expect(sender.sendRawPacket).toHaveBeenCalledOnce();
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x6d6_4');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileReq>>(bytes);
|
||||
expect(env.command).toBe(0x6D6);
|
||||
expect(env.subCommand).toBe(4);
|
||||
expect(env.body.rename).toMatchObject({
|
||||
groupUin: 12345, busId: 102, fileId: '/abc', parentFolder: '/', newFileName: 'new.txt',
|
||||
});
|
||||
});
|
||||
|
||||
it('deserialize throws when the rename slot is missing from the response', () => {
|
||||
expect(() => RenameGroupFile.deserialize({} as any, {})).toThrow(/rename response missing/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user