feat(core,onebot): implement trans_group_file action (#161)
This commit is contained in:
1 parent
2f374ea8c9
commit
9ca64bed10
11 files changed
+260
-10
No files matched your search
@@ -23,6 +23,7 @@ import { MoveGroupFile } from '@snowluma/protocol/oidb-services/group-file/move-
|
|||||||
import { PublishGroupFile } from '@snowluma/protocol/oidb-services/group-file/publish-group-file';
|
import { PublishGroupFile } from '@snowluma/protocol/oidb-services/group-file/publish-group-file';
|
||||||
import { RenameGroupFile } from '@snowluma/protocol/oidb-services/group-file/rename-group-file';
|
import { RenameGroupFile } from '@snowluma/protocol/oidb-services/group-file/rename-group-file';
|
||||||
import { RenameGroupFolder } from '@snowluma/protocol/oidb-services/group-file/rename-group-folder';
|
import { RenameGroupFolder } from '@snowluma/protocol/oidb-services/group-file/rename-group-folder';
|
||||||
|
import { TransGroupFile, type TransGroupFileResult } from '@snowluma/protocol/oidb-services/group-file/trans-group-file';
|
||||||
import { UploadGroupFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-group-file-request';
|
import { UploadGroupFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-group-file-request';
|
||||||
import { UploadPrivateFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-private-file-request';
|
import { UploadPrivateFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-private-file-request';
|
||||||
import { ensureRetCodeZero } from '@snowluma/protocol/oidb-services/shared';
|
import { ensureRetCodeZero } from '@snowluma/protocol/oidb-services/shared';
|
||||||
@@ -238,6 +239,11 @@ export class GroupFileApi {
|
|||||||
return PublishGroupFile.invoke(this.ctx, { groupId, fileId });
|
return PublishGroupFile.invoke(this.ctx, { groupId, fileId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trans(groupId: number, fileId: string): Promise<TransGroupFileResult> {
|
||||||
|
if (!fileId) throw new Error('trans requires fileId');
|
||||||
|
return TransGroupFile.invoke(this.ctx, { groupId, fileId });
|
||||||
|
}
|
||||||
|
|
||||||
// ─────────────── count ───────────────
|
// ─────────────── count ───────────────
|
||||||
|
|
||||||
getCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> {
|
getCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export interface MockGroupFileApi {
|
|||||||
upload: ReturnType<typeof vi.fn>;
|
upload: ReturnType<typeof vi.fn>;
|
||||||
uploadPrivate: ReturnType<typeof vi.fn>;
|
uploadPrivate: ReturnType<typeof vi.fn>;
|
||||||
publish: ReturnType<typeof vi.fn>;
|
publish: ReturnType<typeof vi.fn>;
|
||||||
|
trans: ReturnType<typeof vi.fn>;
|
||||||
getCount: ReturnType<typeof vi.fn>;
|
getCount: ReturnType<typeof vi.fn>;
|
||||||
list: ReturnType<typeof vi.fn>;
|
list: ReturnType<typeof vi.fn>;
|
||||||
getUrl: ReturnType<typeof vi.fn>;
|
getUrl: ReturnType<typeof vi.fn>;
|
||||||
@@ -85,6 +86,7 @@ export function mockGroupFileApi(): MockGroupFileApi {
|
|||||||
upload: vi.fn(async () => ({ fileId: 'stub-fid' })),
|
upload: vi.fn(async () => ({ fileId: 'stub-fid' })),
|
||||||
uploadPrivate: vi.fn(async () => ({ fileId: 'stub-pfid', fileHash: 'stub-hash' })),
|
uploadPrivate: vi.fn(async () => ({ fileId: 'stub-pfid', fileHash: 'stub-hash' })),
|
||||||
publish: vi.fn(async () => undefined),
|
publish: vi.fn(async () => undefined),
|
||||||
|
trans: vi.fn(async () => ({ saveBusId: 102, saveFilePath: '/stub-path' })),
|
||||||
getCount: vi.fn(async () => ({ fileCount: 0, maxCount: 10000 })),
|
getCount: vi.fn(async () => ({ fileCount: 0, maxCount: 10000 })),
|
||||||
list: vi.fn(async () => ({ files: [], folders: [] })),
|
list: vi.fn(async () => ({ files: [], folders: [] })),
|
||||||
getUrl: vi.fn(async () => 'stub://url'),
|
getUrl: vi.fn(async () => 'stub://url'),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
OidbGroupFileViewResp,
|
OidbGroupFileViewResp,
|
||||||
OidbGroupFileFolderResp,
|
OidbGroupFileFolderResp,
|
||||||
OidbGroupSendFileReq,
|
OidbGroupSendFileReq,
|
||||||
|
OidbGroupSendFileResp,
|
||||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||||
import type {
|
import type {
|
||||||
OidbPrivateFileUploadResp,
|
OidbPrivateFileUploadResp,
|
||||||
@@ -246,6 +247,26 @@ describe('apis/group-file', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('trans hits OIDB 0x6d9_0 and returns the saved path metadata', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||||
|
protobuf_encode<OidbBase<OidbGroupSendFileResp>>({
|
||||||
|
body: { transFile: { saveBusId: 102, saveFilePath: '/saved/path' } },
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
const out = await new GroupFileApi(bridge as any).trans(12345, 'fid-trans');
|
||||||
|
expect(out).toEqual({ saveBusId: 102, saveFilePath: '/saved/path' });
|
||||||
|
const [wire, bytes] = bridge.sendRawPacket.mock.calls[0]!;
|
||||||
|
expect(wire).toBe('OidbSvcTrpcTcp.0x6d9_0');
|
||||||
|
const env = protobuf_decode<OidbBase<OidbGroupSendFileReq>>(bytes);
|
||||||
|
expect(env.body?.transFile).toMatchObject({
|
||||||
|
groupUin: 12345n,
|
||||||
|
appId: 7,
|
||||||
|
busId: 102,
|
||||||
|
fileId: 'fid-trans',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('uploadPrivate resolves both target + self UID before OIDB call', async () => {
|
it('uploadPrivate resolves both target + self UID before OIDB call', async () => {
|
||||||
const bridge = mockBridge({
|
const bridge = mockBridge({
|
||||||
identity: {
|
identity: {
|
||||||
|
|||||||
@@ -9094,13 +9094,46 @@
|
|||||||
{
|
{
|
||||||
"name": "trans_group_file",
|
"name": "trans_group_file",
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"summary": "转存群文件(未实现)",
|
"summary": "转存群文件",
|
||||||
|
"returns": "{ ok: true }",
|
||||||
"readOnly": false,
|
"readOnly": false,
|
||||||
"params": [],
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "group_id",
|
||||||
|
"type": "uint",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "file_id",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"invariants": [],
|
"invariants": [],
|
||||||
"inputSchema": {
|
"inputSchema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {},
|
"properties": {
|
||||||
|
"group_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"file_id": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"group_id",
|
||||||
|
"file_id"
|
||||||
|
],
|
||||||
"additionalProperties": true
|
"additionalProperties": true
|
||||||
},
|
},
|
||||||
"category": "扩展"
|
"category": "扩展"
|
||||||
|
|||||||
@@ -9097,13 +9097,46 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
{
|
{
|
||||||
"name": "trans_group_file",
|
"name": "trans_group_file",
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"summary": "转存群文件(未实现)",
|
"summary": "转存群文件",
|
||||||
|
"returns": "{ ok: true }",
|
||||||
"readOnly": false,
|
"readOnly": false,
|
||||||
"params": [],
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "group_id",
|
||||||
|
"type": "uint",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "file_id",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"invariants": [],
|
"invariants": [],
|
||||||
"inputSchema": {
|
"inputSchema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {},
|
"properties": {
|
||||||
|
"group_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"file_id": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"group_id",
|
||||||
|
"file_id"
|
||||||
|
],
|
||||||
"additionalProperties": true
|
"additionalProperties": true
|
||||||
},
|
},
|
||||||
"category": "扩展"
|
"category": "扩展"
|
||||||
|
|||||||
@@ -1636,10 +1636,15 @@ export const actions = [
|
|||||||
|
|
||||||
defineAction({
|
defineAction({
|
||||||
name: 'trans_group_file',
|
name: 'trans_group_file',
|
||||||
summary: '转存群文件(未实现)',
|
summary: '转存群文件',
|
||||||
params: {},
|
returns: '{ ok: true }',
|
||||||
run: async () => {
|
params: {
|
||||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
group_id: f.uint(),
|
||||||
|
file_id: f.string({ allowEmpty: false }),
|
||||||
|
},
|
||||||
|
run: async (p, ctx) => {
|
||||||
|
await ctx.bridge.apis.groupFile.trans(p.group_id, p.file_id);
|
||||||
|
return okResponse({ ok: true });
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@@ -641,6 +641,31 @@ describe('extended-actions / get_group_shut_list', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ─── Wave 1: trans_group_file (0x6D9_0) ───
|
||||||
|
|
||||||
|
describe('extended-actions / trans_group_file', () => {
|
||||||
|
it('forwards group_id + file_id to apis.groupFile.trans and returns ok:true', async () => {
|
||||||
|
const trans = vi.fn(async () => ({ saveBusId: 102, saveFilePath: '/saved/path' }));
|
||||||
|
const bridge = fakeBridge({ apis: { groupFile: { trans } } });
|
||||||
|
const res = await makeHandler(fakeCtx(bridge)).handle('trans_group_file', {
|
||||||
|
group_id: 12345,
|
||||||
|
file_id: 'fid-trans',
|
||||||
|
});
|
||||||
|
expect(trans).toHaveBeenCalledWith(12345, 'fid-trans');
|
||||||
|
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: { ok: true } });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects missing required params', async () => {
|
||||||
|
const trans = vi.fn();
|
||||||
|
const bridge = fakeBridge({ apis: { groupFile: { trans } } });
|
||||||
|
const r1 = await makeHandler(fakeCtx(bridge)).handle('trans_group_file', { file_id: 'fid' });
|
||||||
|
const r2 = await makeHandler(fakeCtx(bridge)).handle('trans_group_file', { group_id: 12345 });
|
||||||
|
expect(r1).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||||
|
expect(r2).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||||
|
expect(trans).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ─── Wave 1: get_file (compose image→record cache) ───
|
// ─── Wave 1: get_file (compose image→record cache) ───
|
||||||
|
|
||||||
describe('extended-actions / get_file', () => {
|
describe('extended-actions / get_file', () => {
|
||||||
|
|||||||
@@ -132,6 +132,19 @@ export interface OidbGroupFileResp {
|
|||||||
rename?: pb<5, OidbGroupFileRetResp>;
|
rename?: pb<5, OidbGroupFileRetResp>;
|
||||||
move?: pb<6, OidbGroupFileRetResp>;
|
move?: pb<6, OidbGroupFileRetResp>;
|
||||||
}
|
}
|
||||||
|
export interface OidbGroupTransFileReq {
|
||||||
|
groupUin?: pb<1, uint_64>;
|
||||||
|
appId?: pb<2, uint_32>;
|
||||||
|
busId?: pb<3, uint_32>;
|
||||||
|
fileId?: pb<4, string>;
|
||||||
|
}
|
||||||
|
export interface OidbGroupTransFileResp {
|
||||||
|
retCode?: pb<1, int_32>;
|
||||||
|
retMsg?: pb<2, string>;
|
||||||
|
clientWording?: pb<3, string>;
|
||||||
|
saveBusId?: pb<4, uint_32>;
|
||||||
|
saveFilePath?: pb<5, string>;
|
||||||
|
}
|
||||||
export interface OidbGroupSendFileInfo {
|
export interface OidbGroupSendFileInfo {
|
||||||
busiType?: pb<1, uint_32>;
|
busiType?: pb<1, uint_32>;
|
||||||
fileId?: pb<2, string>;
|
fileId?: pb<2, string>;
|
||||||
@@ -145,8 +158,12 @@ export interface OidbGroupSendFileBody {
|
|||||||
info?: pb<3, OidbGroupSendFileInfo>;
|
info?: pb<3, OidbGroupSendFileInfo>;
|
||||||
}
|
}
|
||||||
export interface OidbGroupSendFileReq {
|
export interface OidbGroupSendFileReq {
|
||||||
|
transFile?: pb<1, OidbGroupTransFileReq>;
|
||||||
body?: pb<5, OidbGroupSendFileBody>;
|
body?: pb<5, OidbGroupSendFileBody>;
|
||||||
}
|
}
|
||||||
|
export interface OidbGroupSendFileResp {
|
||||||
|
transFile?: pb<1, OidbGroupTransFileResp>;
|
||||||
|
}
|
||||||
export interface OidbGroupFileCreateFolderReq {
|
export interface OidbGroupFileCreateFolderReq {
|
||||||
groupUin?: pb<1, uint_32>;
|
groupUin?: pb<1, uint_32>;
|
||||||
rootDirectory?: pb<3, string>;
|
rootDirectory?: pb<3, string>;
|
||||||
|
|||||||
@@ -332,6 +332,10 @@
|
|||||||
"types": "./src/oidb-services/group-file/publish-group-file.ts",
|
"types": "./src/oidb-services/group-file/publish-group-file.ts",
|
||||||
"default": "./src/oidb-services/group-file/publish-group-file.ts"
|
"default": "./src/oidb-services/group-file/publish-group-file.ts"
|
||||||
},
|
},
|
||||||
|
"./oidb-services/group-file/trans-group-file": {
|
||||||
|
"types": "./src/oidb-services/group-file/trans-group-file.ts",
|
||||||
|
"default": "./src/oidb-services/group-file/trans-group-file.ts"
|
||||||
|
},
|
||||||
"./oidb-services/group-file/get-group-file-count": {
|
"./oidb-services/group-file/get-group-file-count": {
|
||||||
"types": "./src/oidb-services/group-file/get-group-file-count.ts",
|
"types": "./src/oidb-services/group-file/get-group-file-count.ts",
|
||||||
"default": "./src/oidb-services/group-file/get-group-file-count.ts"
|
"default": "./src/oidb-services/group-file/get-group-file-count.ts"
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// 0x6D9_0 — transfer a temporary group file into permanent group storage.
|
||||||
|
// Mirrors LagrangeV2's TransFileReqBody shape under the 0x6D9 family.
|
||||||
|
|
||||||
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||||
|
import type {
|
||||||
|
OidbGroupSendFileReq,
|
||||||
|
OidbGroupSendFileResp,
|
||||||
|
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||||
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
import { ensureRetCodeZero, toInt } from '../shared';
|
||||||
|
|
||||||
|
export interface TransGroupFileResult {
|
||||||
|
saveBusId: number;
|
||||||
|
saveFilePath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace TransGroupFile {
|
||||||
|
export const command = 0x6D9;
|
||||||
|
export const subCommand = 0;
|
||||||
|
|
||||||
|
export interface Params { groupId: number; fileId: string; }
|
||||||
|
export type Deps = OidbSender;
|
||||||
|
|
||||||
|
export const serialize = (_ctx: Deps, p: Params): OidbGroupSendFileReq => ({
|
||||||
|
transFile: {
|
||||||
|
groupUin: BigInt(p.groupId),
|
||||||
|
appId: 7,
|
||||||
|
busId: 102,
|
||||||
|
fileId: p.fileId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const deserialize = (_ctx: Deps, body: OidbGroupSendFileResp): TransGroupFileResult => {
|
||||||
|
const result = body.transFile;
|
||||||
|
if (!result) throw new Error('group file transfer response missing');
|
||||||
|
ensureRetCodeZero('group file transfer', result.retCode, result.retMsg, result.clientWording);
|
||||||
|
return {
|
||||||
|
saveBusId: toInt(result.saveBusId),
|
||||||
|
saveFilePath: typeof result.saveFilePath === 'string' ? result.saveFilePath : '',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const encode = (env: OidbBase<OidbGroupSendFileReq>): Uint8Array =>
|
||||||
|
protobuf_encode<OidbBase<OidbGroupSendFileReq>>(env);
|
||||||
|
|
||||||
|
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupSendFileResp> =>
|
||||||
|
protobuf_decode<OidbBase<OidbGroupSendFileResp>>(bytes);
|
||||||
|
|
||||||
|
export const invoke = (deps: Deps, params: Params): Promise<TransGroupFileResult> =>
|
||||||
|
invokeOidb(deps, TransGroupFile, params);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
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 {
|
||||||
|
OidbGroupSendFileReq, OidbGroupSendFileResp,
|
||||||
|
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||||
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||||
|
|
||||||
|
import { TransGroupFile } from '../../../src/oidb-services/group-file/trans-group-file';
|
||||||
|
|
||||||
|
function makeDeps(body?: OidbGroupSendFileResp) {
|
||||||
|
const responseData = body !== undefined
|
||||||
|
? Buffer.from(protobuf_encode<OidbBase<OidbGroupSendFileResp>>({ body }))
|
||||||
|
: Buffer.alloc(0);
|
||||||
|
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||||
|
return { sendRawPacket: vi.fn(async () => r) };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('TransGroupFile namespace', () => {
|
||||||
|
it('declares 0x6D9_0', () => {
|
||||||
|
expect(TransGroupFile.command).toBe(0x6D9);
|
||||||
|
expect(TransGroupFile.subCommand).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('packages group + file id under the transFile slot', async () => {
|
||||||
|
const deps = makeDeps({ transFile: { saveBusId: 102, saveFilePath: '/abc' } });
|
||||||
|
const out = await TransGroupFile.invoke(deps, { groupId: 12345, fileId: 'fid' });
|
||||||
|
expect(out).toEqual({ saveBusId: 102, saveFilePath: '/abc' });
|
||||||
|
expect(deps.sendRawPacket).toHaveBeenCalledOnce();
|
||||||
|
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||||
|
expect(wire).toBe('OidbSvcTrpcTcp.0x6d9_0');
|
||||||
|
const env = protobuf_decode<OidbBase<OidbGroupSendFileReq>>(bytes);
|
||||||
|
expect(env.body?.transFile).toEqual({
|
||||||
|
groupUin: 12345n,
|
||||||
|
appId: 7,
|
||||||
|
busId: 102,
|
||||||
|
fileId: 'fid',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws on missing transFile sub-message', async () => {
|
||||||
|
const deps = makeDeps({});
|
||||||
|
await expect(TransGroupFile.invoke(deps, { groupId: 1, fileId: 'f' }))
|
||||||
|
.rejects.toThrow(/transfer response missing/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws on non-zero retCode', async () => {
|
||||||
|
const deps = makeDeps({ transFile: { retCode: 7, retMsg: 'denied' } });
|
||||||
|
await expect(TransGroupFile.invoke(deps, { groupId: 1, fileId: 'f' }))
|
||||||
|
.rejects.toThrow(/code=7/);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user