mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 08:10:25 +00:00
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import {ActionName} from '../types';
|
|
import {FromSchema, JSONSchema} from 'json-schema-to-ts';
|
|
import {GetPacketStatusDepends} from "@/onebot/action/packet/GetPacketStatus";
|
|
import {MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams} from "@/core/packet/entities/miniApp";
|
|
import {MiniAppInfo, MiniAppInfoHelper} from "@/core/packet/helper/miniAppHelper";
|
|
|
|
const SchemaData = {
|
|
type: 'object',
|
|
properties: {
|
|
type: {
|
|
type: 'string',
|
|
enum: ['bili', 'weibo']
|
|
},
|
|
title: {type: 'string'},
|
|
desc: {type: 'string'},
|
|
picUrl: {type: 'string'},
|
|
jumpUrl: {type: 'string'},
|
|
iconUrl: {type: 'string'},
|
|
sdkId: {type: 'string'},
|
|
appId: {type: 'string'},
|
|
scene: {type: ['number', 'string']},
|
|
templateType: {type: ['number', 'string']},
|
|
businessType: {type: ['number', 'string']},
|
|
verType: {type: ['number', 'string']},
|
|
shareType: {type: ['number', 'string']},
|
|
versionId: {type: 'string'},
|
|
withShareTicket: {type: ['number', 'string']},
|
|
rawArkData: {type: ['boolean', 'string']}
|
|
},
|
|
oneOf: [
|
|
{
|
|
required: ['type', 'title', 'desc', 'picUrl', 'jumpUrl']
|
|
},
|
|
{
|
|
required: [
|
|
'title', 'desc', 'picUrl', 'jumpUrl',
|
|
'iconUrl', 'appId', 'scene', 'templateType', 'businessType',
|
|
'verType', 'shareType', 'versionId', 'withShareTicket'
|
|
]
|
|
}
|
|
]
|
|
} as const satisfies JSONSchema;
|
|
|
|
type Payload = FromSchema<typeof SchemaData>;
|
|
|
|
export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
|
data: MiniAppData | MiniAppRawData
|
|
}> {
|
|
actionName = ActionName.GetMiniAppArk;
|
|
payloadSchema = SchemaData;
|
|
|
|
async _handle(payload: Payload) {
|
|
let reqParam: MiniAppReqParams;
|
|
const customParams = {
|
|
title: payload.title,
|
|
desc: payload.desc,
|
|
picUrl: payload.picUrl,
|
|
jumpUrl: payload.jumpUrl
|
|
} as MiniAppReqCustomParams;
|
|
if (payload.type) {
|
|
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
|
} else {
|
|
const { appId, scene, iconUrl, templateType, businessType, verType, shareType, versionId, withShareTicket } = payload as Required<Payload>;
|
|
reqParam = MiniAppInfoHelper.generateReq(
|
|
customParams,
|
|
{
|
|
sdkId: payload.sdkId ?? MiniAppInfo.sdkId,
|
|
appId: appId,
|
|
scene: +scene,
|
|
iconUrl: iconUrl,
|
|
templateType: +templateType,
|
|
businessType: +businessType,
|
|
verType: +verType,
|
|
shareType: +shareType,
|
|
versionId: versionId,
|
|
withShareTicket: +withShareTicket
|
|
}
|
|
)
|
|
}
|
|
const arkData = await this.core.apis.PacketApi.sendMiniAppShareInfoReq(reqParam);
|
|
return {
|
|
data: Boolean(payload.rawArkData) ? arkData : MiniAppInfoHelper.RawToSend(arkData)
|
|
}
|
|
}
|
|
}
|