File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,10 +7,12 @@ import {
77 Patch ,
88 Post ,
99 Query ,
10+ Res ,
1011 UploadedFile ,
1112 UseGuards ,
1213 UseInterceptors ,
1314} from '@nestjs/common' ;
15+ import type { Response } from 'express' ;
1416import { FileInterceptor } from '@nestjs/platform-express' ;
1517import { Role } from '@prisma/client' ;
1618import { CurrentUser } from '../auth/decorators/current-user.decorator' ;
@@ -116,7 +118,13 @@ export class LifelinersController {
116118 @Get ( 'private/verification-photo' )
117119 @UseGuards ( JwtAuthGuard , RolesGuard )
118120 @Roles ( Role . LIFELINER )
119- async getVerificationPhoto ( @CurrentUser ( ) user : AuthUser ) {
120- return this . lifelinersService . getVerificationPhotoUrl ( user . id ) ;
121+ async getVerificationPhoto (
122+ @CurrentUser ( ) user : AuthUser ,
123+ @Res ( { passthrough : true } ) res : Response ,
124+ ) {
125+ const { stream, contentType } =
126+ await this . lifelinersService . getVerificationPhoto ( user . id ) ;
127+ res . setHeader ( 'Content-Type' , contentType ) ;
128+ stream . pipe ( res ) ;
121129 }
122130}
Original file line number Diff line number Diff line change @@ -179,7 +179,10 @@ export class LifelinersService {
179179 } ) ;
180180 }
181181
182- async getVerificationPhotoUrl ( userId : string ) : Promise < { url : string } > {
182+ async getVerificationPhoto ( userId : string ) : Promise < {
183+ stream : NodeJS . ReadableStream ;
184+ contentType : string ;
185+ } > {
183186 const lifeliner = await this . prisma . lifeliner . findUnique ( {
184187 where : { user_id : userId } ,
185188 select : { private_picture : true } ,
@@ -188,8 +191,7 @@ export class LifelinersService {
188191 if ( ! lifeliner . private_picture )
189192 throw new NotFoundException ( 'No verification photo uploaded' ) ;
190193
191- const url = await this . storage . getSignedUrl ( lifeliner . private_picture ) ;
192- return { url } ;
194+ return this . storage . download ( lifeliner . private_picture ) ;
193195 }
194196
195197 private extractGcsPath ( url : string ) : string | null {
Original file line number Diff line number Diff line change @@ -51,4 +51,16 @@ export class StorageService {
5151 } ) ;
5252 return url ;
5353 }
54+
55+ async download ( filePath : string ) : Promise < {
56+ stream : NodeJS . ReadableStream ;
57+ contentType : string ;
58+ } > {
59+ const file = this . bucket . file ( this . prefix ( filePath ) ) ;
60+ const [ metadata ] = await file . getMetadata ( ) ;
61+ return {
62+ stream : file . createReadStream ( ) ,
63+ contentType : metadata . contentType ?? 'application/octet-stream' ,
64+ } ;
65+ }
5466}
You can’t perform that action at this time.
0 commit comments