This commit is contained in:
神仙都没用 2025-02-12 22:33:35 +08:00
parent 3299b02362
commit a66e7e176f
2 changed files with 26 additions and 15 deletions

View File

@ -1,4 +1,9 @@
import { CoolController, BaseController, CoolTag, TagTypes } from '@cool-midway/core';
import {
CoolController,
BaseController,
CoolTag,
TagTypes,
} from '@cool-midway/core';
import { Body, Get, Inject, Post } from '@midwayjs/core';
import { BaseCodingService } from '../../service/coding';
@ -16,10 +21,14 @@ export class AdminCodingController extends BaseController {
}
@Post('/createCode', { summary: '创建代码' })
async createCode(@Body() codes: {
path: string;
content: string;
}[]) {
return this.baseCodingService.createCode(codes);
async createCode(
@Body('codes')
codes: {
path: string;
content: string;
}[]
) {
this.baseCodingService.createCode(codes);
return this.ok();
}
}

View File

@ -62,15 +62,17 @@ export class BaseCodingService extends BaseService {
*
* @param codes
*/
async createCode(codes: {
path: string;
content: string;
}[]) {
async createCode(
codes: {
path: string;
content: string;
}[]
) {
if (this.app.getEnv() !== 'local') {
throw new Error('只能在开发环境下创建代码');
}
const moduleDir = await this.app.getBaseDir();
const moduleDir = this.app.getAppDir();
for (const code of codes) {
// 格式化代码内容