Skip to content
Snippets Groups Projects
Commit 36a5ecb9 authored by Ronnie Friman's avatar Ronnie Friman
Browse files

create upload path

parent 770c82cc
No related branches found
No related tags found
3 merge requests!59Development to master,!58Development to testing,!56Cluster update to Development
...@@ -10,12 +10,16 @@ import { ...@@ -10,12 +10,16 @@ import {
UseInterceptors, UseInterceptors,
ClassSerializerInterceptor, ClassSerializerInterceptor,
Delete, Delete,
UploadedFile,
} from '@nestjs/common'; } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname } from 'path';
import { GameService } from './game.service'; import { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard'; import { AuthGuard } from '../shared/auth.guard';
import { User } from '../user/user.decorator'; import { User } from '../user/user.decorator';
import { GameDTO, FlagboxEventDTO, GameStateDTO } from './game.dto'; import { GameDTO, FlagboxEventDTO, GameStateDTO, newGameDTO } from './game.dto';
import { ValidationPipe } from '../shared/validation.pipe'; import { ValidationPipe } from '../shared/validation.pipe';
import { Roles, GameStates } from '../shared/guard.decorator'; import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity'; import { GameEntity } from './game.entity';
...@@ -36,7 +40,7 @@ export class GameController { ...@@ -36,7 +40,7 @@ export class GameController {
@Post('new') @Post('new')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
async newGame(@User('id') person, @Body() body: GameDTO) { async newGame(@User('id') person, @Body() body: newGameDTO) {
return this.gameservice.createNewGame(person, body); return this.gameservice.createNewGame(person, body);
} }
...@@ -101,4 +105,25 @@ export class GameController { ...@@ -101,4 +105,25 @@ export class GameController {
async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) { async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) {
return this.gameservice.flagboxEvent(id, data); return this.gameservice.flagboxEvent(id, data);
} }
@Post('upload')
@UseInterceptors(
FileInterceptor('image', {
storage: diskStorage({
destination: './images',
filename: (req, file, cb) => {
// Generating a 32 random chars long string
const randomName = Array(32)
.fill(null)
.map(() => Math.round(Math.random() * 16).toString(16))
.join('');
//Calling the callback passing the random name generated with the original extension name
cb(null, `${randomName}${extname(file.originalname)}`);
},
}),
}),
)
uploadImage(@UploadedFile() image) {
return image;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment