Skip to content

Commit 599e895

Browse files
committed
feat: upload from url
1 parent ad7f7d9 commit 599e895

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

apps/backend/src/public-api/routes/v1/public.integrations.controller.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import {
2626
} from '@gitroom/backend/services/auth/permissions/permission.exception.class';
2727
import { VideoDto } from '@gitroom/nestjs-libraries/dtos/videos/video.dto';
2828
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';
2932

3033
@ApiTags('Public API')
3134
@Controller('/public/v1')
@@ -56,6 +59,37 @@ export class PublicIntegrationsController {
5659
);
5760
}
5861

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+
5993
@Get('/find-slot/:id')
6094
async findSlotIntegration(
6195
@GetOrgFromRequest() org: Organization,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { IsDefined, IsString, Validate } from 'class-validator';
2+
import { ValidUrlExtension } from '@gitroom/helpers/utils/valid.url.path';
3+
4+
export class UploadDto {
5+
@IsString()
6+
@IsDefined()
7+
@Validate(ValidUrlExtension)
8+
url: string;
9+
}

0 commit comments

Comments
 (0)