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:
8 files changed
+39
-9
No files matched your search
@@ -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({
|
||||
|
||||
Reference in new issue
Block a user