feat: upload from url
This commit is contained in:
parent
ad7f7d9408
commit
599e895239
|
|
@ -26,6 +26,9 @@ import {
|
|||
} from '@gitroom/backend/services/auth/permissions/permission.exception.class';
|
||||
import { VideoDto } from '@gitroom/nestjs-libraries/dtos/videos/video.dto';
|
||||
import { VideoFunctionDto } from '@gitroom/nestjs-libraries/dtos/videos/video.function.dto';
|
||||
import { UploadDto } from '@gitroom/nestjs-libraries/dtos/media/upload.dto';
|
||||
import axios from 'axios';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
@ApiTags('Public API')
|
||||
@Controller('/public/v1')
|
||||
|
|
@ -56,6 +59,37 @@ export class PublicIntegrationsController {
|
|||
);
|
||||
}
|
||||
|
||||
@Post('/upload-from-url')
|
||||
async uploadFromUrl(
|
||||
@GetOrgFromRequest() org: Organization,
|
||||
@Body() body: UploadDto
|
||||
) {
|
||||
const response = await axios.get(body.url, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
const buffer = Buffer.from(response.data);
|
||||
|
||||
const getFile = await this.storage.uploadFile({
|
||||
buffer,
|
||||
mimetype: 'image/jpeg',
|
||||
size: buffer.length,
|
||||
path: '',
|
||||
fieldname: '',
|
||||
destination: '',
|
||||
stream: new Readable(),
|
||||
filename: '',
|
||||
originalname: '',
|
||||
encoding: '',
|
||||
});
|
||||
|
||||
return this._mediaService.saveFile(
|
||||
org.id,
|
||||
getFile.originalname,
|
||||
getFile.path
|
||||
);
|
||||
}
|
||||
|
||||
@Get('/find-slot/:id')
|
||||
async findSlotIntegration(
|
||||
@GetOrgFromRequest() org: Organization,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import { IsDefined, IsString, Validate } from 'class-validator';
|
||||
import { ValidUrlExtension } from '@gitroom/helpers/utils/valid.url.path';
|
||||
|
||||
export class UploadDto {
|
||||
@IsString()
|
||||
@IsDefined()
|
||||
@Validate(ValidUrlExtension)
|
||||
url: string;
|
||||
}
|
||||
Loading…
Reference in New Issue