55 HttpStatus ,
66 Param ,
77 Post ,
8- Query ,
98 Req ,
109 Res ,
1110 UploadedFiles ,
@@ -15,20 +14,21 @@ import { FilesInterceptor } from '@nestjs/platform-express';
1514import { AttachmentsService } from 'omniboxd/attachments/attachments.service' ;
1615import { Request , Response } from 'express' ;
1716import { UserId } from 'omniboxd/decorators/user-id.decorator' ;
18- import { CookieAuth } from 'omniboxd/auth' ;
17+ import { UploadAttachmentsResponseDto } from './dto/upload-attachments-response.dto' ;
18+ import { CookieAuth } from 'omniboxd/auth/decorators' ;
1919
20- @Controller ( 'api/v1/attachments' )
20+ @Controller ( 'api/v1/namespaces/:namespaceId/resources/:resourceId/ attachments' )
2121export class AttachmentsController {
2222 constructor ( private readonly attachmentsService : AttachmentsService ) { }
2323
2424 @Post ( )
2525 @UseInterceptors ( FilesInterceptor ( 'file[]' ) )
2626 async uploadAttachments (
2727 @UserId ( ) userId : string ,
28+ @Param ( 'namespaceId' ) namespaceId : string ,
29+ @Param ( 'resourceId' ) resourceId : string ,
2830 @UploadedFiles ( ) files : Express . Multer . File [ ] ,
29- @Query ( 'namespaceId' ) namespaceId : string ,
30- @Query ( 'resourceId' ) resourceId : string ,
31- ) {
31+ ) : Promise < UploadAttachmentsResponseDto > {
3232 return await this . attachmentsService . uploadAttachments (
3333 namespaceId ,
3434 resourceId ,
@@ -38,13 +38,19 @@ export class AttachmentsController {
3838 }
3939
4040 @Get ( ':attachmentId' )
41+ @CookieAuth ( { onAuthFail : 'continue' } )
4142 async downloadAttachment (
42- @UserId ( ) userId : string ,
43- @Res ( ) res : Response ,
44- @Query ( 'namespaceId' ) namespaceId : string ,
45- @Query ( 'resourceId' ) resourceId : string ,
43+ @Req ( ) req : Request ,
44+ @UserId ( { optional : true } ) userId : string | undefined ,
45+ @Param ( 'namespaceId' ) namespaceId : string ,
46+ @Param ( 'resourceId' ) resourceId : string ,
4647 @Param ( 'attachmentId' ) attachmentId : string ,
48+ @Res ( ) res : Response ,
4749 ) {
50+ if ( ! userId ) {
51+ this . setRedirect ( req , res ) ;
52+ return ;
53+ }
4854 return await this . attachmentsService . downloadAttachment (
4955 namespaceId ,
5056 resourceId ,
@@ -61,47 +67,11 @@ export class AttachmentsController {
6167 . redirect ( `/user/login?redirect=${ encodeURIComponent ( req . url ) } ` ) ;
6268 }
6369
64- @CookieAuth ( { onAuthFail : 'continue' } )
65- @Get ( 'images/:attachmentId' )
66- async displayImage (
67- @UserId ( { optional : true } ) userId : string | undefined ,
68- @Req ( ) req : Request ,
69- @Res ( ) res : Response ,
70- @Param ( 'attachmentId' ) attachmentId : string ,
71- ) {
72- if ( userId ) {
73- return await this . attachmentsService . displayMedia (
74- attachmentId ,
75- userId ,
76- res ,
77- ) ;
78- }
79- this . setRedirect ( req , res ) ;
80- }
81-
82- @CookieAuth ( { onAuthFail : 'continue' } )
83- @Get ( 'media/:attachmentId' )
84- async displayMedia (
85- @UserId ( { optional : true } ) userId : string | undefined ,
86- @Req ( ) req : Request ,
87- @Res ( ) res : Response ,
88- @Param ( 'attachmentId' ) attachmentId : string ,
89- ) {
90- if ( userId ) {
91- return await this . attachmentsService . displayMedia (
92- attachmentId ,
93- userId ,
94- res ,
95- ) ;
96- }
97- this . setRedirect ( req , res ) ;
98- }
99-
10070 @Delete ( ':attachmentId' )
10171 async deleteAttachment (
10272 @UserId ( ) userId : string ,
103- @Query ( 'namespaceId' ) namespaceId : string ,
104- @Query ( 'resourceId' ) resourceId : string ,
73+ @Param ( 'namespaceId' ) namespaceId : string ,
74+ @Param ( 'resourceId' ) resourceId : string ,
10575 @Param ( 'attachmentId' ) attachmentId : string ,
10676 ) {
10777 return await this . attachmentsService . deleteAttachment (
0 commit comments