fix: address P0 and P1 issues from code review
- P0-1: restore customExt field in SetStatusReqSchema - P0-2: remove duplicate setGroupAvatar implementation - P1-3: add attach_info pagination support for get_group_album_media_list - P1-5: clean up commented console.log statements - P1-6: remove raw field from GroupAlbumMediaResult
This commit is contained in:
1 parent
c58f4d4085
commit
e2ee528939
9 files changed
+9
-43
No files matched your search
@@ -214,32 +214,3 @@ 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);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import { GetMediaListRequestSchema, GetMediaListResponseSchema } from '../proto/
|
||||
export interface GroupAlbumMediaResult {
|
||||
mediaList: any[];
|
||||
nextAttachInfo: string;
|
||||
raw: any;
|
||||
}
|
||||
|
||||
function convertBigIntToString(obj: any): any {
|
||||
@@ -40,7 +39,7 @@ export async function getGroupAlbumMediaList(
|
||||
groupId: groupId.toString(),
|
||||
albumId: albumId,
|
||||
field3: 0,
|
||||
attachInfo: attachInfo, // 填入翻页游标
|
||||
attachInfo: attachInfo,
|
||||
field5: '',
|
||||
},
|
||||
traceId: traceId,
|
||||
@@ -59,7 +58,6 @@ export async function getGroupAlbumMediaList(
|
||||
|
||||
const resp = protoDecode(result.responseData, GetMediaListResponseSchema);
|
||||
|
||||
// 校验外层 TRPC 状态码
|
||||
if (!resp || (resp as any).field1 !== 0) {
|
||||
throw new Error(`fetch album media list error: retCode ${(resp as any)?.field1 || 'unknown'}`);
|
||||
}
|
||||
@@ -71,6 +69,5 @@ export async function getGroupAlbumMediaList(
|
||||
return convertBigIntToString({
|
||||
mediaList,
|
||||
nextAttachInfo,
|
||||
raw: resp
|
||||
});
|
||||
}
|
||||
@@ -94,7 +94,7 @@ export interface BridgeInterface {
|
||||
// ─── Group Album ───
|
||||
getGroupAlbumList(groupId: number): Promise<any>;
|
||||
uploadImageToGroupAlbum(groupId: number, albumId: string, albumName: string, filePath: string): Promise<void>;
|
||||
getGroupAlbumMediaList(groupId: number, albumId: string): Promise<any>;
|
||||
getGroupAlbumMediaList(groupId: number, albumId: string, attachInfo?: string): Promise<any>;
|
||||
|
||||
// ─── Forward ───
|
||||
uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number): Promise<string>;
|
||||
|
||||
@@ -495,8 +495,8 @@ export class Bridge implements BridgeInterface {
|
||||
return uploadImageToGroupAlbumWeb_(this, groupId, albumId, albumName, filePath);
|
||||
}
|
||||
|
||||
async getGroupAlbumMediaList(groupId: number, albumId: string): Promise<any> {
|
||||
return getGroupAlbumMediaList_(this, groupId, albumId);
|
||||
async getGroupAlbumMediaList(groupId: number, albumId: string, attachInfo?: string): Promise<any> {
|
||||
return getGroupAlbumMediaList_(this, groupId, albumId, attachInfo);
|
||||
}
|
||||
|
||||
async sendGroupNotice(groupId: number, content: string, options?: any) {
|
||||
|
||||
@@ -879,6 +879,7 @@ export const SetStatusReqSchema = {
|
||||
status: { field: 1, type: 'int32' as const },
|
||||
extStatus: { field: 2, type: 'int32' as const },
|
||||
batteryStatus: { field: 3, type: 'int32' as const },
|
||||
customExt: { field: 4, type: 'message' as const, schema: SetStatusCustomExtSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SetStatusRespSchema = {
|
||||
|
||||
@@ -128,10 +128,6 @@ async function createAlbumUploadSession(
|
||||
|
||||
const api = `https://h5.qzone.qq.com/webapp/json/sliceUpload/FileBatchControl/${imgMd5}?g_tk=${bkn}`;
|
||||
const cookie = `p_uin=o${uin}; p_skey=${pskey}; skey=${skey}; uin=o${uin}`;
|
||||
//
|
||||
// console.log(api);
|
||||
// console.log(cookie);
|
||||
// console.log(JSON.stringify(body));
|
||||
|
||||
const response = await RequestUtil.HttpGetJson<{ data: { session: string }, ret: number, msg: string }>(
|
||||
api,
|
||||
|
||||
@@ -39,12 +39,13 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_group_album_media_list', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const albumId = asString(params.album_id);
|
||||
const attachInfo = asString(params.attach_info) || '';
|
||||
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!albumId) return failedResponse(RETCODE.BAD_REQUEST, 'album_id is required');
|
||||
|
||||
try {
|
||||
const mediaList = await ctx.getGroupAlbumMediaList(groupId, albumId);
|
||||
const mediaList = await ctx.getGroupAlbumMediaList(groupId, albumId, attachInfo);
|
||||
return okResponse(mediaList);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to get group album media list';
|
||||
|
||||
@@ -111,7 +111,7 @@ export interface ApiActionContext {
|
||||
getGroupEssenceAll: (groupId: number) => Promise<GroupEssenceMsgRet[]>;
|
||||
getGroupAlbumList: (groupId: number) => Promise<any>;
|
||||
uploadImageToGroupAlbum: (groupId: number, albumId: string, albumName: string, filePath: string) => Promise<void>;
|
||||
getGroupAlbumMediaList: (groupId: number, albumId: string) => Promise<any>;
|
||||
getGroupAlbumMediaList: (groupId: number, albumId: string, attachInfo?: string) => Promise<any>;
|
||||
sendGroupNotice: (groupId: number, content: string, options?: any) => Promise<any>;
|
||||
getGroupNotice: (groupId: number) => Promise<any[]>;
|
||||
deleteGroupNotice: (groupId: number, fid: string) => Promise<boolean>;
|
||||
|
||||
@@ -188,7 +188,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getGroupEssenceAll: (groupId) => bridge.getGroupEssenceAll(groupId),
|
||||
getGroupAlbumList: (groupId) => bridge.getGroupAlbumList(groupId),
|
||||
uploadImageToGroupAlbum: (groupId, albumId, albumName, filePath) => bridge.uploadImageToGroupAlbum(groupId, albumId, albumName, filePath),
|
||||
getGroupAlbumMediaList: (groupId, albumId) => bridge.getGroupAlbumMediaList(groupId, albumId),
|
||||
getGroupAlbumMediaList: (groupId, albumId, attachInfo) => bridge.getGroupAlbumMediaList(groupId, albumId, attachInfo),
|
||||
sendGroupNotice: (groupId, content, options) => bridge.sendGroupNotice(groupId, content, options),
|
||||
getGroupNotice: (groupId) => bridge.getGroupNotice(groupId),
|
||||
deleteGroupNotice: (groupId, fid) => bridge.deleteGroupNotice(groupId, fid),
|
||||
|
||||
Reference in new issue
Block a user