mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
chore: 目录调整,controller转移到外部单独的目录
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { ALL, Inject } from '@midwayjs/core';
|
||||
import { Body } from '@midwayjs/core';
|
||||
import { Controller, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { CodeService } from '../../modules/basic/service/code-service.js';
|
||||
import { EmailService } from '../../modules/basic/service/email-service.js';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.number().required())
|
||||
phoneCode: number;
|
||||
|
||||
@Rule(RuleType.string().required())
|
||||
mobile: string;
|
||||
|
||||
@Rule(RuleType.string().required().max(10))
|
||||
randomStr: string;
|
||||
|
||||
@Rule(RuleType.number().required().max(4))
|
||||
imgCode: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/code')
|
||||
export class BasicController extends BaseController {
|
||||
@Inject()
|
||||
codeService: CodeService;
|
||||
|
||||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
@Post('/sendSmsCode', { summary: Constants.per.guest })
|
||||
public sendSmsCode(
|
||||
@Body(ALL)
|
||||
body: SmsCodeReq
|
||||
) {
|
||||
// 设置缓存内容
|
||||
return this.ok(null);
|
||||
}
|
||||
|
||||
@Post('/captcha', { summary: Constants.per.guest })
|
||||
public async getCaptcha(
|
||||
@Body()
|
||||
randomStr
|
||||
) {
|
||||
console.assert(randomStr < 10, 'randomStr 过长');
|
||||
const captcha = await this.codeService.generateCaptcha(randomStr);
|
||||
return this.ok(captcha.data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { EmailService } from '../../modules/basic/service/email-service.js';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/email')
|
||||
export class EmailController extends BaseController {
|
||||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
@Post('/test', { summary: Constants.per.authOnly })
|
||||
public async test(
|
||||
@Body('receiver')
|
||||
receiver
|
||||
) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.test(userId, receiver);
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Controller, Fields, Files, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { BaseController, Constants, FileService, UploadFileItem, uploadTmpFileCacheKey } from '@certd/lib-server';
|
||||
import send from 'koa-send';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { cache } from '@certd/pipeline';
|
||||
import { UploadFileInfo } from '@midwayjs/upload';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/file')
|
||||
export class FileController extends BaseController {
|
||||
@Inject()
|
||||
fileService: FileService;
|
||||
|
||||
@Post('/upload', { summary: Constants.per.authOnly })
|
||||
async upload(@Files() files: UploadFileInfo<string>[], @Fields() fields: any) {
|
||||
console.log('files', files, fields);
|
||||
const cacheKey = uploadTmpFileCacheKey + nanoid();
|
||||
const file = files[0];
|
||||
cache.set(
|
||||
cacheKey,
|
||||
{
|
||||
filename: file.filename,
|
||||
tmpFilePath: file.data,
|
||||
} as UploadFileItem,
|
||||
{
|
||||
ttl: 1000 * 60 * 60,
|
||||
}
|
||||
);
|
||||
return this.ok({
|
||||
key: cacheKey,
|
||||
});
|
||||
}
|
||||
|
||||
@Get('/download', { summary: Constants.per.guest })
|
||||
async download(@Query('key') key: string) {
|
||||
let userId: any = null;
|
||||
if (!key.startsWith('/public')) {
|
||||
userId = this.getUserId();
|
||||
}
|
||||
const filePath = this.fileService.getFile(key, userId);
|
||||
this.ctx.response.attachment(filePath);
|
||||
await send(this.ctx, filePath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { MidwayEnvironmentService } from '@midwayjs/core';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
|
||||
import { logger } from '@certd/pipeline';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
|
||||
@Provide()
|
||||
@Controller('/home')
|
||||
export class HomeController {
|
||||
@Inject()
|
||||
environmentService: MidwayEnvironmentService;
|
||||
@Get('/', { summary: Constants.per.guest })
|
||||
async home(): Promise<string> {
|
||||
logger.info('当前环境:', this.environmentService.getCurrentEnvironment()); // prod
|
||||
return 'Hello Midwayjs!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Config, Controller, Get, Inject, Provide } from '@midwayjs/core';
|
||||
import { BaseController, Constants, SysInstallInfo, SysPublicSettings, SysSettingsService, SysSiteEnv, SysSiteInfo } from '@certd/lib-server';
|
||||
import { AppKey, getPlusInfo } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/settings')
|
||||
export class BasicSettingsController extends BaseController {
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
@Config('account.server.baseUrl')
|
||||
accountServerBaseUrl: any;
|
||||
|
||||
@Config('agent')
|
||||
agentConfig: SysSiteEnv['agent'];
|
||||
|
||||
public async getSysPublic() {
|
||||
return await this.sysSettingsService.getSetting(SysPublicSettings);
|
||||
}
|
||||
|
||||
public async getInstallInfo() {
|
||||
const settings: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
settings.accountServerBaseUrl = this.accountServerBaseUrl;
|
||||
settings.appKey = AppKey;
|
||||
return settings;
|
||||
}
|
||||
|
||||
public async getSiteInfo() {
|
||||
return await this.sysSettingsService.getSetting(SysSiteInfo);
|
||||
}
|
||||
|
||||
public async getSiteEnv() {
|
||||
const env: SysSiteEnv = {
|
||||
agent: this.agentConfig,
|
||||
};
|
||||
return env;
|
||||
}
|
||||
|
||||
async plusInfo() {
|
||||
return getPlusInfo();
|
||||
}
|
||||
|
||||
@Get('/all', { summary: Constants.per.guest })
|
||||
async getAllSettings() {
|
||||
const sysPublic = await this.getSysPublic();
|
||||
const installInfo = await this.getInstallInfo();
|
||||
const siteInfo = await this.getSiteInfo();
|
||||
const siteEnv = await this.getSiteEnv();
|
||||
const plusInfo = await this.plusInfo();
|
||||
return this.ok({
|
||||
sysPublic,
|
||||
installInfo,
|
||||
siteInfo,
|
||||
siteEnv,
|
||||
plusInfo,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user