feat: implement upload group avatar
This commit is contained in:
1 parent
00a70b1ccc
commit
b176e929b9
6 files changed
+49
-2
No files matched your search
@@ -151,3 +151,32 @@ export async function getGroupAtAllRemain(
|
||||
};
|
||||
}
|
||||
|
||||
// ─────────────── group avatar ───────────────
|
||||
|
||||
export async function setGroupAvatar(
|
||||
bridge: Bridge,
|
||||
groupId: number,
|
||||
source: string,
|
||||
): Promise<void> {
|
||||
const { loadBinarySource, computeHashes } = await import('../highway/utils');
|
||||
const { fetchHighwaySession, uploadHighwayHttp } = await import('../highway/highway-client');
|
||||
const { protoEncode } = await import('../../protobuf/decode');
|
||||
const { GroupAvatarUploadExtSchema } = await import('../proto/highway');
|
||||
|
||||
const loaded = await loadBinarySource(source, 'group avatar');
|
||||
if (!loaded.bytes.length) throw new Error('group avatar file is empty');
|
||||
|
||||
const extend = protoEncode({
|
||||
field1: 101,
|
||||
groupId: BigInt(groupId),
|
||||
field3: new Uint8Array([0x08, 0x01, 0x12, 0x00]),
|
||||
field5: 3,
|
||||
field6: 0,
|
||||
}, GroupAvatarUploadExtSchema);
|
||||
|
||||
const hashes = computeHashes(loaded.bytes);
|
||||
const session = await fetchHighwaySession(bridge);
|
||||
|
||||
await uploadHighwayHttp(bridge, session, 3000, loaded.bytes, hashes.md5, extend);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
setGroupSpecialTitle as setGroupSpecialTitle_,
|
||||
setGroupRemark as setGroupRemark_,
|
||||
getGroupAtAllRemain as getGroupAtAllRemain_,
|
||||
setGroupAvatar as setGroupAvatar_,
|
||||
} from './actions/group-admin';
|
||||
import {
|
||||
uploadGroupFile as uploadGroupFile_,
|
||||
@@ -631,6 +632,7 @@ export class Bridge {
|
||||
async markPrivateMsgAsRead(userId: number, sequence: number): Promise<void> { return markPrivateMsgAsRead_(this, userId, sequence); }
|
||||
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
||||
async setGroupRemark(groupId: number, remark: string): Promise<void> { return setGroupRemark_(this, groupId, remark); }
|
||||
async setGroupAvatar(groupId: number, source: string): Promise<void> { return setGroupAvatar_(this, groupId, source); }
|
||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||
return getGroupHonorInfo_(this, groupId, type);
|
||||
}
|
||||
|
||||
@@ -334,3 +334,13 @@ export const NTV2UploadRichMediaRespSchema = {
|
||||
respHead: { field: 1, type: 'message' as const, schema: NTV2UploadRespHeadSchema },
|
||||
upload: { field: 2, type: 'message' as const, schema: NTV2UploadRespBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Group Avatar Upload Extend ---
|
||||
|
||||
export const GroupAvatarUploadExtSchema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
groupId: { field: 2, type: 'uint64' as const },
|
||||
field3: { field: 3, type: 'bytes' as const },
|
||||
field5: { field: 5, type: 'uint32' as const },
|
||||
field6: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
Reference in new issue
Block a user