first commit

This commit is contained in:
raiper34
2024-06-22 17:06:41 +02:00
commit da9cf53c69
53 changed files with 20449 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import {Body, Controller, Delete, Get, Param, Post, Put, Res, StreamableFile} from '@nestjs/common';
import {TrackService} from "./track.service";
import {TrackModel} from "./track.model";
import {TrackEntity} from "./track.entity";
import {createReadStream} from "fs";
import { join } from 'path';
import type { Response } from 'express';
@Controller('track')
export class TrackController {
constructor(private readonly service: TrackService) {
}
@Get()
getAll(): Promise<TrackModel[]> {
return this.service.findAll();
}
@Get(':id')
get(@Param('id') id: number): Promise<TrackModel> {
return this.service.findOne(id);
}
@Post()
create(@Body() track: TrackModel): Promise<TrackModel> {
return this.service.create(track as TrackEntity);
}
@Put(':id')
update(@Param('id') id: number, @Body() track: TrackModel): Promise<void> {
return this.service.update(id, track as TrackEntity);
}
@Delete(':id')
delete(@Param('id') id: number): Promise<void> {
return this.service.remove(id);
}
@Get('download/:id')
async getFile(@Res({ passthrough: true }) res: Response, @Param('id') id: number): Promise<StreamableFile> {
const track = await this.service.findOne(id);
const file = createReadStream(join(process.cwd(), 'downloads', `${track.artist} - ${track.song}.mp3`));
res.set({'Content-Disposition': `attachment; filename="${track.artist} - ${track.song}.mp3"`,});
return new StreamableFile(file);
}
}