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

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-12-09 00:12:15 +08:00
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
import { BaseController, Constants, FileService, SysSettingsService, SysSiteInfo } from '@certd/lib-server';
2024-11-04 16:39:02 +08:00
import { http, logger } from '@certd/basic';
2024-12-09 00:12:15 +08:00
import { isComm } from '@certd/plus-core';
2024-11-01 00:59:09 +08:00
/**
*/
@Provide()
@Controller('/api/app/')
export class AppController extends BaseController {
2024-12-09 00:12:15 +08:00
@Inject()
sysSettingsService: SysSettingsService;
@Inject()
fileService: FileService;
2024-11-01 00:59:09 +08:00
@Get('/latest', { summary: Constants.per.authOnly })
async latest(): Promise<any> {
try {
2025-01-22 15:35:28 +08:00
const res = await http.request({
url: 'https://registry.npmmirror.com/@certd/pipeline',
method: 'get',
logRes: false,
timeout: 5000,
});
2024-11-01 00:59:09 +08:00
const latest = res['dist-tags'].latest;
return this.ok(latest);
} catch (e: any) {
logger.error(e);
return this.ok('');
}
}
2024-12-09 00:12:15 +08:00
@Get('/favicon', { summary: Constants.per.guest })
public async getFavicon() {
if (isComm()) {
const siteInfo = await this.sysSettingsService.getSetting<SysSiteInfo>(SysSiteInfo);
const favicon = siteInfo.logo;
if (favicon) {
const redirect = '/api/basic/file/download?key=' + favicon;
this.ctx.response.redirect(redirect);
this.ctx.response.set('Cache-Control', 'public,max-age=25920');
return;
}
}
const redirect = '/static/images/logo/logo.svg';
this.ctx.response.redirect(redirect);
this.ctx.response.set('Cache-Control', 'public,max-age=25920');
}
2024-11-01 00:59:09 +08:00
}