building dist and environment paths rework
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
DB_PATH=./config/db.sqlite
|
||||
FE_PATH=../frontend/browser
|
||||
DOWNLOADS_PATH=./downloads
|
||||
FORMAT=mp3
|
||||
@@ -45,6 +45,7 @@ lerna-debug.log*
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
config
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --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",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
|
||||
@@ -9,6 +9,7 @@ import {TrackModule} from "./track/track.module";
|
||||
import {PlaylistModule} from "./playlist/playlist.module";
|
||||
import {PlaylistEntity} from "./playlist/playlist.entity";
|
||||
import { resolve } from 'path';
|
||||
import {EnviromentEnum} from "./enviroment.enum";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -18,7 +19,7 @@ import { resolve } from 'path';
|
||||
imports:[ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => ({
|
||||
type: 'sqlite',
|
||||
database: configService.get<string>('DB'),
|
||||
database: resolve(__dirname, configService.get<string>(EnviromentEnum.DB_PATH)),
|
||||
entities: [TrackEntity, PlaylistEntity],
|
||||
synchronize: true,
|
||||
}),
|
||||
@@ -27,7 +28,7 @@ import { resolve } from 'path';
|
||||
ServeStaticModule.forRootAsync({
|
||||
imports:[ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => ([{
|
||||
rootPath: resolve(__dirname, configService.get<string>('FE')),
|
||||
rootPath: resolve(__dirname, configService.get<string>(EnviromentEnum.FE_PATH)),
|
||||
exclude: ['/api/(.*)'],
|
||||
}]),
|
||||
inject: [ConfigService]
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export enum EnviromentEnum {
|
||||
DB_PATH = 'DB_PATH',
|
||||
FE_PATH = 'FE_PATH',
|
||||
DOWNLOADS_PATH = 'DOWNLOADS_PATH',
|
||||
FORMAT = 'FORMAT',
|
||||
}
|
||||
@@ -9,5 +9,5 @@ async function bootstrap() {
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
const folderName = resolve(__dirname, process.env.DOWNLOADS);
|
||||
const folderName = resolve(__dirname, process.env.DOWNLOADS_PATH);
|
||||
!fs.existsSync(folderName) && fs.mkdirSync(folderName);
|
||||
|
||||
@@ -5,6 +5,7 @@ import {createReadStream} from "fs";
|
||||
import { resolve } from 'path';
|
||||
import type { Response } from 'express';
|
||||
import {ConfigService} from "@nestjs/config";
|
||||
import {EnviromentEnum} from "../enviroment.enum";
|
||||
|
||||
@Controller('track')
|
||||
export class TrackController {
|
||||
@@ -26,8 +27,8 @@ export class TrackController {
|
||||
@Get('download/:id')
|
||||
async getFile(@Res({ passthrough: true }) res: Response, @Param('id') id: number): Promise<StreamableFile> {
|
||||
const track = await this.service.findOne(id);
|
||||
const fileName = `${track.artist} - ${track.song}.${this.configService.get<string>('FORMAT')}`;
|
||||
const filePath = createReadStream(resolve(__dirname, '..', this.configService.get<string>('DOWNLOADS'), fileName));
|
||||
const fileName = `${track.artist} - ${track.song}.${this.configService.get<string>(EnviromentEnum.FORMAT)}`;
|
||||
const filePath = createReadStream(resolve(__dirname, '..', this.configService.get<string>(EnviromentEnum.DOWNLOADS_PATH), fileName));
|
||||
res.set({'Content-Disposition': `attachment; filename="${fileName}`});
|
||||
return new StreamableFile(filePath);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import {resolve} from "path";
|
||||
import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets";
|
||||
import {Server} from "socket.io";
|
||||
import * as ffmpeg from 'fluent-ffmpeg';
|
||||
import {EnviromentEnum} from "../enviroment.enum";
|
||||
|
||||
@WebSocketGateway()
|
||||
@Injectable()
|
||||
@@ -108,13 +109,13 @@ export class TrackService {
|
||||
.on('error', (err) => reject(err));
|
||||
ffmpeg(audio)
|
||||
.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))
|
||||
.pipe(
|
||||
fs.createWriteStream(
|
||||
resolve(
|
||||
__dirname, '..', this.configService.get<string>('DOWNLOADS'),
|
||||
`${track.artist} - ${track.song.replace('/', '')}.${this.configService.get<string>('FORMAT')}`
|
||||
__dirname, '..', this.configService.get<string>(EnviromentEnum.DOWNLOADS_PATH),
|
||||
`${track.artist} - ${track.song.replace('/', '')}.${this.configService.get<string>(EnviromentEnum.FORMAT)}`
|
||||
)
|
||||
).on('finish', () => res()).on('error', (err) => reject(err))
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"outDir": "../../dist/backend",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "dist/spooty-fe",
|
||||
"outputPath": "../../dist/frontend",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": [
|
||||
|
||||
Reference in New Issue
Block a user