feat: Qzone支持上传图片(发说说、评论附图) (#152)
* feat(core,onebot,protocol): support publish shuoshuo and comment with image * Fix: Accidentally changed notes
This commit is contained in:
1 parent
547640bbfd
commit
62eb8fd763
9 files changed
+658
-28
No files matched your search
@@ -222,6 +222,19 @@ describe('qzone / publishQzoneMsg (HTTP layer)', () => {
|
||||
expect(form.get('qzreferrer')).toBe('https://user.qzone.qq.com/10000');
|
||||
});
|
||||
|
||||
it('threads image richType/richval into the publish form', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue(
|
||||
'{"code":0,"t1_tid":"NEWTID","t1_time":"1700000000"}',
|
||||
);
|
||||
const richval = ',12345,abc,abc,22,800,600,,800,600\t,12346,def,def,22,640,480,,640,480';
|
||||
|
||||
await publishQzoneMsg(cookies, '10000', 'with images', 1, richval);
|
||||
|
||||
const form = new URLSearchParams(spy.mock.calls[0]![2] as string);
|
||||
expect(form.get('richtype')).toBe('1');
|
||||
expect(form.get('richval')).toBe(richval);
|
||||
});
|
||||
|
||||
it('falls back to tid/now for alternate client builds', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"tid":"ALT","now":1700000001}');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi')).resolves.toEqual({ tid: 'ALT', time: 1700000001 });
|
||||
@@ -233,6 +246,13 @@ describe('qzone / publishQzoneMsg (HTTP layer)', () => {
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects incomplete publish rich params before any request', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi', 1)).rejects.toThrow('richType and richval');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi', undefined, ',123')).rejects.toThrow('richType and richval');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws on a non-zero qzone code (rejected/rate-limited)', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-10000,"message":"too frequent"}');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi')).rejects.toThrow('code=-10000');
|
||||
@@ -378,7 +398,7 @@ describe('qzone / commentQzoneMsg (HTTP layer)', () => {
|
||||
expect(form.get('uin')).toBe('10000');
|
||||
expect(form.get('hostUin')).toBe('20002');
|
||||
expect(form.get('content')).toBe('说得好 & 顶');
|
||||
expect(form.get('format')).toBe('fs');
|
||||
expect(form.get('format')).toBe('json');
|
||||
// qzreferrer carries the commenter's own space (matches the impls)
|
||||
expect(form.get('qzreferrer')).toBe('https://user.qzone.qq.com/10000');
|
||||
// the re_feeds param family (3/3 impls) the publish sibling also sends
|
||||
@@ -387,6 +407,17 @@ describe('qzone / commentQzoneMsg (HTTP layer)', () => {
|
||||
expect(form.get('paramstr')).toBe('1');
|
||||
});
|
||||
|
||||
it('threads image direct-url richval into the comment form', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"commentid":987}');
|
||||
const richval = 'https://example.qzone.qq.com/a.jpg\thttps://example.qzone.qq.com/b.jpg';
|
||||
|
||||
await commentQzoneMsg(cookies, '10000', '20002', 'TIDX', 'pics', 1, richval);
|
||||
|
||||
const form = new URLSearchParams(spy.mock.calls[0]![2] as string);
|
||||
expect(form.get('richtype')).toBe('1');
|
||||
expect(form.get('richval')).toBe(richval);
|
||||
});
|
||||
|
||||
it('resolves with empty comment_id on success when the response carries no id (field name varies)', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0}');
|
||||
await expect(commentQzoneMsg(cookies, '10000', '20002', 'TIDX', 'hi')).resolves.toEqual({ comment_id: '' });
|
||||
@@ -404,6 +435,13 @@ describe('qzone / commentQzoneMsg (HTTP layer)', () => {
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects incomplete comment rich params before any request', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText');
|
||||
await expect(commentQzoneMsg(cookies, '10000', '20002', 'TIDX', 'hi', 1)).rejects.toThrow('richType and richval');
|
||||
await expect(commentQzoneMsg(cookies, '10000', '20002', 'TIDX', 'hi', undefined, 'https://example.com/img.jpg')).rejects.toThrow('richType and richval');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws on a non-zero code (comments disabled / no permission)', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-3000,"message":"forbidden"}');
|
||||
await expect(commentQzoneMsg(cookies, '10000', '20002', 'TIDX', 'hi')).rejects.toThrow('comment failed: code=-3000');
|
||||
|
||||
Reference in new issue
Block a user