mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-09 04:47:41 +00:00
start with streamer
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Head, Param, Req, Res } from '@nestjs/common';
|
||||
import ApiResponse from '../Dto/api-response.dto';
|
||||
import { AllFilesService } from './all-files.service';
|
||||
import { TitleTypeEnum } from './Enum/title-type.enum';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
@Controller('api/all')
|
||||
export class AllFilesController {
|
||||
@@ -23,8 +24,13 @@ export class AllFilesController {
|
||||
}
|
||||
|
||||
@Get('play/:fileId')
|
||||
play(@Param('fileId') fileId: string) {
|
||||
return { will: 'return a playable stream of ' + fileId };
|
||||
@Head('play/:fileId')
|
||||
play(
|
||||
@Param('fileId') fileId: string,
|
||||
@Req() request: Request,
|
||||
@Res() response: Response,
|
||||
) {
|
||||
this.allFilesService.play(fileId, request, response);
|
||||
}
|
||||
|
||||
@Get(':titleId/:seasonId?')
|
||||
|
||||
@@ -5,9 +5,13 @@ import { KodiApiResponseFactory } from '../kodi-api-response.factory';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { TitleEntity } from './Entity/title.entity';
|
||||
import { FileEntity } from './Entity/file.entity';
|
||||
import { StreamerModule } from '../../Streamer/streamer.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([TitleEntity, FileEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([TitleEntity, FileEntity]),
|
||||
StreamerModule,
|
||||
],
|
||||
controllers: [AllFilesController],
|
||||
providers: [AllFilesService, KodiApiResponseFactory],
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import ApiResponse from '../Dto/api-response.dto';
|
||||
import { KodiApiResponseFactory } from '../kodi-api-response.factory';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -6,6 +6,8 @@ import { Repository } from 'typeorm';
|
||||
import { TitleEntity } from './Entity/title.entity';
|
||||
import { FileEntity } from './Entity/file.entity';
|
||||
import { TitleTypeEnum } from './Enum/title-type.enum';
|
||||
import { StreamerFacade } from '../../Streamer/streamer.facade';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class AllFilesService {
|
||||
@@ -15,6 +17,7 @@ export class AllFilesService {
|
||||
private titleRepository: Repository<TitleEntity>,
|
||||
@InjectRepository(FileEntity)
|
||||
private fileRepository: Repository<FileEntity>,
|
||||
private readonly streamerFacade: StreamerFacade,
|
||||
) {}
|
||||
|
||||
getMenu(): ApiResponse {
|
||||
@@ -125,4 +128,19 @@ export class AllFilesService {
|
||||
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
async play(
|
||||
fileId: string,
|
||||
request: Request,
|
||||
response: Response,
|
||||
): Promise<void> {
|
||||
const id = parseInt(fileId);
|
||||
const entity = await this.fileRepository.findOne({ where: { id: id } });
|
||||
|
||||
if (entity === null) {
|
||||
throw new NotFoundException('entity not found id: ' + fileId);
|
||||
}
|
||||
|
||||
this.streamerFacade.streamFile(request, response, entity.path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user