Untitled
unknown
plain_text
2 years ago
2.5 kB
8
Indexable
@Post()
@UseInterceptors(
FileInterceptor('video', {
storage: diskStorage({
destination: './uploads/story',
filename: (req, file, cb) => {
const randomNameFile =
Date.now() + '-' + Math.round(Math.random() * 1e9);
const extensionFile = extname(file.originalname);
const fileName = `${randomNameFile}_${file.fieldname}${extensionFile}`;
cb(null, fileName);
},
})
})
)
createStory(
@Res() res: Response<any, Record<string, any>>,
@Body() dto: any,
@UploadedFile() video: Express.Multer.File
): Observable<Response<any, Record<string, any>>> {
try {
this.validateVideo(video);
const data: StoryDTO = {
uploadBy: dto.uploadBy,
category: dto.category,
title: dto.title,
description: dto.description,
personalNumber: dto.personalNumber,
unit: dto.unit,
video: video.filename,
path: `story/${video.filename.split('.').slice(0, -1).join('.')}/transcodeMP4.m3u8`
}
this.errorsValidation(StoryDTO, data, video);
// const result = await this.storyService.createStory(data);
// const basePath = `./uploads/story/${video.filename.split('.').slice(0, -1).join('.')}`;
// fs.mkdirSync(basePath, { recursive: true });
// fs.rename(video.path, `${basePath}/${video.filename}`, (err) => {
// if (err) {
// throw err;
// }
// });
const fileProcess: JobInterface = {
inputPath: `./uploads/story/${video.filename}`,
// inputPath: `./uploads/story/${video.filename.split('.').slice(0, -1).join('.')}/${video.filename}`,
// outputPath: basePath
outputPath: './uploads/story'
};
const x = this.videouploadQueue.add('transcode', fileProcess, { jobId: data.title });
return of(
res.status(201).send(
this.responseMessage('story', 'Create', 201, {
// result,
x
})
)
);
} catch (error) {
throw error;
}
}Editor is loading...