@@ -26,6 +26,9 @@ import {
26
26
} from '@gitroom/backend/services/auth/permissions/permission.exception.class' ;
27
27
import { VideoDto } from '@gitroom/nestjs-libraries/dtos/videos/video.dto' ;
28
28
import { VideoFunctionDto } from '@gitroom/nestjs-libraries/dtos/videos/video.function.dto' ;
29
+ import { UploadDto } from '@gitroom/nestjs-libraries/dtos/media/upload.dto' ;
30
+ import axios from 'axios' ;
31
+ import { Readable } from 'stream' ;
29
32
30
33
@ApiTags ( 'Public API' )
31
34
@Controller ( '/public/v1' )
@@ -56,6 +59,37 @@ export class PublicIntegrationsController {
56
59
) ;
57
60
}
58
61
62
+ @Post ( '/upload-from-url' )
63
+ async uploadFromUrl (
64
+ @GetOrgFromRequest ( ) org : Organization ,
65
+ @Body ( ) body : UploadDto
66
+ ) {
67
+ const response = await axios . get ( body . url , {
68
+ responseType : 'arraybuffer' ,
69
+ } ) ;
70
+
71
+ const buffer = Buffer . from ( response . data ) ;
72
+
73
+ const getFile = await this . storage . uploadFile ( {
74
+ buffer,
75
+ mimetype : 'image/jpeg' ,
76
+ size : buffer . length ,
77
+ path : '' ,
78
+ fieldname : '' ,
79
+ destination : '' ,
80
+ stream : new Readable ( ) ,
81
+ filename : '' ,
82
+ originalname : '' ,
83
+ encoding : '' ,
84
+ } ) ;
85
+
86
+ return this . _mediaService . saveFile (
87
+ org . id ,
88
+ getFile . originalname ,
89
+ getFile . path
90
+ ) ;
91
+ }
92
+
59
93
@Get ( '/find-slot/:id' )
60
94
async findSlotIntegration (
61
95
@GetOrgFromRequest ( ) org : Organization ,
0 commit comments