19 changed files with 178 additions and 51 deletions
@ -0,0 +1,18 @@ |
|||
import { Test, TestingModule } from '@nestjs/testing'; |
|||
import { RaceResultsController } from './race-results.controller'; |
|||
|
|||
describe('RaceResultsController', () => { |
|||
let controller: RaceResultsController; |
|||
|
|||
beforeEach(async () => { |
|||
const module: TestingModule = await Test.createTestingModule({ |
|||
controllers: [RaceResultsController], |
|||
}).compile(); |
|||
|
|||
controller = module.get<RaceResultsController>(RaceResultsController); |
|||
}); |
|||
|
|||
it('should be defined', () => { |
|||
expect(controller).toBeDefined(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,35 @@ |
|||
import { Controller, Get, Header, Param, Res, StreamableFile } from '@nestjs/common'; |
|||
import { createReadStream } from 'fs'; |
|||
import { join } from 'path'; |
|||
import type { Response } from 'express'; |
|||
import { RaceResultsService } from './race-results.service'; |
|||
|
|||
@Controller('race-results') |
|||
export class RaceResultsController { |
|||
|
|||
constructor( |
|||
private raceResultsService: RaceResultsService |
|||
) |
|||
{} |
|||
|
|||
@Get(':id/ghost') |
|||
async getFile(@Param() params: any, @Res({ passthrough: true }) res: Response): Promise<StreamableFile> { |
|||
console.log(params); |
|||
let result = await this.raceResultsService.findOne(params.id); |
|||
|
|||
const file = createReadStream(join(process.cwd(), result.replayPath)); |
|||
res.set({ |
|||
'Content-Type': 'application/json', |
|||
'Content-Disposition': 'attachment; filename="'+result.replayPath+'.gbx"', |
|||
}); |
|||
return new StreamableFile(file); |
|||
} |
|||
|
|||
@Get(':id/get-ghost') |
|||
async getGhostFile(@Param() params: any, @Res() res: Response) { |
|||
console.log(params); |
|||
let result = await this.raceResultsService.findOne(params.id); |
|||
const file = createReadStream(join(process.cwd(), result.replayPath)); |
|||
file.pipe(res); |
|||
} |
|||
} |
|||
@ -1,3 +1,3 @@ |
|||
.img-thumbnail{ |
|||
width: 400px; |
|||
width: 300px; |
|||
} |
|||
Loading…
Reference in new issue