Files
certd/packages/ui/certd-server/src/controller/basic/settings-controller.ts
T

111 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-04-27 22:51:47 +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,
2025-04-27 22:51:47 +08:00
SysSuiteSetting
} from "@certd/lib-server";
import { AppKey, getPlusInfo, isComm } from "@certd/plus-core";
import { cloneDeep } from "lodash-es";
import { getVersion } from "../../utils/version.js";
import { http } from "@certd/basic";
/**
*/
@Provide()
2025-04-27 22:51:47 +08:00
@Controller("/api/basic/settings")
export class BasicSettingsController extends BaseController {
@Inject()
sysSettingsService: SysSettingsService;
2025-04-27 22:51:47 +08:00
@Config("account.server.baseUrl")
2024-09-24 02:42:08 +08:00
accountServerBaseUrl: any;
2025-04-27 22:51:47 +08:00
@Config("agent")
agentConfig: SysSiteEnv["agent"];
2024-10-10 18:38:22 +08:00
public async getSysPublic() {
2024-10-12 14:59:12 +08:00
return await this.sysSettingsService.getSetting(SysPublicSettings);
}
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 {
2025-04-27 22:51:47 +08:00
enabled: setting.enabled
2024-12-25 00:52:39 +08:00
};
}
2024-10-10 18:38:22 +08:00
public async getSiteEnv() {
const env: SysSiteEnv = {
2025-04-27 22:51:47 +08:00
agent: this.agentConfig
2024-10-10 18:38:22 +08:00
};
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
}
2025-04-27 22:51:47 +08:00
@Get("/productInfo", { summary: Constants.per.guest })
async getProductInfo() {
const info = await http.request({
url: "https://app.handfree.work/certd/info.json"
});
return this.ok(info);
}
@Get("/all", { summary: Constants.per.guest })
2024-10-12 14:59:12 +08:00
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();
2025-04-27 22:51:47 +08:00
const version = await getVersion();
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,
2025-04-27 22:51:47 +08:00
app: {
2025-03-24 18:39:22 +08:00
time: new Date().getTime(),
2025-04-27 22:51:47 +08:00
version
},
2024-10-05 01:46:25 +08:00
});
}
}