Commit 3842efdd authored by nanahira's avatar nanahira

readme

parent d57d031a
# App name # ygopro-deckform-filler
App description. 上传 YGOPro YDK 卡组文件,生成可打印的卡组登记表 PDF。
## Installation ## Installation
......
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
import { FileInterceptor } from '@nestjs/platform-express'; import { FileInterceptor } from '@nestjs/platform-express';
import { FileUploadDto } from './dto/file-upload.dto'; import { FileUploadDto } from './dto/file-upload.dto';
import YGOProDeck from 'ygopro-deck-encode'; import YGOProDeck from 'ygopro-deck-encode';
import { DataQuery } from 'nesties'; import { ApiError, BlankReturnMessageDto, DataQuery } from 'nesties';
import { FillOptionsDto } from './dto/fill-options.dto'; import { FillOptionsDto } from './dto/fill-options.dto';
@Controller() @Controller()
...@@ -34,11 +34,19 @@ export class AppController { ...@@ -34,11 +34,19 @@ export class AppController {
format: 'binary', format: 'binary',
}, },
}) })
@ApiError(400, '不是有效的 YDK 文件')
@ApiError(404, '有卡片数据未找到')
@ApiError(500, '服务器内部错误')
async fillDeckForm( async fillDeckForm(
@UploadedFile() file: Express.Multer.File, @UploadedFile() file: Express.Multer.File,
@DataQuery() dto: FillOptionsDto, @DataQuery() dto: FillOptionsDto,
) { ) {
const ydk = YGOProDeck.fromYdkString(file.buffer.toString('utf-8')); const ydk = new YGOProDeck();
try {
ydk.fromYdkString(file.buffer.toString('utf-8'));
} catch (e) {
throw new BlankReturnMessageDto(400, 'Invalid YDK file').toException();
}
return this.appService.fillDeckForm(ydk, dto); return this.appService.fillDeckForm(ydk, dto);
} }
} }
...@@ -4,6 +4,7 @@ export class FileUploadDto { ...@@ -4,6 +4,7 @@ export class FileUploadDto {
@ApiProperty({ @ApiProperty({
type: 'string', type: 'string',
format: 'binary', format: 'binary',
description: '上传的 YGOPro YDK 卡组文件',
}) })
file: string; file: string;
} }
import { IsDate, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { IsDateString, IsOptional, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import moment from 'moment';
export class FillOptionsDto { export class FillOptionsDto {
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiProperty({
description: '参赛者姓名',
})
name?: string; name?: string;
@IsDate() @IsDateString()
@IsOptional() @IsOptional()
date?: Date; @ApiProperty({
type: String,
format: 'date',
example: moment().format('YYYY-MM-DD'),
description: '参赛日期,格式为 YYYY-MM-DD 或者其他符合 ISO 8601 的日期格式',
})
date?: string;
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiProperty({
description: '比赛名称',
})
event?: string; event?: string;
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiProperty({
description: '座位号 / 姓氏首字母',
})
lastInitial?: string; lastInitial?: string;
} }
...@@ -13,8 +13,8 @@ async function bootstrap() { ...@@ -13,8 +13,8 @@ async function bootstrap() {
const config = app.get(ConfigService); const config = app.get(ConfigService);
if (!config.get('NO_OPENAPI')) { if (!config.get('NO_OPENAPI')) {
const documentConfig = new DocumentBuilder() const documentConfig = new DocumentBuilder()
.setTitle('app') .setTitle('ygopro-deckform-filler')
.setDescription('The app') .setDescription('上传 YGOPro YDK 卡组文件,生成可打印的卡组登记表 PDF。')
.setVersion('1.0') .setVersion('1.0')
.build(); .build();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment