|
1 |
| -import { Controller, Post, Req, Res, HttpException, HttpStatus } from '@nestjs/common'; |
2 |
| -import { HostService } from './host.service.js'; |
| 1 | +import { Controller, Post, Req, Res, HttpException, HttpStatus, Body } from '@nestjs/common'; |
| 2 | +import { keyGenerateRequestDto, HostService } from './host.service.js'; |
3 | 3 | import { Request, Response } from 'express';
|
| 4 | +import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; |
4 | 5 |
|
5 | 6 | @Controller('host')
|
| 7 | +@ApiTags('Host API') |
6 | 8 | export class HostController {
|
7 | 9 | constructor(private readonly hostService: HostService) {}
|
8 | 10 |
|
9 |
| - @Post('/') |
10 |
| - async generateStreamKey(@Req() req: Request, @Res() res: Response) { |
| 11 | + @Post('/key') |
| 12 | + @ApiOperation({ summary: 'Host Stream, Session Key Generate API', description: 'Host용 스트림키와 세션키를 생성합니다.' }) |
| 13 | + @ApiCreatedResponse({ description: '스트림키, 세션키를 생성한다.', type: Array<string> }) |
| 14 | + async generateStreamKey(@Body() requestDto: keyGenerateRequestDto, @Req() req: Request, @Res() res: Response) { |
11 | 15 | try {
|
12 | 16 | const host = req.headers['host'] as string;
|
13 | 17 | const contentType = req.headers['content-type'];
|
14 |
| - const { uuid } = req.body; |
15 | 18 |
|
16 |
| - if (!host || !contentType || !uuid) { |
| 19 | + if (!host || !contentType || !requestDto.uuid) { |
17 | 20 | throw new HttpException('Bad Request', HttpStatus.BAD_REQUEST);
|
18 | 21 | }
|
19 | 22 | if (contentType !== 'application/json') {
|
20 | 23 | throw new HttpException('Content-Type must be application/json', HttpStatus.BAD_REQUEST);
|
21 | 24 | }
|
22 | 25 |
|
23 |
| - const [streamKey, sessionKey] = await this.hostService.generateStreamKey(uuid); |
| 26 | + const [streamKey, sessionKey] = await this.hostService.generateStreamKey(requestDto); |
24 | 27 | res.status(HttpStatus.OK).json({ 'stream-key': streamKey, 'session-key':sessionKey });
|
25 | 28 | } catch (error) {
|
26 | 29 | if ((error as { status: number }).status === 400) {
|
|
0 commit comments