Files
NapCatQQ/packages/napcat-onebot/action/extends/qzone/GetQzoneProfile.ts
T
Qiao 49ecfe0f56 feat(qzone): 完善空间 API 并兼容 SnowLuma API 格式 (#2124)
* feat(qzone): 接入内置空间动态、说说和赞评接口

新增好友动态、个人说说、详情及点赞、取消赞、评论和回复动作。
纯文本发表接入QQ内置空间接口,保留原有图片发表和删除路径。
保留完整动态身份和原始数据,约束游标、权限转换及请求错误处理。

验证:全工作区类型检查,367项测试通过、1项既有条件测试跳过,
变更文件ESLint及WebUI、Shell、Framework、OpenAPI构建通过。

* feat(qzone): 补齐空间管理、评论分页及 SnowLuma 兼容

* fix(qzone): 兼容真实 FormSender 回执与评论字段

* fix(qzone): 兼容黑名单回执中的空间名称

* docs(qzone): remove redundant API readme
2026-10-30 00:17:49 +08:00

55 lines
2.5 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 { QzoneProfile } from '@/napcat-core/data/qzone-web';
export const GetQzoneProfilePayloadSchema = Type.Object({
target_uin: Type.Optional(Type.Union([
Type.String({ pattern: '^[1-9][0-9]*$', maxLength: 20 }),
Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),
], { description: '空间所属 QQ 号;不传时为当前账号' })),
}, { additionalProperties: false });
export type GetQzoneProfilePayload = Static<typeof GetQzoneProfilePayloadSchema>;
const ReturnSchema = Type.Object({
name: Type.String({ description: '空间名称' }),
description: Type.String({ description: '空间说明' }),
});
function targetUin (payload: GetQzoneProfilePayload): string | undefined {
if (!payload || typeof payload !== 'object' || Array.isArray(payload) || Object.keys(payload).some(key => key !== 'target_uin')) {
throw new Error('获取空间资料只支持 target_uin 参数');
}
const value = payload.target_uin;
if (value === undefined) return undefined;
if (typeof value === 'number' && (!Number.isSafeInteger(value) || value <= 0)) throw new Error('target_uin 必须为有效QQ号');
if ((typeof value !== 'string' && typeof value !== 'number') || !/^[1-9][0-9]{0,19}$/.test(String(value))) {
throw new Error('target_uin 必须为有效QQ号');
}
return String(value);
}
export class GetQzoneProfile extends OneBotAction<GetQzoneProfilePayload, QzoneProfile> {
override actionName = ActionName.GetQzoneProfile;
override actionSummary = '获取QQ空间资料';
override actionDescription = '获取空间名称和空间说明;target_uin 不传时读取当前账号,空名称或说明按原值返回。';
override actionTags = ['扩展接口'];
override payloadExample = { target_uin: '10001' };
override returnExample = { name: '我的空间', description: '记录生活' };
override payloadSchema = GetQzoneProfilePayloadSchema;
override returnSchema = ReturnSchema;
protected override async check (payload: GetQzoneProfilePayload): Promise<BaseCheckResult> {
try {
targetUin(payload);
} catch (error) {
return { valid: false, message: (error as Error).message };
}
return await super.check(payload);
}
async _handle (payload: GetQzoneProfilePayload): Promise<QzoneProfile> {
return await this.core.apis.QzoneApi.getProfile(targetUin(payload));
}
}