Joey / src /controllers /article-controller.ts
yuanjiajun
feat: 情感文章添加风格和结局设定
ec10306
raw
history blame contribute delete
936 Bytes
import { Context } from 'koa';
import Router from 'koa-router';
import { handleControllerError } from '@/middleware';
import { processArticleServe, processArticleElementServe } from '@/service';
const router = new Router({ prefix: '/api' });
// 获取文章要素
router.get('/generate-article-element', async (ctx: Context) => {
try {
const result = await processArticleElementServe();
ctx.body = result;
} catch (error) {
// 将捕获到的异常传递给统一的错误处理中间件
await handleControllerError(ctx, error);
}
});
// 根据文案生成文章
router.post('/generate-article', async (ctx: Context) => {
const data = ctx.request.body as any;
try {
const result = await processArticleServe(data);
ctx.body = result;
} catch (error) {
// 将捕获到的异常传递给统一的错误处理中间件
await handleControllerError(ctx, error);
}
});
export default router;