Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/audio-file-uploader/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=3001
1 change: 1 addition & 0 deletions apps/audio-file-uploader/.env.e2e-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=8098
2 changes: 2 additions & 0 deletions apps/audio-file-uploader/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DATABASE=firestore
FILESERVER_PATH=/usr/share/public/musics
8 changes: 8 additions & 0 deletions apps/audio-file-uploader/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

describe('AppController', () => {
describe('getData', () => {
it('should return "Hello API"', () => {
expect(1).toEqual(1);
});
});
});
8 changes: 7 additions & 1 deletion apps/rpg-maestro-ui-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"sourceRoot": "apps/rpg-maestro-ui-e2e/src",
"implicitDependencies": ["rpg-maestro-ui"],
"// targets": "to see all targets run: nx show project rpg-maestro-ui-e2e --web",
"targets": {}
"targets": {
"e2e": {
"dependsOn": [
"rpg-maestro:build", "audio-file-uploader:build", "rpg-maestro-ui:build"
]
}
}
}
3 changes: 2 additions & 1 deletion apps/rpg-maestro-ui/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_RPG_MAESTRO_API_URL=http://localhost:3000
VITE_RPG_MAESTRO_API_URL=http://localhost:3000
VITE_AUDIO_FILE_UPLOADER_API_URL=http://localhost:3001/api
3 changes: 2 additions & 1 deletion apps/rpg-maestro-ui/.env.e2e-tests
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_RPG_MAESTRO_API_URL=http://localhost:8099
VITE_RPG_MAESTRO_API_URL=http://localhost:8099
VITE_AUDIO_FILE_UPLOADER_API_URL=http://localhost:8098/api
3 changes: 2 additions & 1 deletion apps/rpg-maestro-ui/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_RPG_MAESTRO_API_URL=https://fourgate.cloud/api
VITE_RPG_MAESTRO_API_URL=https://fourgate.cloud/api
VITE_AUDIO_FILE_UPLOADER_API_URL=https://fourgate.cloud/audio-file-uploader/api
1 change: 1 addition & 0 deletions apps/rpg-maestro-ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"options": {
"commands": [
"PORT=8099 npx nx run rpg-maestro:dev --configuration=e2e-tests --no-cloud",
"PORT=8098 npx nx run audio-file-uploader:dev --configuration=e2e-tests --no-cloud",
"npx nx run rpg-maestro-ui:preview --configuration=e2e-tests --no-cloud"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { styled } from '@mui/material/styles';
import axios, { AxiosRequestConfig } from 'axios';

const rpgmaestroapiurl = import.meta.env.VITE_RPG_MAESTRO_API_URL; // TODO centralize
const audioFileUploaderAPI = import.meta.env.VITE_AUDIO_FILE_UPLOADER_API_URL;

const VisuallyHiddenInput = styled('input')({
clip: 'rect(0 0 0 0)',
Expand Down Expand Up @@ -45,7 +45,7 @@ export function FileUpload(props: FileUploadProps) {
};

axios
.post(`${rpgmaestroapiurl}/admin/tracks/upload`, formData, config)
.post(`${audioFileUploaderAPI}/upload/audio`, formData, config)
.then((response) => {
console.log(response.data);
const uploadRes = response.data as {fileURL: string};
Expand Down
1 change: 0 additions & 1 deletion apps/rpg-maestro/.env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DATABASE=firestore
FILESERVER_PATH=/usr/share/public/musics
16 changes: 2 additions & 14 deletions apps/rpg-maestro/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Inject, Param, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common';
import { Body, Controller, Get, Inject, Param, Post, Put } from '@nestjs/common';
import { TrackService } from './admin-api/TrackService';
import { Database } from './admin-api/Database';
import { ManageCurrentlyPlayingTracks } from './admin-api/ManageCurrentlyPlayingTracks';
Expand All @@ -13,10 +13,6 @@ import {
import { DEFAULT_CURRENT_SESSION_ID, FirestoreDatabase } from './infrastructure/FirestoreDatabase';
import * as process from 'node:process';
import { InMemoryDatabase } from './infrastructure/InMemoryDatabase';
import { FileInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
import 'multer';
import { FileUploadService } from './infrastructure/fileUpload/FileUploadService';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache, Milliseconds } from 'cache-manager';

Expand All @@ -29,10 +25,8 @@ export class AppController {
private readonly manageCurrentlyPlayingTracks: ManageCurrentlyPlayingTracks;

constructor(
private readonly fileUploadService: FileUploadService,
@Inject(CACHE_MANAGER) private cacheManager: Cache
) {
this.fileUploadService = fileUploadService;
const databaseImpl: string | undefined = process.env.DATABASE;
if (databaseImpl === 'firestore') {
console.log('using firestore as database');
Expand Down Expand Up @@ -68,12 +62,6 @@ export class AppController {
return this.trackService.getAll();
}

@Post('/admin/tracks/upload')
@UseInterceptors(FileInterceptor('file'))
uploadTrack(@UploadedFile() file: Express.Multer.File) {
return this.fileUploadService.handleFileUpload(file);
}

@Put('/admin/sessions/current/tracks')
async changeCurrentTrack(@Body() trackToPlay: TrackToPlay): Promise<PlayingTrack> {
const playingTrack = await this.manageCurrentlyPlayingTracks.changeCurrentTrack(trackToPlay);
Expand All @@ -86,7 +74,7 @@ export class AppController {
return this.trackService.get(id);
}

@Get ('/sessions/current/tracks')
@Get('/sessions/current/tracks')
async getCurrentTrack(): Promise<PlayingTrack> {
// TODO fix this hack forbidding having more than one instance
// this was done to avoid reaching Firestore quotas
Expand Down
15 changes: 1 addition & 14 deletions apps/rpg-maestro/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { FileUploadService } from './infrastructure/fileUpload/FileUploadService';
import * as process from 'node:process';
import { CacheModule } from '@nestjs/cache-manager';

@Module({
Expand All @@ -17,18 +13,9 @@ import { CacheModule } from '@nestjs/cache-manager';

serveStaticOptions: { redirect: false },
}),
MulterModule.register({
storage: diskStorage({
destination: `${process.env.FILESERVER_PATH ? process.env.FILESERVER_PATH : '.'}/uploads`,
filename: (req, file, cb) => {
const filename = `${file.originalname}`;
cb(null, filename);
},
}),
}),
CacheModule.register(),
],
controllers: [AppController],
providers: [FileUploadService],
providers: [],
})
export class AppModule {}
Loading