feat(group-album): expose cover and upload metadata
Decode the verified album cover response field and expose normalized cover details and last-upload timestamps through both album list actions. Preserve the legacy numeric timestamp shape, retain string timestamps for the native response, return null when no cover exists, and avoid additional network requests. Document the new output contracts in the OneBot and MCP catalogs. Add independent wire fixtures and action-level regression tests for the protocol mapping and public response shapes. Refs #257
This commit is contained in:
9 files changed
+841
-5
No files matched your search
@@ -14,6 +14,7 @@ import type {
|
||||
GetMediaListRequest,
|
||||
GetMediaListResponse,
|
||||
MediaInfo,
|
||||
UrlInfo,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-album';
|
||||
import { uploadImageToGroupAlbum } from '@snowluma/protocol/web/group-album';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
@@ -53,6 +54,35 @@ function normalizeAlbumCreator(creator: AlbumCreator | undefined): QunAlbumCreat
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeCoverUrl(url: UrlInfo | null | undefined): QunAlbumCoverUrl | null {
|
||||
if (!url) return null;
|
||||
return {
|
||||
url: url.url ?? '',
|
||||
width: url.width ?? 0,
|
||||
height: url.height ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeAlbumCover(cover: MediaInfo | undefined): QunAlbumCover | null {
|
||||
if (!cover) return null;
|
||||
const image = cover.image;
|
||||
return {
|
||||
type: cover.type ?? 0,
|
||||
image: image ? {
|
||||
name: image.name ?? '',
|
||||
sloc: image.sloc ?? '',
|
||||
lloc: image.lloc ?? '',
|
||||
photoUrls: (image.photoUrls ?? []).map((photoUrl) => ({
|
||||
spec: photoUrl.spec ?? 0,
|
||||
url: normalizeCoverUrl(photoUrl.url),
|
||||
})),
|
||||
defaultUrl: normalizeCoverUrl(image.defaultUrl),
|
||||
isGif: image.isGif ?? false,
|
||||
hasRaw: image.hasRaw ?? false,
|
||||
} : null,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeQunAlbum(album: GroupAlbumInfoWire): QunAlbumInfo {
|
||||
const normalized: QunAlbumInfo = {
|
||||
album_id: album.albumId ?? '',
|
||||
@@ -63,6 +93,7 @@ function normalizeQunAlbum(album: GroupAlbumInfoWire): QunAlbumInfo {
|
||||
modify_time: uint64ToString(album.modifyTime),
|
||||
last_upload_time: uint64ToString(album.lastUploadTime),
|
||||
upload_number: uint64ToString(album.uploadNumber),
|
||||
cover: normalizeAlbumCover(album.cover),
|
||||
top_flag: uint64ToString(album.topFlag),
|
||||
busi_type: album.busiType ?? 0,
|
||||
status: album.status ?? 0,
|
||||
@@ -94,6 +125,8 @@ function toLegacyAlbum(album: GroupAlbumInfoWire): GroupAlbumInfo {
|
||||
// Unlike the legacy Qzone HTTP endpoint, it does not rewrite Unicode
|
||||
// emoji into ambiguous [em]...[/em] tags.
|
||||
createnickname: creator?.nick ?? '',
|
||||
last_upload_time: uint64ToSafeNumber(album.lastUploadTime, 'last_upload_time'),
|
||||
cover: normalizeAlbumCover(album.cover),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -426,6 +459,8 @@ export interface GroupAlbumInfo {
|
||||
owner: string;
|
||||
createuin: string;
|
||||
createnickname: string;
|
||||
last_upload_time: number;
|
||||
cover: QunAlbumCover | null;
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
@@ -446,6 +481,32 @@ export interface QunAlbumCreator {
|
||||
ditto_uin: string;
|
||||
}
|
||||
|
||||
export interface QunAlbumCoverUrl extends JsonObject {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface QunAlbumCoverPhotoUrl extends JsonObject {
|
||||
spec: number;
|
||||
url: QunAlbumCoverUrl | null;
|
||||
}
|
||||
|
||||
export interface QunAlbumCoverImage extends JsonObject {
|
||||
name: string;
|
||||
sloc: string;
|
||||
lloc: string;
|
||||
photoUrls: QunAlbumCoverPhotoUrl[];
|
||||
defaultUrl: QunAlbumCoverUrl | null;
|
||||
isGif: boolean;
|
||||
hasRaw: boolean;
|
||||
}
|
||||
|
||||
export interface QunAlbumCover extends JsonObject {
|
||||
type: number;
|
||||
image: QunAlbumCoverImage | null;
|
||||
}
|
||||
|
||||
export interface QunAlbumInfo {
|
||||
album_id: string;
|
||||
owner: string;
|
||||
@@ -455,6 +516,7 @@ export interface QunAlbumInfo {
|
||||
modify_time: string;
|
||||
last_upload_time: string;
|
||||
upload_number: string;
|
||||
cover: QunAlbumCover | null;
|
||||
creator?: QunAlbumCreator;
|
||||
top_flag: string;
|
||||
busi_type: number;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import type { bytes, int_32, pb, pb_repeated } from '@snowluma/proton';
|
||||
import type {
|
||||
bool,
|
||||
bytes,
|
||||
int_32,
|
||||
pb,
|
||||
pb_repeated,
|
||||
uint_32,
|
||||
uint_64,
|
||||
} from '@snowluma/proton';
|
||||
|
||||
interface GroupAlbumListReqDataWireOracle {
|
||||
groupId?: pb<1, string>;
|
||||
@@ -19,6 +27,52 @@ export interface GroupAlbumListRequestWireOracle {
|
||||
extMap?: pb_repeated<10, GroupAlbumListExtWireOracle>;
|
||||
}
|
||||
|
||||
interface GroupAlbumCoverUrlWireOracle {
|
||||
url?: pb<1, string>;
|
||||
width?: pb<2, uint_32>;
|
||||
height?: pb<3, uint_32>;
|
||||
}
|
||||
|
||||
interface GroupAlbumCoverPhotoUrlWireOracle {
|
||||
spec?: pb<1, uint_32>;
|
||||
url?: pb<2, GroupAlbumCoverUrlWireOracle>;
|
||||
}
|
||||
|
||||
interface GroupAlbumCoverImageWireOracle {
|
||||
name?: pb<1, string>;
|
||||
sloc?: pb<2, string>;
|
||||
lloc?: pb<3, string>;
|
||||
photoUrls?: pb_repeated<4, GroupAlbumCoverPhotoUrlWireOracle>;
|
||||
defaultUrl?: pb<5, GroupAlbumCoverUrlWireOracle>;
|
||||
isGif?: pb<6, bool>;
|
||||
hasRaw?: pb<7, bool>;
|
||||
}
|
||||
|
||||
interface GroupAlbumCoverWireOracle {
|
||||
type?: pb<1, uint_32>;
|
||||
image?: pb<2, GroupAlbumCoverImageWireOracle>;
|
||||
}
|
||||
|
||||
interface GroupAlbumListItemWireOracle {
|
||||
albumId?: pb<1, string>;
|
||||
owner?: pb<2, string>;
|
||||
name?: pb<3, string>;
|
||||
description?: pb<4, string>;
|
||||
createTime?: pb<5, uint_64>;
|
||||
lastUploadTime?: pb<7, uint_64>;
|
||||
uploadNumber?: pb<8, uint_64>;
|
||||
cover?: pb<9, GroupAlbumCoverWireOracle>;
|
||||
}
|
||||
|
||||
interface GroupAlbumListResponseDataWireOracle {
|
||||
albumList?: pb_repeated<1, GroupAlbumListItemWireOracle>;
|
||||
}
|
||||
|
||||
export interface GroupAlbumListResponseWireOracle {
|
||||
result?: pb<2, int_32>;
|
||||
data?: pb<4, GroupAlbumListResponseDataWireOracle>;
|
||||
}
|
||||
|
||||
interface GroupAlbumMediaListReqInfoWireOracle {
|
||||
reserved?: pb<4, string>;
|
||||
pageInfo?: pb<5, string>;
|
||||
|
||||
@@ -8,9 +8,41 @@ import { GroupAlbumApi } from '../../src/bridge/apis/group-album';
|
||||
import { mockBridge } from './_helpers';
|
||||
import type {
|
||||
GroupAlbumListRequestWireOracle,
|
||||
GroupAlbumListResponseWireOracle,
|
||||
GroupAlbumMediaListRequestWireOracle,
|
||||
} from './group-album-wire-fixture';
|
||||
|
||||
function albumListResponseWithCover(): Uint8Array {
|
||||
return protobuf_encode<GroupAlbumListResponseWireOracle>({
|
||||
data: {
|
||||
albumList: [{
|
||||
albumId: 'album-id',
|
||||
owner: '10001',
|
||||
name: '测试相册',
|
||||
description: 'desc',
|
||||
createTime: 1700000000n,
|
||||
lastUploadTime: 1700000123n,
|
||||
uploadNumber: 5n,
|
||||
cover: {
|
||||
type: 1,
|
||||
image: {
|
||||
name: 'cover.jpg',
|
||||
sloc: 'small-location',
|
||||
lloc: 'large-location',
|
||||
photoUrls: [{
|
||||
spec: 3,
|
||||
url: { url: 'https://example.test/cover-320.jpg', width: 320, height: 180 },
|
||||
}],
|
||||
defaultUrl: { url: 'https://example.test/cover.jpg', width: 1280, height: 720 },
|
||||
isGif: false,
|
||||
hasRaw: true,
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe('apis/group-album', () => {
|
||||
it('uses QQ NT AlbumService and puts the pagination cursor in request body field 2', async () => {
|
||||
const bridge = mockBridge();
|
||||
@@ -70,6 +102,8 @@ describe('apis/group-album', () => {
|
||||
owner: '10001',
|
||||
createuin: '10001',
|
||||
createnickname: '😂[em]e328514[/em]',
|
||||
last_upload_time: 0,
|
||||
cover: null,
|
||||
}]);
|
||||
});
|
||||
|
||||
@@ -108,6 +142,64 @@ describe('apis/group-album', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('decodes the native album cover field for get_qun_album_list', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(albumListResponseWithCover()),
|
||||
});
|
||||
|
||||
const result = await new GroupAlbumApi(bridge as never).listQun(12345);
|
||||
|
||||
expect(result.albumList[0]).toMatchObject({
|
||||
album_id: 'album-id',
|
||||
last_upload_time: '1700000123',
|
||||
cover: {
|
||||
type: 1,
|
||||
image: {
|
||||
name: 'cover.jpg',
|
||||
sloc: 'small-location',
|
||||
lloc: 'large-location',
|
||||
photoUrls: [{
|
||||
spec: 3,
|
||||
url: { url: 'https://example.test/cover-320.jpg', width: 320, height: 180 },
|
||||
}],
|
||||
defaultUrl: { url: 'https://example.test/cover.jpg', width: 1280, height: 720 },
|
||||
isGif: false,
|
||||
hasRaw: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns cover and last-upload metadata from the legacy album list action', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(albumListResponseWithCover()),
|
||||
});
|
||||
|
||||
const result = await new GroupAlbumApi(bridge as never).list(12345);
|
||||
|
||||
expect(result[0]).toMatchObject({
|
||||
id: 'album-id',
|
||||
last_upload_time: 1700000123,
|
||||
cover: {
|
||||
type: 1,
|
||||
image: {
|
||||
name: 'cover.jpg',
|
||||
defaultUrl: { url: 'https://example.test/cover.jpg', width: 1280, height: 720 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('surfaces AlbumService response errors instead of falling back to the lossy web endpoint', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
|
||||
Reference in new issue
Block a user