Loading backend/src/pointOfInterest/PointOfInterest.controller.ts +14 −6 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query, StreamableFile, } from '@nestjs/common'; import { PointOfInterestService } from './PointOfInterest.service'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; Loading Loading @@ -36,10 +46,8 @@ export class PointOfInterestController { @ApiQuery({ name: 'lang', type: String }) @Get('point/:idPoint/audio') async getAudio( @Param('idPoint') idPoint: number, @Query('lang') lang: string, ): Promise<Promise<NodeJS.ReadableStream>> { return this.activityService.getAudio(idPoint, lang as LANGUAGES); async getAudio(@Param('idPoint') idPoint: number, @Query('lang') lang: string): Promise<StreamableFile> { const file = await this.activityService.getAudio(idPoint, lang as LANGUAGES); return file; } } backend/src/pointOfInterest/PointOfInterest.service.ts +12 −5 Original line number Diff line number Diff line import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; import { BadRequestException, Injectable, NotFoundException, StreamableFile } from '@nestjs/common'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; import { PointOfInterest } from './entities/PointOfInterest.entity'; Loading @@ -11,6 +11,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { getPointDto } from './dto/getPoint.dto'; import { ServerConstants } from 'src/constants/server.contants'; import { createReadStream } from 'fs'; import { join } from 'path'; @Injectable() export class PointOfInterestService { Loading Loading @@ -87,12 +88,18 @@ export class PointOfInterestService { return points; } async getAudio(idPoint: number, lang: LANGUAGES): Promise<NodeJS.ReadableStream> { const pointTrad = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang }); async getAudio(idPoint: number, lang: LANGUAGES): Promise<StreamableFile> { const pointTrad: PointOfInterestTraduction = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang, }); if (!pointTrad) { throw new NotFoundException('Point not found'); } const filePath = `${ServerConstants.HOST}/audios/${pointTrad.audioName}`; return createReadStream(filePath); const filePath = join(ServerConstants.ROOT_STATIC_PATH, 'audios', pointTrad.audioName); const fileStream = createReadStream(filePath); return new StreamableFile(fileStream); } async createAudio() {} } Loading
backend/src/pointOfInterest/PointOfInterest.controller.ts +14 −6 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query, StreamableFile, } from '@nestjs/common'; import { PointOfInterestService } from './PointOfInterest.service'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; Loading Loading @@ -36,10 +46,8 @@ export class PointOfInterestController { @ApiQuery({ name: 'lang', type: String }) @Get('point/:idPoint/audio') async getAudio( @Param('idPoint') idPoint: number, @Query('lang') lang: string, ): Promise<Promise<NodeJS.ReadableStream>> { return this.activityService.getAudio(idPoint, lang as LANGUAGES); async getAudio(@Param('idPoint') idPoint: number, @Query('lang') lang: string): Promise<StreamableFile> { const file = await this.activityService.getAudio(idPoint, lang as LANGUAGES); return file; } }
backend/src/pointOfInterest/PointOfInterest.service.ts +12 −5 Original line number Diff line number Diff line import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; import { BadRequestException, Injectable, NotFoundException, StreamableFile } from '@nestjs/common'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; import { PointOfInterest } from './entities/PointOfInterest.entity'; Loading @@ -11,6 +11,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { getPointDto } from './dto/getPoint.dto'; import { ServerConstants } from 'src/constants/server.contants'; import { createReadStream } from 'fs'; import { join } from 'path'; @Injectable() export class PointOfInterestService { Loading Loading @@ -87,12 +88,18 @@ export class PointOfInterestService { return points; } async getAudio(idPoint: number, lang: LANGUAGES): Promise<NodeJS.ReadableStream> { const pointTrad = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang }); async getAudio(idPoint: number, lang: LANGUAGES): Promise<StreamableFile> { const pointTrad: PointOfInterestTraduction = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang, }); if (!pointTrad) { throw new NotFoundException('Point not found'); } const filePath = `${ServerConstants.HOST}/audios/${pointTrad.audioName}`; return createReadStream(filePath); const filePath = join(ServerConstants.ROOT_STATIC_PATH, 'audios', pointTrad.audioName); const fileStream = createReadStream(filePath); return new StreamableFile(fileStream); } async createAudio() {} }