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

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-08-14 21:24:12 +08:00
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { SysSettingsService } from '../service/sys-settings-service.js';
import { BaseController } from '../../../basic/base-controller.js';
2024-09-23 14:04:33 +08:00
import { AppKey } from '@certd/pipeline';
import { SysInstallInfo } from '../service/models.js';
2024-08-14 21:24:12 +08:00
import { logger } from '../../../utils/logger.js';
2024-08-24 01:05:06 +08:00
import { PlusService } from '../../basic/service/plus-service.js';
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) {
const { code } = body;
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
2024-09-23 14:04:33 +08:00
const siteId = installInfo.siteId;
2024-08-14 21:24:12 +08:00
const formData = {
2024-08-25 01:55:34 +08:00
appKey: AppKey,
2024-08-14 21:24:12 +08:00
code,
2024-09-23 14:04:33 +08:00
subjectId: siteId,
2024-08-14 21:24:12 +08:00
};
2024-08-21 08:36:03 +08:00
2024-08-24 01:05:06 +08:00
const res: any = await this.plusService.active(formData);
2024-08-14 21:24:12 +08:00
if (res.code > 0) {
logger.error('激活失败', res.message);
return this.fail(res.message, 1);
}
const license = res.data.license;
2024-09-24 11:11:08 +08:00
await this.plusService.updateLicense(license);
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;
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
await this.plusService.bindUrl(installInfo.siteId, url);
installInfo.bindUrl = url;
await this.sysSettingsService.saveSetting(installInfo);
2024-09-23 14:04:33 +08:00
return this.ok(true);
2024-08-14 21:24:12 +08:00
}
}