* feat(qzone): 接入内置空间动态、说说和赞评接口 新增好友动态、个人说说、详情及点赞、取消赞、评论和回复动作。 纯文本发表接入QQ内置空间接口,保留原有图片发表和删除路径。 保留完整动态身份和原始数据,约束游标、权限转换及请求错误处理。 验证:全工作区类型检查,367项测试通过、1项既有条件测试跳过, 变更文件ESLint及WebUI、Shell、Framework、OpenAPI构建通过。 * feat(qzone): 补齐空间管理、评论分页及 SnowLuma 兼容 * fix(qzone): 兼容真实 FormSender 回执与评论字段 * fix(qzone): 兼容黑名单回执中的空间名称 * docs(qzone): remove redundant API readme
58 lines
2.9 KiB
TypeScript
58 lines
2.9 KiB
TypeScript
import { Static, Type } from '@sinclair/typebox';
|
|
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName, BaseCheckResult } from '@/napcat-onebot/action/router';
|
|
import type { QzoneProfileUpdate } from '@/napcat-core/data/qzone-web';
|
|
|
|
const profileValueSchema = (description: string) => Type.Union([
|
|
Type.String({ maxLength: 8192 }), Type.Number(), Type.Boolean(),
|
|
], { description });
|
|
export const SetQzoneProfilePayloadSchema = Type.Object({
|
|
name: Type.Optional(profileValueSchema('空间名称;空字符串表示清空,省略时不修改')),
|
|
description: Type.Optional(profileValueSchema('空间说明;空字符串表示清空,省略时不修改')),
|
|
}, { additionalProperties: false });
|
|
export type SetQzoneProfilePayload = Static<typeof SetQzoneProfilePayloadSchema>;
|
|
|
|
function profileUpdate (payload: SetQzoneProfilePayload): QzoneProfileUpdate {
|
|
if (!payload || typeof payload !== 'object' || Array.isArray(payload) || Object.keys(payload).some(key => key !== 'name' && key !== 'description')) {
|
|
throw new Error('修改空间资料只支持 name 和 description 参数');
|
|
}
|
|
const profile: QzoneProfileUpdate = {};
|
|
for (const key of ['name', 'description'] as const) {
|
|
const value = payload[key];
|
|
if (value === undefined) continue;
|
|
if ((typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') || (typeof value === 'number' && !Number.isFinite(value))) {
|
|
throw new Error(`${key} 必须为字符串、有限数字或布尔值`);
|
|
}
|
|
const normalized = String(value);
|
|
if (normalized.length > 8192) throw new Error(`${key} 不能超过8192个字符`);
|
|
profile[key] = normalized;
|
|
}
|
|
if (profile.name === undefined && profile.description === undefined) throw new Error('name 或 description 至少提供一项');
|
|
return profile;
|
|
}
|
|
|
|
export class SetQzoneProfile extends OneBotAction<SetQzoneProfilePayload, null> {
|
|
override actionName = ActionName.SetQzoneProfile;
|
|
override actionSummary = '修改QQ空间资料';
|
|
override actionDescription = '仅修改当前账号的空间名称或说明,至少提供一项。省略字段保持不变;空字符串清空字段;数字和布尔值转换为字符串。';
|
|
override actionTags = ['扩展接口'];
|
|
override payloadExample = { name: '我的空间', description: '记录生活' };
|
|
override returnExample = null;
|
|
override payloadSchema = SetQzoneProfilePayloadSchema;
|
|
override returnSchema = Type.Null();
|
|
|
|
protected override async check (payload: SetQzoneProfilePayload): Promise<BaseCheckResult> {
|
|
try {
|
|
profileUpdate(payload);
|
|
} catch (error) {
|
|
return { valid: false, message: (error as Error).message };
|
|
}
|
|
return await super.check(payload);
|
|
}
|
|
|
|
async _handle (payload: SetQzoneProfilePayload): Promise<null> {
|
|
await this.core.apis.QzoneApi.setProfile(profileUpdate(payload));
|
|
return null;
|
|
}
|
|
}
|