Files
certd/packages/ui/certd-server/src/controller/sys/plus/plus-controller.ts
T

90 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-10-12 16:49:49 +08:00
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from '@certd/lib-server';
2025-11-05 00:08:59 +08:00
import { logger } from '@certd/basic';
2024-08-14 21:24:12 +08:00
/**
*/
@Provide()
@Controller('/api/sys/plus')
export class SysPlusController extends BaseController {
@Inject()
sysSettingsService: SysSettingsService;
2024-08-24 01:05:06 +08:00
@Inject()
plusService: PlusService;
2024-08-14 21:24:12 +08:00
@Post('/active', { summary: 'sys:settings:edit' })
async active(@Body(ALL) body) {
2024-12-09 00:12:15 +08:00
const { code, inviteCode } = body;
2024-08-14 21:24:12 +08:00
2024-12-09 00:12:15 +08:00
await this.plusService.active(code, inviteCode);
2024-08-14 21:24:12 +08:00
2024-09-24 02:42:08 +08:00
return this.ok(true);
}
@Post('/bindUrl', { summary: 'sys:settings:edit' })
async bindUrl(@Body(ALL) body: { url: string }) {
const { url } = body;
2024-12-23 23:33:13 +08:00
await this.plusService.register();
2024-09-24 02:42:08 +08:00
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
2024-11-07 02:05:20 +08:00
await this.plusService.bindUrl(url);
2024-09-24 02:42:08 +08:00
installInfo.bindUrl = url;
await this.sysSettingsService.saveSetting(installInfo);
2025-11-05 00:08:59 +08:00
//重新验证vip
try{
await this.plusService.verify();
}catch(e){
logger.error(`验证配置失败:${e}`);
}
2024-10-08 19:02:51 +08:00
return this.ok(true);
}
2024-11-17 01:06:27 +08:00
@Post('/getVipTrial', { summary: 'sys:settings:edit' })
2025-08-15 00:20:38 +08:00
async getVipTrial(@Body("vipType") vipType?:string) {
const res = await this.plusService.getVipTrial(vipType);
2024-11-17 01:06:27 +08:00
return this.ok(res);
}
2024-10-12 16:49:49 +08:00
//
// @Get('/test', { summary: Constants.per.guest })
// async test() {
// const subjectId = 'xxxxxx';
// const license = '';
// const timestamps = 1728365013899;
// const bindUrl = 'http://127.0.0.1:7001/';
// const service = new PlusRequestService({
// subjectId: subjectId,
// plusServerBaseUrls: ['https://api.ai.handsfree.work'],
// });
// const body = { subjectId, appKey: 'kQth6FHM71IPV3qdWc', url: bindUrl };
//
// async function test() {
// await verify({
// subjectId: subjectId,
// license: license,
// plusRequestService: service,
// });
//
// const res = await service.sign(body, timestamps);
// console.log('sign:', res);
//
// const res2 = await service.request({
// url: '/activation/subject/vip/check',
// data: {
// url: 'http://127.0.0.1:7001/',
// },
// });
//
// console.log('res2:', res2);
// }
// console.log('2222');
// await test();
// console.log('3333');
//
// return this.ok(true);
// }
2024-08-14 21:24:12 +08:00
}