feat(onebot): include download urls on group notice images

_get_group_notice already returned picture ids. Add a fetchable url
on each image so callers do not need a separate action.

Fixes #440
This commit is contained in:
DrSmoothl committed 2026-09-13 21:25:59 +08:00
1 parent 201d10c534
commit 7ef256c487
8 files changed
+39 -9

No files matched your search

+4 -2
View File
@@ -10,6 +10,7 @@ import {
GROUP_NOTICE_TYPE_NEW_MEMBERS,
GROUP_NOTICE_TYPE_NORMAL,
getGroupNoticeWebAPI,
groupNoticeImageUrl,
setGroupNoticeWebAPI,
uploadGroupNoticeImage,
type SetNoticeRetSuccess,
@@ -43,8 +44,8 @@ export interface WebNoticeInfo {
publish_time: number;
message: {
text: string;
image: Array<{ id: string; height: number; width: number }>;
images: Array<{ id: string; height: number; width: number }>;
image: Array<{ id: string; url: string; height: number; width: number }>;
images: Array<{ id: string; url: string; height: number; width: number }>;
};
settings: import('@snowluma/common/json').JsonValue;
read_num: number;
@@ -104,6 +105,7 @@ function mapGroupNoticeFeed(feed: WebApiGroupNoticeFeed, sendToNewMembers: boole
}
return {
id: pic.id,
url: groupNoticeImageUrl(pic.id),
height: finiteNumber(pic.h, `feed ${feed.fid} image ${index}.h`),
width: finiteNumber(pic.w, `feed ${feed.fid} image ${index}.w`),
};
+6 -2
View File
@@ -33,8 +33,8 @@ describe('mapGroupNoticeResponse', () => {
publish_time: 1_700_000_000,
message: {
text: 'regular',
image: [{ id: 'pic', width: 640, height: 360 }],
images: [{ id: 'pic', width: 640, height: 360 }],
image: [{ id: 'pic', url: 'https://gdynamic.qpic.cn/gdynamic/pic/0', width: 640, height: 360 }],
images: [{ id: 'pic', url: 'https://gdynamic.qpic.cn/gdynamic/pic/0', width: 640, height: 360 }],
},
settings: {},
read_num: 2,
@@ -75,5 +75,9 @@ describe('mapGroupNoticeResponse', () => {
ec: 0,
feeds: [feed('bad', { msg: { text: 'bad', pics: [{ id: 'x', w: 'wide', h: 20 }] } })],
})).toThrow('image 0.w');
expect(() => mapGroupNoticeResponse({
ec: 0,
feeds: [feed('bad-id', { msg: { text: 'bad', pics: [{ id: 'a/b', w: 20, h: 20 }] } })],
})).toThrow('malformed');
});
});
+1 -1
View File
@@ -99,7 +99,7 @@
"name": "_get_group_notice",
"aliases": [],
"summary": "获取群公告",
"returns": "普通公告与新成员公告的合并数组;send_to_new_members 标识后者",
"returns": "普通公告与新成员公告的合并数组;send_to_new_members 标识后者;图片含 id、url、宽高",
"readOnly": true,
"params": [
{
+1 -1
View File
@@ -102,7 +102,7 @@ export const ACTIONS: CatalogAction[] = [
"name": "_get_group_notice",
"aliases": [],
"summary": "获取群公告",
"returns": "普通公告与新成员公告的合并数组;send_to_new_members 标识后者",
"returns": "普通公告与新成员公告的合并数组;send_to_new_members 标识后者;图片含 id、url、宽高",
"readOnly": true,
"params": [
{
+1 -1
View File
@@ -726,7 +726,7 @@ export const actions = [
groupAction({
name: '_get_group_notice',
summary: '获取群公告',
returns: '普通公告与新成员公告的合并数组;send_to_new_members 标识后者',
returns: '普通公告与新成员公告的合并数组;send_to_new_members 标识后者;图片含 id、url、宽高',
readOnly: true,
run: async (p, ctx) => {
const notices = await ctx.bridge.apis.web.getNotice(p.group_id);
+10
View File
@@ -21,6 +21,16 @@ export interface UploadImageRetSuccess {
export const GROUP_NOTICE_TYPE_NORMAL = 1;
export const GROUP_NOTICE_TYPE_NEW_MEMBERS = 20;
const GROUP_NOTICE_IMAGE_CDN = 'https://gdynamic.qpic.cn/gdynamic';
/** Public download URL for a group-notice picture id from list_announce. */
export function groupNoticeImageUrl(id: string): string {
const trimmed = id.trim();
if (!trimmed) throw new Error('group notice image id is empty');
if (/[/?#\s]/.test(trimmed)) throw new Error('group notice image id is malformed');
return `${GROUP_NOTICE_IMAGE_CDN}/${encodeURIComponent(trimmed)}/0`;
}
export interface SetGroupNoticeOptions {
pinned?: number;
/** Raw publish type kept for OneBot compatibility: 1=regular, 20=new members. */
@@ -3,6 +3,7 @@ import {
GROUP_NOTICE_TYPE_NEW_MEMBERS,
calculateBkn,
getGroupNoticeWebAPI,
groupNoticeImageUrl,
parseGroupNoticeImageUploadResponse,
resolveGroupNoticeOptions,
setGroupNoticeWebAPI,
@@ -103,6 +104,19 @@ describe('group-notice / publish HTTP layer', () => {
});
});
describe('group-notice / image download url', () => {
it('builds the public CDN url from a picture id', () => {
expect(groupNoticeImageUrl('pic-1')).toBe('https://gdynamic.qpic.cn/gdynamic/pic-1/0');
});
it('rejects empty or path-like ids', () => {
expect(() => groupNoticeImageUrl('')).toThrow('empty');
expect(() => groupNoticeImageUrl(' ')).toThrow('empty');
expect(() => groupNoticeImageUrl('a/b')).toThrow('malformed');
expect(() => groupNoticeImageUrl('a?x=1')).toThrow('malformed');
});
});
describe('group-notice / image upload response', () => {
it('parses HTML-escaped image metadata', () => {
expect(parseGroupNoticeImageUploadResponse(JSON.stringify({
+2 -2
View File
@@ -66,8 +66,8 @@ export interface GroupNoticeInfo {
publish_time: number;
message: {
text: string;
image: Array<{ id: string; height: number; width: number }>;
images: Array<{ id: string; height: number; width: number }>;
image: Array<{ id: string; url: string; height: number; width: number }>;
images: Array<{ id: string; url: string; height: number; width: number }>;
};
settings: JsonValue;
read_num: number;