Implement some actions: comment, send and cancel like, delete media for group album!
This commit is contained in:
1 parent
e2ee528939
commit
64530cc287
7 files changed
+495
-3
No files matched your search
@@ -2,13 +2,29 @@
|
|||||||
|
|
||||||
import type { Bridge } from '../bridge';
|
import type { Bridge } from '../bridge';
|
||||||
import { protoEncode, protoDecode } from '@/protobuf/decode';
|
import { protoEncode, protoDecode } from '@/protobuf/decode';
|
||||||
import { GetMediaListRequestSchema, GetMediaListResponseSchema } from '../proto/oidb-action';
|
import { GetMediaListRequestSchema,
|
||||||
|
GetMediaListResponseSchema,
|
||||||
|
DoQunCommentRequestSchema,
|
||||||
|
DoQunCommentResponseSchema,
|
||||||
|
DoQunLikeRequestSchema,
|
||||||
|
DoQunLikeResponseSchema,
|
||||||
|
DeleteMediasRequestSchema,
|
||||||
|
DeleteMediasResponseSchema
|
||||||
|
} from '../proto/oidb-action';
|
||||||
|
|
||||||
export interface GroupAlbumMediaResult {
|
export interface GroupAlbumMediaResult {
|
||||||
mediaList: any[];
|
mediaList: any[];
|
||||||
nextAttachInfo: string;
|
nextAttachInfo: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GroupAlbumCommentResult {
|
||||||
|
id: string;
|
||||||
|
user: { uin: string };
|
||||||
|
content: Array<{ type: number; content: string }>;
|
||||||
|
time: string;
|
||||||
|
clientKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
function convertBigIntToString(obj: any): any {
|
function convertBigIntToString(obj: any): any {
|
||||||
if (obj === null || obj === undefined) return obj;
|
if (obj === null || obj === undefined) return obj;
|
||||||
if (typeof obj === 'bigint') return obj.toString();
|
if (typeof obj === 'bigint') return obj.toString();
|
||||||
@@ -71,3 +87,196 @@ export async function getGroupAlbumMediaList(
|
|||||||
nextAttachInfo,
|
nextAttachInfo,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function commentGroupAlbumMedia(
|
||||||
|
bridge: Bridge,
|
||||||
|
groupId: number,
|
||||||
|
albumId: string,
|
||||||
|
lloc: string,
|
||||||
|
content: string
|
||||||
|
): Promise<GroupAlbumCommentResult> {
|
||||||
|
const traceId = `_${Date.now()}_${Math.floor(Math.random() * 100000)}`;
|
||||||
|
const clientKey = Date.now().toString();
|
||||||
|
const uin = bridge.identity.uin;
|
||||||
|
|
||||||
|
const body = protoEncode({
|
||||||
|
field1: 8527,
|
||||||
|
field2: new Uint8Array(0),
|
||||||
|
field3: new Uint8Array(0),
|
||||||
|
body: {
|
||||||
|
groupId: groupId.toString(),
|
||||||
|
field3: 2,
|
||||||
|
reqBody: {
|
||||||
|
field1: { field3: 0, field4: "" },
|
||||||
|
field2: {
|
||||||
|
field1: { uin }
|
||||||
|
},
|
||||||
|
field5: {
|
||||||
|
field1: {
|
||||||
|
field2: {
|
||||||
|
field1: 0, field2: "",
|
||||||
|
lloc,
|
||||||
|
field4: "", field6: "", field7: 0, field8: 0, field9: 0, field14: 0, field15: 0, field17: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
albumId,
|
||||||
|
field5: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
field5: {
|
||||||
|
field2: { uin },
|
||||||
|
field3: {
|
||||||
|
field1: 0,
|
||||||
|
field2: content,
|
||||||
|
field3: "", field4: "", field5: 0, field6: ""
|
||||||
|
},
|
||||||
|
clientKey,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
traceId,
|
||||||
|
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||||
|
}, DoQunCommentRequestSchema);
|
||||||
|
|
||||||
|
const result = await bridge.sendRawPacket(
|
||||||
|
'QunAlbum.trpc.qzone.webapp_qun_operation.FeedsWriter.DoQunComment',
|
||||||
|
body,
|
||||||
|
15000
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||||
|
throw new Error(result.errorMessage || 'failed to comment on album media');
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = protoDecode(result.responseData, DoQunCommentResponseSchema);
|
||||||
|
|
||||||
|
const resCode = (resp as any)?.field1;
|
||||||
|
if (!resp || (resCode !== 0 && resCode !== 8527 && !(resp as any).comment)) {
|
||||||
|
throw new Error(`comment album media error: retCode ${resCode || 'unknown'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const commentData = (resp as any).comment?.data || {};
|
||||||
|
|
||||||
|
return convertBigIntToString({
|
||||||
|
id: commentData.id || '',
|
||||||
|
user: { uin: commentData.user?.uin || '' },
|
||||||
|
content: commentData.content || [],
|
||||||
|
time: commentData.time || '0',
|
||||||
|
clientKey: commentData.clientKey || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function likeGroupAlbumMedia(
|
||||||
|
bridge: Bridge,
|
||||||
|
groupId: number,
|
||||||
|
albumId: string,
|
||||||
|
batchId: string,
|
||||||
|
lloc: string | undefined,
|
||||||
|
isLike: boolean
|
||||||
|
): Promise<any> {
|
||||||
|
const uin = bridge.identity.uin;
|
||||||
|
const clientKey = `${uin}_${Date.now()}_${Math.floor(Math.random() * 100000)}`;
|
||||||
|
|
||||||
|
const type = isLike ? 2 : 1;
|
||||||
|
const status = isLike ? 0 : 1;
|
||||||
|
|
||||||
|
let id = '';
|
||||||
|
if (lloc) {
|
||||||
|
id = `421_1_0_${groupId}|${albumId}|${batchId}^||^421_1_0_${groupId}|${albumId}|${lloc}^||^0`;
|
||||||
|
} else {
|
||||||
|
id = `421_1_0_${groupId}|${albumId}|${batchId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = protoEncode({
|
||||||
|
field1: 5495,
|
||||||
|
field2: "h5_test",
|
||||||
|
field3: "h5_test",
|
||||||
|
body: {
|
||||||
|
type,
|
||||||
|
like: { id, status },
|
||||||
|
publish: {
|
||||||
|
cellCommon: {
|
||||||
|
time: BigInt(Date.now()),
|
||||||
|
feedId: `422_0_${batchId}`
|
||||||
|
},
|
||||||
|
cellUserInfo: {
|
||||||
|
user: { uin }
|
||||||
|
},
|
||||||
|
cellMedia: {
|
||||||
|
albumId: albumId,
|
||||||
|
batchId: BigInt(batchId)
|
||||||
|
},
|
||||||
|
cellQunInfo: {
|
||||||
|
qunId: groupId.toString()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clientKey
|
||||||
|
},
|
||||||
|
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||||
|
}, DoQunLikeRequestSchema);
|
||||||
|
|
||||||
|
const result = await bridge.sendRawPacket(
|
||||||
|
'QunAlbum.trpc.qzone.webapp_qun_operation.FeedsWriter.DoQunLike',
|
||||||
|
body,
|
||||||
|
15000
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||||
|
throw new Error(result.errorMessage || 'failed to like album media');
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = protoDecode(result.responseData, DoQunLikeResponseSchema);
|
||||||
|
const resCode = (resp as any)?.field1;
|
||||||
|
|
||||||
|
if (!resp || resCode !== 5495) {
|
||||||
|
throw new Error(`like album media error: retCode ${resCode || 'unknown'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (resp as any).body?.like || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteGroupAlbumMedia(
|
||||||
|
bridge: Bridge,
|
||||||
|
groupId: number,
|
||||||
|
albumId: string,
|
||||||
|
lloc: string
|
||||||
|
): Promise<any> {
|
||||||
|
const uin = bridge.identity.uin;
|
||||||
|
const clientKey = `${uin}_${Date.now()}_${Math.floor(Math.random() * 100000)}`;
|
||||||
|
|
||||||
|
const body = protoEncode({
|
||||||
|
field1: 8694,
|
||||||
|
field2: "h5_test",
|
||||||
|
field3: "h5_test",
|
||||||
|
body: {
|
||||||
|
groupId: groupId.toString(),
|
||||||
|
albumId: albumId,
|
||||||
|
lloc: lloc,
|
||||||
|
},
|
||||||
|
traceId: clientKey,
|
||||||
|
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||||
|
}, DeleteMediasRequestSchema);
|
||||||
|
|
||||||
|
const result = await bridge.sendRawPacket(
|
||||||
|
'QunAlbum.trpc.qzone.webapp_qun_media.QunMedia.DeleteMedias',
|
||||||
|
body,
|
||||||
|
15000
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||||
|
throw new Error(result.errorMessage || 'failed to delete album media');
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = protoDecode(result.responseData, DeleteMediasResponseSchema);
|
||||||
|
const resCode = (resp as any)?.field1;
|
||||||
|
const errCode = (resp as any)?.field2;
|
||||||
|
const errMsg = (resp as any)?.field3;
|
||||||
|
|
||||||
|
if (!resp || resCode !== 8694 || errCode) {
|
||||||
|
throw new Error(`delete album media error [${errCode || 'unknown'}]: ${errMsg || 'unknown'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
@@ -95,6 +95,9 @@ export interface BridgeInterface {
|
|||||||
getGroupAlbumList(groupId: number): Promise<any>;
|
getGroupAlbumList(groupId: number): Promise<any>;
|
||||||
uploadImageToGroupAlbum(groupId: number, albumId: string, albumName: string, filePath: string): Promise<void>;
|
uploadImageToGroupAlbum(groupId: number, albumId: string, albumName: string, filePath: string): Promise<void>;
|
||||||
getGroupAlbumMediaList(groupId: number, albumId: string, attachInfo?: string): Promise<any>;
|
getGroupAlbumMediaList(groupId: number, albumId: string, attachInfo?: string): Promise<any>;
|
||||||
|
commentGroupAlbumMedia(groupId: number, albumId: string, lloc: string, content: string): Promise<any>;
|
||||||
|
deleteGroupAlbumMedia(groupId: number, albumId: string, lloc: string): Promise<any>;
|
||||||
|
likeGroupAlbumMedia(groupId: number, albumId: string, batchId: string, lloc: string | undefined, isLike: boolean): Promise<any>;
|
||||||
|
|
||||||
// ─── Forward ───
|
// ─── Forward ───
|
||||||
uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number): Promise<string>;
|
uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number): Promise<string>;
|
||||||
|
|||||||
@@ -129,7 +129,11 @@ import {
|
|||||||
getGroupAlbumListWeb as getGroupAlbumListWeb_,
|
getGroupAlbumListWeb as getGroupAlbumListWeb_,
|
||||||
uploadImageToGroupAlbumWeb as uploadImageToGroupAlbumWeb_,
|
uploadImageToGroupAlbumWeb as uploadImageToGroupAlbumWeb_,
|
||||||
} from './web-actions';
|
} from './web-actions';
|
||||||
import { getGroupAlbumMediaList as getGroupAlbumMediaList_ } from './actions/group-album';
|
import { getGroupAlbumMediaList as getGroupAlbumMediaList_,
|
||||||
|
commentGroupAlbumMedia as commentGroupAlbumMedia_,
|
||||||
|
likeGroupAlbumMedia as likeGroupAlbumMedia_,
|
||||||
|
deleteGroupAlbumMedia as deleteGroupAlbumMedia_,
|
||||||
|
} from './actions/group-album';
|
||||||
import type { GroupFilesResult } from './actions/group-file';
|
import type { GroupFilesResult } from './actions/group-file';
|
||||||
import type { MediaIndexNode } from './actions/shared';
|
import type { MediaIndexNode } from './actions/shared';
|
||||||
import { BridgeEventBus } from './event-bus';
|
import { BridgeEventBus } from './event-bus';
|
||||||
@@ -499,6 +503,18 @@ export class Bridge implements BridgeInterface {
|
|||||||
return getGroupAlbumMediaList_(this, groupId, albumId, attachInfo);
|
return getGroupAlbumMediaList_(this, groupId, albumId, attachInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async commentGroupAlbumMedia(groupId: number, albumId: string, lloc: string, content: string): Promise<any> {
|
||||||
|
return commentGroupAlbumMedia_(this, groupId, albumId, lloc, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
async likeGroupAlbumMedia(groupId: number, albumId: string, batchId: string, lloc: string | undefined, isLike: boolean): Promise<any> {
|
||||||
|
return likeGroupAlbumMedia_(this, groupId, albumId, batchId, lloc, isLike);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteGroupAlbumMedia(groupId: number, albumId: string, lloc: string): Promise<any> {
|
||||||
|
return deleteGroupAlbumMedia_(this, groupId, albumId, lloc);
|
||||||
|
}
|
||||||
|
|
||||||
async sendGroupNotice(groupId: number, content: string, options?: any) {
|
async sendGroupNotice(groupId: number, content: string, options?: any) {
|
||||||
return sendGroupNotice_(this, groupId, content, options);
|
return sendGroupNotice_(this, groupId, content, options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1351,4 +1351,185 @@ export const GetMediaListResponseSchema = {
|
|||||||
field2: { field: 2, type: 'bytes' as const },
|
field2: { field: 2, type: 'bytes' as const },
|
||||||
field3: { field: 3, type: 'bytes' as const },
|
field3: { field: 3, type: 'bytes' as const },
|
||||||
data: { field: 4, type: 'message' as const, schema: GetMediaListRspDataSchema }, // 将原本的 bytes 修正为 message 解析
|
data: { field: 4, type: 'message' as const, schema: GetMediaListRspDataSchema }, // 将原本的 bytes 修正为 message 解析
|
||||||
} satisfies ProtoSchema;
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
|
||||||
|
// --- DoQunComment: Comment on group album media ---
|
||||||
|
|
||||||
|
// --- DoQunComment: 严格对齐底层字节的字段定义 ---
|
||||||
|
|
||||||
|
export const CommentContentItemSchema = {
|
||||||
|
type: { field: 1, type: 'uint32' as const },
|
||||||
|
content: { field: 2, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentUserSchema = {
|
||||||
|
uin: { field: 13, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
// 评论具体内容结构 (原 CommentReqContentSchema)
|
||||||
|
export const CommentReqContentSchema = {
|
||||||
|
field2: { field: 2, type: 'message' as const, schema: CommentUserSchema },
|
||||||
|
field3: { field: 3, type: 'message' as const, schema: {
|
||||||
|
field1: { field: 1, type: 'uint32' as const },
|
||||||
|
field2: { field: 2, type: 'string' as const },
|
||||||
|
field3: { field: 3, type: 'string' as const },
|
||||||
|
field4: { field: 4, type: 'string' as const },
|
||||||
|
field5: { field: 5, type: 'uint32' as const },
|
||||||
|
field6: { field: 6, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
clientKey: { field: 7, type: 'string' as const }, // 对应你的 clientKey
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentReqPhotoInfoSchema = {
|
||||||
|
field1: { field: 1, type: 'message' as const, schema: {
|
||||||
|
field2: { field: 2, type: 'message' as const, schema: {
|
||||||
|
field1: { field: 1, type: 'uint32' as const },
|
||||||
|
field2: { field: 2, type: 'string' as const },
|
||||||
|
lloc: { field: 3, type: 'string' as const },
|
||||||
|
field4: { field: 4, type: 'string' as const },
|
||||||
|
field6: { field: 6, type: 'string' as const },
|
||||||
|
field7: { field: 7, type: 'uint32' as const },
|
||||||
|
field8: { field: 8, type: 'uint32' as const },
|
||||||
|
field9: { field: 9, type: 'uint32' as const },
|
||||||
|
field14: { field: 14, type: 'uint32' as const },
|
||||||
|
field15: { field: 15, type: 'uint32' as const },
|
||||||
|
field17: { field: 17, type: 'uint32' as const },
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
albumId: { field: 3, type: 'string' as const },
|
||||||
|
field5: { field: 5, type: 'uint32' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentReqBodySchema = {
|
||||||
|
field1: { field: 1, type: 'message' as const, schema: {
|
||||||
|
field3: { field: 3, type: 'uint32' as const },
|
||||||
|
field4: { field: 4, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
field2: { field: 2, type: 'message' as const, schema: {
|
||||||
|
field1: { field: 1, type: 'message' as const, schema: CommentUserSchema }
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
field5: { field: 5, type: 'message' as const, schema: CommentReqPhotoInfoSchema }, // 注意:抓包证实照片在 field 5
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunCommentRequestSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const },
|
||||||
|
field2: { field: 2, type: 'bytes' as const },
|
||||||
|
field3: { field: 3, type: 'bytes' as const },
|
||||||
|
body: { field: 4, type: 'message' as const, schema: {
|
||||||
|
groupId: { field: 2, type: 'string' as const },
|
||||||
|
field3: { field: 3, type: 'uint32' as const },
|
||||||
|
reqBody: { field: 4, type: 'message' as const, schema: CommentReqBodySchema },
|
||||||
|
field5: { field: 5, type: 'message' as const, schema: CommentReqContentSchema }, // 注意:评论文本实际在外层的 field 5
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
traceId: { field: 5, type: 'string' as const },
|
||||||
|
extMap: { field: 10, type: 'repeated_message' as const, schema: ExtMapEntrySchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentRespUserSchema = {
|
||||||
|
uin: { field: 13, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentRespContentSchema = {
|
||||||
|
type: { field: 1, type: 'uint32' as const },
|
||||||
|
content: { field: 2, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const CommentRespDataSchema = {
|
||||||
|
id: { field: 1, type: 'string' as const },
|
||||||
|
user: { field: 2, type: 'message' as const, schema: CommentRespUserSchema },
|
||||||
|
content: { field: 3, type: 'repeated_message' as const, schema: CommentRespContentSchema },
|
||||||
|
time: { field: 4, type: 'uint64' as const },
|
||||||
|
clientKey: { field: 7, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunCommentResponseSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const },
|
||||||
|
comment: { field: 4, type: 'message' as const, schema: {
|
||||||
|
data: { field: 2, type: 'message' as const, schema: CommentRespDataSchema },
|
||||||
|
} satisfies ProtoSchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
// --- DoQunLike: Like group album media ---
|
||||||
|
|
||||||
|
export const DoQunLikeReqLikeInfoSchema = {
|
||||||
|
id: { field: 1, type: 'string' as const },
|
||||||
|
status: { field: 3, type: 'uint32' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqCellCommonSchema = {
|
||||||
|
time: { field: 3, type: 'uint64' as const },
|
||||||
|
feedId: { field: 4, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqCellUserSchema = {
|
||||||
|
uin: { field: 13, type: 'string' as const }, // 修复:抓包证实 uin 是 field 13
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqCellUserInfoSchema = {
|
||||||
|
user: { field: 1, type: 'message' as const, schema: DoQunLikeReqCellUserSchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqCellQunInfoSchema = {
|
||||||
|
qunId: { field: 1, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqCellMediaSchema = {
|
||||||
|
albumId: { field: 3, type: 'string' as const },
|
||||||
|
batchId: { field: 5, type: 'uint64' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqFeedPublishSchema = {
|
||||||
|
cellCommon: { field: 1, type: 'message' as const, schema: DoQunLikeReqCellCommonSchema },
|
||||||
|
cellUserInfo: { field: 2, type: 'message' as const, schema: DoQunLikeReqCellUserInfoSchema },
|
||||||
|
cellMedia: { field: 5, type: 'message' as const, schema: DoQunLikeReqCellMediaSchema },
|
||||||
|
cellQunInfo: { field: 12, type: 'message' as const, schema: DoQunLikeReqCellQunInfoSchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeReqBodySchema = {
|
||||||
|
type: { field: 2, type: 'uint32' as const },
|
||||||
|
like: { field: 3, type: 'message' as const, schema: DoQunLikeReqLikeInfoSchema },
|
||||||
|
publish: { field: 4, type: 'message' as const, schema: DoQunLikeReqFeedPublishSchema },
|
||||||
|
clientKey: { field: 5, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeRequestSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const },
|
||||||
|
field2: { field: 2, type: 'string' as const },
|
||||||
|
field3: { field: 3, type: 'string' as const },
|
||||||
|
body: { field: 4, type: 'message' as const, schema: DoQunLikeReqBodySchema },
|
||||||
|
extMap: { field: 10, type: 'repeated_message' as const, schema: ExtMapEntrySchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeRespBodySchema = {
|
||||||
|
like: { field: 2, type: 'message' as const, schema: DoQunLikeReqLikeInfoSchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DoQunLikeResponseSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const },
|
||||||
|
body: { field: 4, type: 'message' as const, schema: DoQunLikeRespBodySchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
// --- DeleteMedias: Delete group album media ---
|
||||||
|
|
||||||
|
export const DeleteMediasReqBodySchema = {
|
||||||
|
groupId: { field: 1, type: 'string' as const },
|
||||||
|
albumId: { field: 2, type: 'string' as const },
|
||||||
|
lloc: { field: 3, type: 'string' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DeleteMediasRequestSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const },
|
||||||
|
field2: { field: 2, type: 'string' as const },
|
||||||
|
field3: { field: 3, type: 'string' as const },
|
||||||
|
body: { field: 4, type: 'message' as const, schema: DeleteMediasReqBodySchema },
|
||||||
|
traceId: { field: 5, type: 'string' as const }, // <-- 把它挪到外层了!
|
||||||
|
extMap: { field: 10, type: 'repeated_message' as const, schema: ExtMapEntrySchema },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
export const DeleteMediasResponseSchema = {
|
||||||
|
field1: { field: 1, type: 'int32' as const }, // 8694
|
||||||
|
field2: { field: 2, type: 'int32' as const }, // 错误码 (例如: 10023)
|
||||||
|
field3: { field: 3, type: 'string' as const }, // 错误信息 (例如: "no right delete...")
|
||||||
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
@@ -52,4 +52,81 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
|||||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
h.registerAction('do_group_album_comment', async (params) => {
|
||||||
|
const groupId = asNumber(params.group_id);
|
||||||
|
const albumId = asString(params.album_id);
|
||||||
|
const lloc = asString(params.lloc);
|
||||||
|
const content = asString(params.content);
|
||||||
|
|
||||||
|
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||||
|
if (!albumId) return failedResponse(RETCODE.BAD_REQUEST, 'album_id is required');
|
||||||
|
if (!lloc) return failedResponse(RETCODE.BAD_REQUEST, 'lloc is required');
|
||||||
|
if (!content) return failedResponse(RETCODE.BAD_REQUEST, 'content is required');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const comment = await ctx.commentGroupAlbumMedia(groupId, albumId, lloc, content);
|
||||||
|
return okResponse(comment);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'failed to comment on album media';
|
||||||
|
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
h.registerAction('set_group_album_media_like', async (params) => {
|
||||||
|
const groupId = asNumber(params.group_id);
|
||||||
|
const albumId = asString(params.album_id);
|
||||||
|
const batchId = asString(params.batch_id);
|
||||||
|
const lloc = params.lloc ? asString(params.lloc) : undefined; // 可选参数
|
||||||
|
|
||||||
|
if (!groupId || !albumId || !batchId) {
|
||||||
|
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, album_id and batch_id are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await ctx.likeGroupAlbumMedia(groupId, albumId, batchId, lloc, true);
|
||||||
|
return okResponse(res);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'failed to set like on album media';
|
||||||
|
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 取消点赞群相册媒体
|
||||||
|
h.registerAction('cancel_group_album_media_like', async (params) => {
|
||||||
|
const groupId = asNumber(params.group_id);
|
||||||
|
const albumId = asString(params.album_id);
|
||||||
|
const batchId = asString(params.batch_id);
|
||||||
|
const lloc = params.lloc ? asString(params.lloc) : undefined; // 可选参数
|
||||||
|
|
||||||
|
if (!groupId || !albumId || !batchId) {
|
||||||
|
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, album_id and batch_id are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await ctx.likeGroupAlbumMedia(groupId, albumId, batchId, lloc, false);
|
||||||
|
return okResponse(res);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'failed to cancel like on album media';
|
||||||
|
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
h.registerAction('del_group_album_media', async (params) => {
|
||||||
|
const groupId = asNumber(params.group_id);
|
||||||
|
const albumId = asString(params.album_id);
|
||||||
|
const lloc = asString(params.lloc);
|
||||||
|
|
||||||
|
if (!groupId || !albumId || !lloc) {
|
||||||
|
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, album_id and lloc are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await ctx.deleteGroupAlbumMedia(groupId, albumId, lloc);
|
||||||
|
return okResponse(res);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'failed to delete album media';
|
||||||
|
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -112,6 +112,9 @@ export interface ApiActionContext {
|
|||||||
getGroupAlbumList: (groupId: number) => Promise<any>;
|
getGroupAlbumList: (groupId: number) => Promise<any>;
|
||||||
uploadImageToGroupAlbum: (groupId: number, albumId: string, albumName: string, filePath: string) => Promise<void>;
|
uploadImageToGroupAlbum: (groupId: number, albumId: string, albumName: string, filePath: string) => Promise<void>;
|
||||||
getGroupAlbumMediaList: (groupId: number, albumId: string, attachInfo?: string) => Promise<any>;
|
getGroupAlbumMediaList: (groupId: number, albumId: string, attachInfo?: string) => Promise<any>;
|
||||||
|
commentGroupAlbumMedia: (groupId: number, albumId: string, lloc: string, content: string) => Promise<any>;
|
||||||
|
deleteGroupAlbumMedia: (groupId: number, albumId: string, lloc: string) => Promise<any>;
|
||||||
|
likeGroupAlbumMedia: (groupId: number, albumId: string, batchId: string, lloc: string | undefined, isLike: boolean) => Promise<any>;
|
||||||
sendGroupNotice: (groupId: number, content: string, options?: any) => Promise<any>;
|
sendGroupNotice: (groupId: number, content: string, options?: any) => Promise<any>;
|
||||||
getGroupNotice: (groupId: number) => Promise<any[]>;
|
getGroupNotice: (groupId: number) => Promise<any[]>;
|
||||||
deleteGroupNotice: (groupId: number, fid: string) => Promise<boolean>;
|
deleteGroupNotice: (groupId: number, fid: string) => Promise<boolean>;
|
||||||
|
|||||||
@@ -189,6 +189,9 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
|||||||
getGroupAlbumList: (groupId) => bridge.getGroupAlbumList(groupId),
|
getGroupAlbumList: (groupId) => bridge.getGroupAlbumList(groupId),
|
||||||
uploadImageToGroupAlbum: (groupId, albumId, albumName, filePath) => bridge.uploadImageToGroupAlbum(groupId, albumId, albumName, filePath),
|
uploadImageToGroupAlbum: (groupId, albumId, albumName, filePath) => bridge.uploadImageToGroupAlbum(groupId, albumId, albumName, filePath),
|
||||||
getGroupAlbumMediaList: (groupId, albumId, attachInfo) => bridge.getGroupAlbumMediaList(groupId, albumId, attachInfo),
|
getGroupAlbumMediaList: (groupId, albumId, attachInfo) => bridge.getGroupAlbumMediaList(groupId, albumId, attachInfo),
|
||||||
|
commentGroupAlbumMedia: (groupId, albumId, lloc, content) => bridge.commentGroupAlbumMedia(groupId, albumId, lloc, content),
|
||||||
|
deleteGroupAlbumMedia: (groupId, albumId, lloc) => bridge.deleteGroupAlbumMedia(groupId, albumId, lloc),
|
||||||
|
likeGroupAlbumMedia: (groupId, albumId, batchId, lloc, isLike) => bridge.likeGroupAlbumMedia(groupId, albumId, batchId, lloc, isLike),
|
||||||
sendGroupNotice: (groupId, content, options) => bridge.sendGroupNotice(groupId, content, options),
|
sendGroupNotice: (groupId, content, options) => bridge.sendGroupNotice(groupId, content, options),
|
||||||
getGroupNotice: (groupId) => bridge.getGroupNotice(groupId),
|
getGroupNotice: (groupId) => bridge.getGroupNotice(groupId),
|
||||||
deleteGroupNotice: (groupId, fid) => bridge.deleteGroupNotice(groupId, fid),
|
deleteGroupNotice: (groupId, fid) => bridge.deleteGroupNotice(groupId, fid),
|
||||||
|
|||||||
Reference in new issue
Block a user