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

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-05-31 01:41:33 +08:00
import { Body, Controller, Get, Inject, Post, Provide } from "@midwayjs/core";
import { BaseController, Constants, FileService, SysSettingsService, SysSiteInfo } from "@certd/lib-server";
import { http, logger } from "@certd/basic";
import { isComm } from "@certd/plus-core";
2024-12-09 00:12:15 +08:00
export function normalizeReleaseVersion(release: { tag_name?: string; name?: string }) {
2026-05-31 01:41:33 +08:00
const version = release?.tag_name || release?.name || "";
return version.replace(/^v/i, "");
}
2024-11-01 00:59:09 +08:00
/**
*/
@Provide()
2026-05-31 01:41:33 +08:00
@Controller("/api/app/")
2024-11-01 00:59:09 +08:00
export class AppController extends BaseController {
2024-12-09 00:12:15 +08:00
@Inject()
sysSettingsService: SysSettingsService;
@Inject()
fileService: FileService;
2026-05-31 01:41:33 +08:00
@Get("/latest", { description: Constants.per.authOnly })
2024-11-01 00:59:09 +08:00
async latest(): Promise<any> {
try {
2025-01-22 15:35:28 +08:00
const res = await http.request({
2026-05-31 01:41:33 +08:00
url: "https://api.atomgit.com/api/v5/repos/certd/certd/releases/latest",
method: "get",
2025-01-22 15:35:28 +08:00
logRes: false,
timeout: 5000,
});
const latest = normalizeReleaseVersion(res);
2024-11-01 00:59:09 +08:00
return this.ok(latest);
} catch (e: any) {
logger.error(e);
2026-05-31 01:41:33 +08:00
return this.ok("");
2024-11-01 00:59:09 +08:00
}
}
2024-12-09 00:12:15 +08:00
2026-05-31 01:41:33 +08:00
@Get("/favicon", { description: Constants.per.guest })
2024-12-09 00:12:15 +08:00
public async getFavicon() {
if (isComm()) {
const siteInfo = await this.sysSettingsService.getSetting<SysSiteInfo>(SysSiteInfo);
const favicon = siteInfo.logo;
if (favicon) {
2026-05-31 01:41:33 +08:00
const redirect = "/api/basic/file/download?key=" + favicon;
2024-12-09 00:12:15 +08:00
this.ctx.response.redirect(redirect);
2026-05-31 01:41:33 +08:00
this.ctx.response.set("Cache-Control", "public,max-age=25920");
2024-12-09 00:12:15 +08:00
return;
}
}
2026-05-31 01:41:33 +08:00
const redirect = "/static/images/logo/logo.svg";
2024-12-09 00:12:15 +08:00
this.ctx.response.redirect(redirect);
2026-05-31 01:41:33 +08:00
this.ctx.response.set("Cache-Control", "public,max-age=25920");
2024-12-09 00:12:15 +08:00
}
2025-08-07 11:26:14 +08:00
2026-05-31 01:41:33 +08:00
@Post("/webhook", { description: Constants.per.guest })
public async webhook(@Body() body: any) {
logger.info("webhook", JSON.stringify(body));
return this.ok("success");
2025-08-07 11:26:14 +08:00
}
2024-11-01 00:59:09 +08:00
}