#1 - Created request to check newest version of the app
All checks were successful
Build / build (push) Successful in 2m35s
All checks were successful
Build / build (push) Successful in 2m35s
#2 - Added request to download the newest version of the app #3 - Added request to check progress during sync #4 - Now blocking all request while sync is in progress #5 - Implemented ants for thread pooling #6 - Changed the sync request to now only start the sync
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"music-server/internal/backend"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -16,6 +17,10 @@ func NewMusicHandler() *MusicHandler {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetSong(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
song := ctx.QueryParam("song")
|
||||
if song == "" {
|
||||
return ctx.String(http.StatusBadRequest, "song can't be empty")
|
||||
@@ -30,6 +35,10 @@ func (m *MusicHandler) GetSong(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetSoundCheckSong(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetSoundCheckSong()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -40,11 +49,19 @@ func (m *MusicHandler) GetSoundCheckSong(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) ResetMusic(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
backend.Reset()
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetRandomSong(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetRandomSong()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -55,6 +72,10 @@ func (m *MusicHandler) GetRandomSong(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetRandomSongLowChance(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetRandomSongLowChance()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -65,6 +86,10 @@ func (m *MusicHandler) GetRandomSongLowChance(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetRandomSongClassic(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetRandomSongClassic()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -85,6 +110,10 @@ func (m *MusicHandler) GetPlayedSongs(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetNextSong(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetNextSong()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -95,6 +124,10 @@ func (m *MusicHandler) GetNextSong(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetPreviousSong(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
songPath := backend.GetPreviousSong()
|
||||
file, err := os.Open(songPath)
|
||||
if err != nil {
|
||||
@@ -105,11 +138,19 @@ func (m *MusicHandler) GetPreviousSong(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetAllGames(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
gameList := backend.GetAllGames()
|
||||
return ctx.JSON(http.StatusOK, gameList)
|
||||
}
|
||||
|
||||
func (m *MusicHandler) GetAllGamesRandom(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
gameList := backend.GetAllGamesRandom()
|
||||
return ctx.JSON(http.StatusOK, gameList)
|
||||
}
|
||||
@@ -119,6 +160,10 @@ type played struct {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) PutPlayed(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
var played played
|
||||
err := ctx.Bind(&played)
|
||||
if err != nil {
|
||||
@@ -129,11 +174,19 @@ func (m *MusicHandler) PutPlayed(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (m *MusicHandler) AddLatestToQue(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
backend.AddLatestToQue()
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (m *MusicHandler) AddLatestPlayed(ctx echo.Context) error {
|
||||
if backend.Syncing {
|
||||
log.Println("Syncing is in progress")
|
||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||
}
|
||||
backend.AddLatestPlayed()
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user