| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2024-06-17 19:19:20 |
| 4 | * @LastEditTime: 2024-12-23 12:45:22 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: admin AI工具 |
| 7 | */ |
| 8 | import { Body, Controller, Get, Param, Post } from '@nestjs/common'; |
| 9 | import { ParamsValidationPipe } from 'src/validation.pipe'; |
| 10 | import { AiToolsService } from './ai.service'; |
| 11 | import { Manager } from 'src/auth/manager.guard'; |
| 12 | import { |
| 13 | AdminAiIdDto, |
| 14 | AdminAiMarkdownDto, |
| 15 | AdminFireflycardDto, |
| 16 | AdminJmTaskDto, |
| 17 | } from './dto/aiAdmin.dto'; |
| 18 | import { OssService } from 'src/lib/oss/oss.service'; |
| 19 | @Manager() |
| 20 | @Controller('admin/tools/ai') |
| 21 | export class AiToolsAdminController { |
| 22 | constructor( |
| 23 | private readonly aiToolsService: AiToolsService, |
| 24 | private readonly ossService: OssService, |
| 25 | ) {} |
| 26 | |
| 27 | @Post('fireflycard') |
| 28 | async fireflycard( |
| 29 | @Body(new ParamsValidationPipe()) body: AdminFireflycardDto, |
| 30 | ) { |
| 31 | // 二进制文件流 |
| 32 | const res = await this.aiToolsService.fireflycard( |
| 33 | body.content, |
| 34 | body.temp, |
| 35 | body.title, |
| 36 | ); |
| 37 | |
| 38 | const fileRes = await this.ossService.uploadByStream(res, { |
| 39 | path: 'fireflycard', |
| 40 | fileType: 'png', |
| 41 | }); |
| 42 | |
| 43 | return fileRes; |
| 44 | } |
| 45 | |
| 46 | @Post('markdown') |
| 47 | async aiMarkdown(@Body(new ParamsValidationPipe()) body: AdminAiMarkdownDto) { |
| 48 | const res = await this.aiToolsService.aiMarkdown(body); |
| 49 | return res; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * 获取AI的mk结果 |
| 54 | * @param id |
| 55 | * @returns |
| 56 | */ |
| 57 | @Get('markdown/:id') |
| 58 | async getAiMarkdown(@Param(new ParamsValidationPipe()) param: AdminAiIdDto) { |
| 59 | const res = await this.aiToolsService.getAiMarkdown(param.id); |
| 60 | return res; |
| 61 | } |
| 62 | |
| 63 | @Post('jm/task') |
| 64 | async upJmImgTask(@Body(new ParamsValidationPipe()) body: AdminJmTaskDto) { |
| 65 | const res = await this.aiToolsService.upJmImgTask(body); |
| 66 | |
| 67 | return res; |
| 68 | } |
| 69 | |
| 70 | @Get('jm/task/:id') |
| 71 | async getJmImgTaskRes(@Param('id') id: string) { |
| 72 | const res = await this.aiToolsService.getJmImgTaskRes(id); |
| 73 | return res; |
| 74 | } |
| 75 | } |
| 76 |