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 { 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 {
|
||||
mediaList: any[];
|
||||
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 {
|
||||
if (obj === null || obj === undefined) return obj;
|
||||
if (typeof obj === 'bigint') return obj.toString();
|
||||
@@ -71,3 +87,196 @@ export async function getGroupAlbumMediaList(
|
||||
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 };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user