feat(wordcloud): WordCloudJob 模型/迁移 + 词云生成与轮询适配器
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiBearerAuth, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { CurrentUser, JwtPayload } from '../common/decorators/current-user.decorator';
|
||||
import { WordCloudService } from './wordcloud.service';
|
||||
|
||||
@ApiTags('词云')
|
||||
@ApiBearerAuth()
|
||||
@Controller('wordcloud')
|
||||
export class WordCloudController {
|
||||
constructor(private readonly wordCloudService: WordCloudService) {}
|
||||
|
||||
/** 创建词云任务:multipart(image) + form 字段 names/params */
|
||||
@Post('generate')
|
||||
@ApiOperation({ summary: '创建词云任务(底图 + 名单文本)' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('image'))
|
||||
async generate(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@UploadedFile() image: Express.Multer.File | undefined,
|
||||
@Body('names') names: string,
|
||||
@Body('params') params?: string,
|
||||
) {
|
||||
if (!image) {
|
||||
throw new HttpException('缺少底图', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const jobId = await this.wordCloudService.createGenerateJob(
|
||||
user.sub,
|
||||
{ buffer: image.buffer, originalname: image.originalname },
|
||||
names ?? '',
|
||||
params,
|
||||
);
|
||||
return { jobId };
|
||||
}
|
||||
|
||||
/** 轮询词云任务(仅本人) */
|
||||
@Get('jobs/:id')
|
||||
@ApiOperation({ summary: '轮询词云任务状态(仅本人)' })
|
||||
async job(@CurrentUser() user: JwtPayload, @Param('id') id: string) {
|
||||
return this.wordCloudService.getUserJob(user.sub, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user