mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-24 14:47:56 +00:00
feat: generate upload signed url for oci
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
import { Body, Controller, Post, UploadedFile, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||
import { memoryStorage } from 'multer';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { AuthenticatedUser } from '~/common/decorators';
|
||||
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiLangRequestHeader } from '~/core/decorators';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { UploadDocumentRequestDto } from '../dtos/request';
|
||||
import { DocumentMetaResponseDto } from '../dtos/response';
|
||||
import { DocumentType } from '../enums';
|
||||
import { GenerateUploadSignedUrlRequestDto } from '../dtos/request';
|
||||
import { DocumentService } from '../services';
|
||||
@Controller('document')
|
||||
@ApiTags('Document')
|
||||
@@ -19,34 +13,9 @@ import { DocumentService } from '../services';
|
||||
export class DocumentController {
|
||||
constructor(private readonly documentService: DocumentService) {}
|
||||
|
||||
@Post()
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
document: {
|
||||
type: 'string',
|
||||
format: 'binary',
|
||||
},
|
||||
documentType: {
|
||||
type: 'string',
|
||||
enum: Object.values(DocumentType).filter(
|
||||
(value) => ![DocumentType.DEFAULT_AVATAR, DocumentType.DEFAULT_TASKS_LOGO].includes(value),
|
||||
),
|
||||
},
|
||||
},
|
||||
required: ['document', 'documentType'],
|
||||
},
|
||||
})
|
||||
@UseInterceptors(FileInterceptor('document', { storage: memoryStorage() }))
|
||||
async createDocument(
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Body() uploadedDocumentRequest: UploadDocumentRequestDto,
|
||||
@AuthenticatedUser() user: IJwtPayload,
|
||||
) {
|
||||
const document = await this.documentService.createDocument(file, uploadedDocumentRequest, user.sub);
|
||||
|
||||
return ResponseFactory.data(new DocumentMetaResponseDto(document));
|
||||
@Post('signed-url')
|
||||
async generateSignedUrl(@Body() body: GenerateUploadSignedUrlRequestDto) {
|
||||
const signedUrl = await this.documentService.generateUploadSignedUrl(body);
|
||||
return ResponseFactory.data(signedUrl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user