building dist and environment paths rework

This commit is contained in:
raiper34
2024-07-21 14:24:36 +02:00
parent 7938e56dce
commit b77956e76c
13 changed files with 30 additions and 13 deletions
+1
View File
@@ -1,3 +1,4 @@
/node_modules /node_modules
/dist
/.idea /.idea
**/*.sqlite **/*.sqlite
+3 -1
View File
@@ -1,9 +1,11 @@
FROM node:18 FROM node:18
WORKDIR /usr/src/app WORKDIR /spooty
COPY . . COPY . .
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends ffmpeg
RUN npm install RUN npm install
RUN npm run build RUN npm run build
+1 -1
View File
@@ -6,7 +6,7 @@
"start:fe": "npm run start -w frontend", "start:fe": "npm run start -w frontend",
"build:be": "npm run build -w backend", "build:be": "npm run build -w backend",
"build:fe": "npm run build -w frontend", "build:fe": "npm run build -w frontend",
"build": "npm run build:be npm run build:fe", "build": "npm run build:be && npm run build:fe",
"gen:fe": "npm run gen -w frontend", "gen:fe": "npm run gen -w frontend",
"start": "npm run start:prod -w backend" "start": "npm run start:prod -w backend"
} }
+4
View File
@@ -0,0 +1,4 @@
DB_PATH=./config/db.sqlite
FE_PATH=../frontend/browser
DOWNLOADS_PATH=./downloads
FORMAT=mp3
+1
View File
@@ -45,6 +45,7 @@ lerna-debug.log*
# temp directory # temp directory
.temp .temp
.tmp .tmp
config
# Runtime data # Runtime data
pids pids
+1 -1
View File
@@ -11,7 +11,7 @@
"start": "nest start", "start": "nest start",
"start:dev": "nest start --watch", "start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch", "start:debug": "nest start --debug --watch",
"start:prod": "node dist/main", "start:prod": "node ../../dist/backend/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
+3 -2
View File
@@ -9,6 +9,7 @@ import {TrackModule} from "./track/track.module";
import {PlaylistModule} from "./playlist/playlist.module"; import {PlaylistModule} from "./playlist/playlist.module";
import {PlaylistEntity} from "./playlist/playlist.entity"; import {PlaylistEntity} from "./playlist/playlist.entity";
import { resolve } from 'path'; import { resolve } from 'path';
import {EnviromentEnum} from "./enviroment.enum";
@Module({ @Module({
imports: [ imports: [
@@ -18,7 +19,7 @@ import { resolve } from 'path';
imports:[ConfigModule], imports:[ConfigModule],
useFactory: async (configService: ConfigService) => ({ useFactory: async (configService: ConfigService) => ({
type: 'sqlite', type: 'sqlite',
database: configService.get<string>('DB'), database: resolve(__dirname, configService.get<string>(EnviromentEnum.DB_PATH)),
entities: [TrackEntity, PlaylistEntity], entities: [TrackEntity, PlaylistEntity],
synchronize: true, synchronize: true,
}), }),
@@ -27,7 +28,7 @@ import { resolve } from 'path';
ServeStaticModule.forRootAsync({ ServeStaticModule.forRootAsync({
imports:[ConfigModule], imports:[ConfigModule],
useFactory: async (configService: ConfigService) => ([{ useFactory: async (configService: ConfigService) => ([{
rootPath: resolve(__dirname, configService.get<string>('FE')), rootPath: resolve(__dirname, configService.get<string>(EnviromentEnum.FE_PATH)),
exclude: ['/api/(.*)'], exclude: ['/api/(.*)'],
}]), }]),
inject: [ConfigService] inject: [ConfigService]
+6
View File
@@ -0,0 +1,6 @@
export enum EnviromentEnum {
DB_PATH = 'DB_PATH',
FE_PATH = 'FE_PATH',
DOWNLOADS_PATH = 'DOWNLOADS_PATH',
FORMAT = 'FORMAT',
}
+1 -1
View File
@@ -9,5 +9,5 @@ async function bootstrap() {
await app.listen(3000); await app.listen(3000);
} }
bootstrap(); bootstrap();
const folderName = resolve(__dirname, process.env.DOWNLOADS); const folderName = resolve(__dirname, process.env.DOWNLOADS_PATH);
!fs.existsSync(folderName) && fs.mkdirSync(folderName); !fs.existsSync(folderName) && fs.mkdirSync(folderName);
+3 -2
View File
@@ -5,6 +5,7 @@ import {createReadStream} from "fs";
import { resolve } from 'path'; import { resolve } from 'path';
import type { Response } from 'express'; import type { Response } from 'express';
import {ConfigService} from "@nestjs/config"; import {ConfigService} from "@nestjs/config";
import {EnviromentEnum} from "../enviroment.enum";
@Controller('track') @Controller('track')
export class TrackController { export class TrackController {
@@ -26,8 +27,8 @@ export class TrackController {
@Get('download/:id') @Get('download/:id')
async getFile(@Res({ passthrough: true }) res: Response, @Param('id') id: number): Promise<StreamableFile> { async getFile(@Res({ passthrough: true }) res: Response, @Param('id') id: number): Promise<StreamableFile> {
const track = await this.service.findOne(id); const track = await this.service.findOne(id);
const fileName = `${track.artist} - ${track.song}.${this.configService.get<string>('FORMAT')}`; const fileName = `${track.artist} - ${track.song}.${this.configService.get<string>(EnviromentEnum.FORMAT)}`;
const filePath = createReadStream(resolve(__dirname, '..', this.configService.get<string>('DOWNLOADS'), fileName)); const filePath = createReadStream(resolve(__dirname, '..', this.configService.get<string>(EnviromentEnum.DOWNLOADS_PATH), fileName));
res.set({'Content-Disposition': `attachment; filename="${fileName}`}); res.set({'Content-Disposition': `attachment; filename="${fileName}`});
return new StreamableFile(filePath); return new StreamableFile(filePath);
} }
+4 -3
View File
@@ -14,6 +14,7 @@ import {resolve} from "path";
import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets"; import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets";
import {Server} from "socket.io"; import {Server} from "socket.io";
import * as ffmpeg from 'fluent-ffmpeg'; import * as ffmpeg from 'fluent-ffmpeg';
import {EnviromentEnum} from "../enviroment.enum";
@WebSocketGateway() @WebSocketGateway()
@Injectable() @Injectable()
@@ -108,13 +109,13 @@ export class TrackService {
.on('error', (err) => reject(err)); .on('error', (err) => reject(err));
ffmpeg(audio) ffmpeg(audio)
.outputOptions('-metadata', `title=${track.song}`, '-metadata', `artist=${track.artist}`) .outputOptions('-metadata', `title=${track.song}`, '-metadata', `artist=${track.artist}`)
.format(this.configService.get<string>('FORMAT')) .format(this.configService.get<string>(EnviromentEnum.FORMAT))
.on('error', (err) => reject(err)) .on('error', (err) => reject(err))
.pipe( .pipe(
fs.createWriteStream( fs.createWriteStream(
resolve( resolve(
__dirname, '..', this.configService.get<string>('DOWNLOADS'), __dirname, '..', this.configService.get<string>(EnviromentEnum.DOWNLOADS_PATH),
`${track.artist} - ${track.song.replace('/', '')}.${this.configService.get<string>('FORMAT')}` `${track.artist} - ${track.song.replace('/', '')}.${this.configService.get<string>(EnviromentEnum.FORMAT)}`
) )
).on('finish', () => res()).on('error', (err) => reject(err)) ).on('finish', () => res()).on('error', (err) => reject(err))
); );
+1 -1
View File
@@ -8,7 +8,7 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "../../dist/backend",
"baseUrl": "./", "baseUrl": "./",
"incremental": true, "incremental": true,
"skipLibCheck": true, "skipLibCheck": true,
+1 -1
View File
@@ -17,7 +17,7 @@
"build": { "build": {
"builder": "@angular-devkit/build-angular:application", "builder": "@angular-devkit/build-angular:application",
"options": { "options": {
"outputPath": "dist/spooty-fe", "outputPath": "../../dist/frontend",
"index": "src/index.html", "index": "src/index.html",
"browser": "src/main.ts", "browser": "src/main.ts",
"polyfills": [ "polyfills": [