2024-10-12 14:59:12 +08:00
|
|
|
import { Config, Controller, Get, Inject, Provide } from '@midwayjs/core';
|
2024-12-25 00:52:39 +08:00
|
|
|
import {
|
|
|
|
|
BaseController,
|
|
|
|
|
Constants,
|
|
|
|
|
SysHeaderMenus,
|
|
|
|
|
SysInstallInfo,
|
|
|
|
|
SysPublicSettings,
|
|
|
|
|
SysSettingsService,
|
|
|
|
|
SysSiteEnv,
|
|
|
|
|
SysSiteInfo,
|
|
|
|
|
SysSuiteSetting,
|
|
|
|
|
} from '@certd/lib-server';
|
2024-11-25 09:51:45 +08:00
|
|
|
import { AppKey, getPlusInfo, isComm } from '@certd/plus-core';
|
2025-01-24 20:02:11 +08:00
|
|
|
import { cloneDeep } from 'lodash-es';
|
2024-06-16 00:20:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/basic/settings')
|
|
|
|
|
export class BasicSettingsController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
2024-09-24 02:42:08 +08:00
|
|
|
@Config('account.server.baseUrl')
|
|
|
|
|
accountServerBaseUrl: any;
|
2024-06-16 00:20:02 +08:00
|
|
|
|
2024-10-10 18:38:22 +08:00
|
|
|
@Config('agent')
|
|
|
|
|
agentConfig: SysSiteEnv['agent'];
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
public async getSysPublic() {
|
2024-10-12 14:59:12 +08:00
|
|
|
return await this.sysSettingsService.getSetting(SysPublicSettings);
|
2024-06-16 00:20:02 +08:00
|
|
|
}
|
2024-08-25 01:55:34 +08:00
|
|
|
|
|
|
|
|
public async getInstallInfo() {
|
2024-09-24 02:42:08 +08:00
|
|
|
const settings: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
|
|
|
|
settings.accountServerBaseUrl = this.accountServerBaseUrl;
|
|
|
|
|
settings.appKey = AppKey;
|
2024-10-12 14:59:12 +08:00
|
|
|
return settings;
|
2024-08-25 01:55:34 +08:00
|
|
|
}
|
2024-09-23 11:27:53 +08:00
|
|
|
|
|
|
|
|
public async getSiteInfo() {
|
2024-10-12 14:59:12 +08:00
|
|
|
return await this.sysSettingsService.getSetting(SysSiteInfo);
|
2024-09-23 11:27:53 +08:00
|
|
|
}
|
2024-10-05 01:46:25 +08:00
|
|
|
|
2024-10-25 23:56:24 +08:00
|
|
|
public async getHeaderMenus() {
|
|
|
|
|
return await this.sysSettingsService.getSetting(SysHeaderMenus);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-25 00:52:39 +08:00
|
|
|
public async getSuiteSetting() {
|
|
|
|
|
if (!isComm()) {
|
|
|
|
|
return { enabled: false };
|
|
|
|
|
}
|
|
|
|
|
const setting = await this.sysSettingsService.getSetting<SysSuiteSetting>(SysSuiteSetting);
|
|
|
|
|
return {
|
|
|
|
|
enabled: setting.enabled,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 18:38:22 +08:00
|
|
|
public async getSiteEnv() {
|
|
|
|
|
const env: SysSiteEnv = {
|
|
|
|
|
agent: this.agentConfig,
|
|
|
|
|
};
|
2024-10-12 14:59:12 +08:00
|
|
|
return env;
|
2024-10-10 18:38:22 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-12 14:59:12 +08:00
|
|
|
async plusInfo() {
|
2025-01-24 20:02:11 +08:00
|
|
|
const res = getPlusInfo();
|
|
|
|
|
const copy = cloneDeep(res);
|
|
|
|
|
delete copy.secret;
|
|
|
|
|
return copy;
|
2024-10-12 14:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('/all', { summary: Constants.per.guest })
|
|
|
|
|
async getAllSettings() {
|
|
|
|
|
const sysPublic = await this.getSysPublic();
|
|
|
|
|
const installInfo = await this.getInstallInfo();
|
2024-11-25 09:51:45 +08:00
|
|
|
let siteInfo = {};
|
2024-11-26 01:21:49 +08:00
|
|
|
if (isComm()) {
|
2024-11-25 09:51:45 +08:00
|
|
|
siteInfo = await this.getSiteInfo();
|
|
|
|
|
}
|
2024-10-12 14:59:12 +08:00
|
|
|
const siteEnv = await this.getSiteEnv();
|
|
|
|
|
const plusInfo = await this.plusInfo();
|
2024-10-25 23:56:24 +08:00
|
|
|
const headerMenus = await this.getHeaderMenus();
|
2024-12-25 00:52:39 +08:00
|
|
|
const suiteSetting = await this.getSuiteSetting();
|
2024-10-05 01:46:25 +08:00
|
|
|
return this.ok({
|
2024-10-12 14:59:12 +08:00
|
|
|
sysPublic,
|
|
|
|
|
installInfo,
|
|
|
|
|
siteInfo,
|
|
|
|
|
siteEnv,
|
|
|
|
|
plusInfo,
|
2024-10-25 23:56:24 +08:00
|
|
|
headerMenus,
|
2024-12-25 00:52:39 +08:00
|
|
|
suiteSetting,
|
2024-10-05 01:46:25 +08:00
|
|
|
});
|
|
|
|
|
}
|
2024-06-16 00:20:02 +08:00
|
|
|
}
|