11import {
2- Body , Controller , Get , Param , Post , Query , Req , Res , UploadedFile , UseInterceptors , UsePipes
2+ Body ,
3+ Controller ,
4+ Get ,
5+ Param ,
6+ Post ,
7+ Query ,
8+ Req ,
9+ Res ,
10+ UploadedFile ,
11+ UseInterceptors ,
12+ UsePipes ,
313} from '@nestjs/common' ;
414import { Request , Response } from 'express' ;
515import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request' ;
@@ -25,14 +35,35 @@ export class MediaController {
2535 async generateImage (
2636 @GetOrgFromRequest ( ) org : Organization ,
2737 @Req ( ) req : Request ,
28- @Body ( 'prompt' ) prompt : string
38+ @Body ( 'prompt' ) prompt : string ,
39+ isPicturePrompt = false
2940 ) {
3041 const total = await this . _subscriptionService . checkCredits ( org ) ;
3142 if ( total . credits <= 0 ) {
3243 return false ;
3344 }
3445
35- return { output : 'data:image/png;base64,' + await this . _mediaService . generateImage ( prompt , org ) } ;
46+ return {
47+ output :
48+ ( isPicturePrompt ? '' : 'data:image/png;base64,' ) +
49+ ( await this . _mediaService . generateImage ( prompt , org , isPicturePrompt ) ) ,
50+ } ;
51+ }
52+
53+ @Post ( '/generate-image-with-prompt' )
54+ async generateImageFromText (
55+ @GetOrgFromRequest ( ) org : Organization ,
56+ @Req ( ) req : Request ,
57+ @Body ( 'prompt' ) prompt : string
58+ ) {
59+ const image = await this . generateImage ( org , req , prompt , true ) ;
60+ if ( ! image ) {
61+ return false ;
62+ }
63+
64+ const file = await this . storage . uploadSimple ( image . output ) ;
65+
66+ return this . _mediaService . saveFile ( org . id , file . split ( '/' ) . pop ( ) , file ) ;
3667 }
3768
3869 @Post ( '/upload-server' )
@@ -43,7 +74,11 @@ export class MediaController {
4374 @UploadedFile ( ) file : Express . Multer . File
4475 ) {
4576 const uploadedFile = await this . storage . uploadFile ( file ) ;
46- return this . _mediaService . saveFile ( org . id , uploadedFile . originalname , uploadedFile . path ) ;
77+ return this . _mediaService . saveFile (
78+ org . id ,
79+ uploadedFile . originalname ,
80+ uploadedFile . path
81+ ) ;
4782 }
4883
4984 @Post ( '/upload-simple' )
@@ -53,7 +88,11 @@ export class MediaController {
5388 @UploadedFile ( 'file' ) file : Express . Multer . File
5489 ) {
5590 const getFile = await this . storage . uploadFile ( file ) ;
56- return this . _mediaService . saveFile ( org . id , getFile . originalname , getFile . path ) ;
91+ return this . _mediaService . saveFile (
92+ org . id ,
93+ getFile . originalname ,
94+ getFile . path
95+ ) ;
5796 }
5897
5998 @Post ( '/:endpoint' )
@@ -75,10 +114,14 @@ export class MediaController {
75114 // @ts -ignore
76115 const name = upload . Location . split ( '/' ) . pop ( ) ;
77116
78- // @ts -ignore
79- const saveFile = await this . _mediaService . saveFile ( org . id , name , upload . Location ) ;
117+ const saveFile = await this . _mediaService . saveFile (
118+ org . id ,
119+ name ,
120+ // @ts -ignore
121+ upload . Location
122+ ) ;
80123
81- res . status ( 200 ) . json ( { ...upload , saved : saveFile } ) ;
124+ res . status ( 200 ) . json ( { ...upload , saved : saveFile } ) ;
82125 // const filePath =
83126 // file.path.indexOf('http') === 0
84127 // ? file.path
0 commit comments