Upgrade Echo framework from v4 to v5
This commit is contained in:
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/a-h/templ v0.3.937
|
github.com/a-h/templ v0.3.937
|
||||||
github.com/golang-migrate/migrate/v4 v4.18.3
|
github.com/golang-migrate/migrate/v4 v4.18.3
|
||||||
github.com/jackc/pgx/v5 v5.7.5
|
github.com/jackc/pgx/v5 v5.7.5
|
||||||
github.com/labstack/echo/v4 v4.15.2
|
github.com/labstack/echo/v5 v5.1.1
|
||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
github.com/panjf2000/ants/v2 v2.11.3
|
github.com/panjf2000/ants/v2 v2.11.3
|
||||||
github.com/spf13/afero v1.14.0
|
github.com/spf13/afero v1.14.0
|
||||||
@@ -29,6 +29,7 @@ require (
|
|||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
|
github.com/labstack/echo/v4 v4.9.0 // indirect
|
||||||
github.com/labstack/gommon v0.5.0 // indirect
|
github.com/labstack/gommon v0.5.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/labstack/echo/v4 v4.15.2 h1:nnh2sCzGCVYnU+wCisMPiYapEg/QVo/gcI9ePKg5/T4=
|
github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
|
||||||
github.com/labstack/echo/v4 v4.15.2/go.mod h1:Xzp1Ns1RA2c9fY7nSgUJkpkUZGNbEIVHZbtbOMPktBI=
|
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
|
||||||
|
github.com/labstack/echo/v5 v5.1.1 h1:4QkvKoS8ps5ch49t8b72QS9Z581ytgxhTzxuB/CBA2I=
|
||||||
|
github.com/labstack/echo/v5 v5.1.1/go.mod h1:SyvlSdObGjRXeQfCCXW/sybkZdOOQZBmpKF0bvALaeo=
|
||||||
github.com/labstack/gommon v0.5.0 h1:6VSQ2NOzsnEJ5W6+84E0RbcaDDmgB6NIAzWCczTEe6c=
|
github.com/labstack/gommon v0.5.0 h1:6VSQ2NOzsnEJ5W6+84E0RbcaDDmgB6NIAzWCczTEe6c=
|
||||||
github.com/labstack/gommon v0.5.0/go.mod h1:Rzlg7HHy1maLfzBYGg9NZcVuz1sA68HHhLjhcEllYE0=
|
github.com/labstack/gommon v0.5.0/go.mod h1:Rzlg7HHy1maLfzBYGg9NZcVuz1sA68HHhLjhcEllYE0=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v5"
|
||||||
"log"
|
"log"
|
||||||
"music-server/internal/backend"
|
"music-server/internal/backend"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -22,7 +22,7 @@ func NewDownloadHandler() *DownloadHandler {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {string} string
|
// @Success 200 {string} string
|
||||||
// @Router /download [get]
|
// @Router /download [get]
|
||||||
func (d *DownloadHandler) checkLatest(ctx echo.Context) error {
|
func (d *DownloadHandler) checkLatest(ctx *echo.Context) error {
|
||||||
log.Println("Checking latest version")
|
log.Println("Checking latest version")
|
||||||
latest := backend.CheckLatest()
|
latest := backend.CheckLatest()
|
||||||
return ctx.JSON(http.StatusOK, latest)
|
return ctx.JSON(http.StatusOK, latest)
|
||||||
@@ -36,7 +36,7 @@ func (d *DownloadHandler) checkLatest(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} string
|
// @Success 200 {array} string
|
||||||
// @Router /download/list [get]
|
// @Router /download/list [get]
|
||||||
func (d *DownloadHandler) listAssetsOfLatest(ctx echo.Context) error {
|
func (d *DownloadHandler) listAssetsOfLatest(ctx *echo.Context) error {
|
||||||
log.Println("Listing assets")
|
log.Println("Listing assets")
|
||||||
assets := backend.ListAssetsOfLatest()
|
assets := backend.ListAssetsOfLatest()
|
||||||
return ctx.JSON(http.StatusOK, assets)
|
return ctx.JSON(http.StatusOK, assets)
|
||||||
@@ -49,7 +49,7 @@ func (d *DownloadHandler) listAssetsOfLatest(ctx echo.Context) error {
|
|||||||
// @Produce octet-stream
|
// @Produce octet-stream
|
||||||
// @Success 302 {string} string
|
// @Success 302 {string} string
|
||||||
// @Router /download/windows [get]
|
// @Router /download/windows [get]
|
||||||
func (d *DownloadHandler) downloadLatestWindows(ctx echo.Context) error {
|
func (d *DownloadHandler) downloadLatestWindows(ctx *echo.Context) error {
|
||||||
log.Println("Downloading latest windows")
|
log.Println("Downloading latest windows")
|
||||||
asset := backend.DownloadLatestWindows()
|
asset := backend.DownloadLatestWindows()
|
||||||
ctx.Response().Header().Set("Content-Type", "application/octet-stream")
|
ctx.Response().Header().Set("Content-Type", "application/octet-stream")
|
||||||
@@ -63,7 +63,7 @@ func (d *DownloadHandler) downloadLatestWindows(ctx echo.Context) error {
|
|||||||
// @Produce octet-stream
|
// @Produce octet-stream
|
||||||
// @Success 302 {string} string
|
// @Success 302 {string} string
|
||||||
// @Router /download/linux [get]
|
// @Router /download/linux [get]
|
||||||
func (d *DownloadHandler) downloadLatestLinux(ctx echo.Context) error {
|
func (d *DownloadHandler) downloadLatestLinux(ctx *echo.Context) error {
|
||||||
log.Println("Downloading latest linux")
|
log.Println("Downloading latest linux")
|
||||||
asset := backend.DownloadLatestLinux()
|
asset := backend.DownloadLatestLinux()
|
||||||
ctx.Response().Header().Set("Content-Type", "application/octet-stream")
|
ctx.Response().Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"music-server/internal/db"
|
"music-server/internal/db"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexHandler struct {
|
type IndexHandler struct {
|
||||||
@@ -25,7 +25,7 @@ func NewIndexHandler() *IndexHandler {
|
|||||||
// @Success 200 {object} backend.VersionData
|
// @Success 200 {object} backend.VersionData
|
||||||
// @Failure 404 {object} string
|
// @Failure 404 {object} string
|
||||||
// @Router /version [get]
|
// @Router /version [get]
|
||||||
func (i *IndexHandler) GetVersion(ctx echo.Context) error {
|
func (i *IndexHandler) GetVersion(ctx *echo.Context) error {
|
||||||
versionHistory := backend.GetVersionHistory()
|
versionHistory := backend.GetVersionHistory()
|
||||||
if versionHistory.Version == "" {
|
if versionHistory.Version == "" {
|
||||||
return ctx.JSON(http.StatusNotFound, "version not found")
|
return ctx.JSON(http.StatusNotFound, "version not found")
|
||||||
@@ -41,7 +41,7 @@ func (i *IndexHandler) GetVersion(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {string} string "TestedDB"
|
// @Success 200 {string} string "TestedDB"
|
||||||
// @Router /dbtest [get]
|
// @Router /dbtest [get]
|
||||||
func (i *IndexHandler) GetDBTest(ctx echo.Context) error {
|
func (i *IndexHandler) GetDBTest(ctx *echo.Context) error {
|
||||||
backend.TestDB()
|
backend.TestDB()
|
||||||
return ctx.JSON(http.StatusOK, "TestedDB")
|
return ctx.JSON(http.StatusOK, "TestedDB")
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ func (i *IndexHandler) GetDBTest(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {string} string "OK"
|
// @Success 200 {string} string "OK"
|
||||||
// @Router /health [get]
|
// @Router /health [get]
|
||||||
func (i *IndexHandler) HealthCheck(ctx echo.Context) error {
|
func (i *IndexHandler) HealthCheck(ctx *echo.Context) error {
|
||||||
return ctx.JSON(http.StatusOK, db.Health())
|
return ctx.JSON(http.StatusOK, db.Health())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ func (i *IndexHandler) HealthCheck(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} string
|
// @Success 200 {array} string
|
||||||
// @Router /characters [get]
|
// @Router /characters [get]
|
||||||
func (i *IndexHandler) GetCharacterList(ctx echo.Context) error {
|
func (i *IndexHandler) GetCharacterList(ctx *echo.Context) error {
|
||||||
characters := backend.GetCharacterList()
|
characters := backend.GetCharacterList()
|
||||||
return ctx.JSON(http.StatusOK, characters)
|
return ctx.JSON(http.StatusOK, characters)
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ func (i *IndexHandler) GetCharacterList(ctx echo.Context) error {
|
|||||||
// @Param name query string true "Character name"
|
// @Param name query string true "Character name"
|
||||||
// @Success 200 {file} file
|
// @Success 200 {file} file
|
||||||
// @Router /character [get]
|
// @Router /character [get]
|
||||||
func (i *IndexHandler) GetCharacter(ctx echo.Context) error {
|
func (i *IndexHandler) GetCharacter(ctx *echo.Context) error {
|
||||||
character := ctx.QueryParam("name")
|
character := ctx.QueryParam("name")
|
||||||
return ctx.File(backend.GetCharacter(character))
|
return ctx.File(backend.GetCharacter(character))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MusicHandler struct {
|
type MusicHandler struct {
|
||||||
@@ -29,7 +29,7 @@ func NewMusicHandler() *MusicHandler {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music [get]
|
// @Router /music [get]
|
||||||
func (m *MusicHandler) GetSong(ctx echo.Context) error {
|
func (m *MusicHandler) GetSong(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -41,7 +41,7 @@ func (m *MusicHandler) GetSong(ctx echo.Context) error {
|
|||||||
songPath := backend.GetSong(song)
|
songPath := backend.GetSong(song)
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -56,7 +56,7 @@ func (m *MusicHandler) GetSong(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/soundTest [get]
|
// @Router /music/soundTest [get]
|
||||||
func (m *MusicHandler) GetSoundCheckSong(ctx echo.Context) error {
|
func (m *MusicHandler) GetSoundCheckSong(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -64,7 +64,7 @@ func (m *MusicHandler) GetSoundCheckSong(ctx echo.Context) error {
|
|||||||
songPath := backend.GetSoundCheckSong()
|
songPath := backend.GetSoundCheckSong()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -78,7 +78,7 @@ func (m *MusicHandler) GetSoundCheckSong(ctx echo.Context) error {
|
|||||||
// @Success 204
|
// @Success 204
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/reset [get]
|
// @Router /music/reset [get]
|
||||||
func (m *MusicHandler) ResetMusic(ctx echo.Context) error {
|
func (m *MusicHandler) ResetMusic(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -96,7 +96,7 @@ func (m *MusicHandler) ResetMusic(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/rand [get]
|
// @Router /music/rand [get]
|
||||||
func (m *MusicHandler) GetRandomSong(ctx echo.Context) error {
|
func (m *MusicHandler) GetRandomSong(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -104,7 +104,7 @@ func (m *MusicHandler) GetRandomSong(ctx echo.Context) error {
|
|||||||
songPath := backend.GetRandomSong()
|
songPath := backend.GetRandomSong()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -119,7 +119,7 @@ func (m *MusicHandler) GetRandomSong(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/rand/low [get]
|
// @Router /music/rand/low [get]
|
||||||
func (m *MusicHandler) GetRandomSongLowChance(ctx echo.Context) error {
|
func (m *MusicHandler) GetRandomSongLowChance(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -127,7 +127,7 @@ func (m *MusicHandler) GetRandomSongLowChance(ctx echo.Context) error {
|
|||||||
songPath := backend.GetRandomSongLowChance()
|
songPath := backend.GetRandomSongLowChance()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -142,7 +142,7 @@ func (m *MusicHandler) GetRandomSongLowChance(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/rand/classic [get]
|
// @Router /music/rand/classic [get]
|
||||||
func (m *MusicHandler) GetRandomSongClassic(ctx echo.Context) error {
|
func (m *MusicHandler) GetRandomSongClassic(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -150,7 +150,7 @@ func (m *MusicHandler) GetRandomSongClassic(ctx echo.Context) error {
|
|||||||
songPath := backend.GetRandomSongClassic()
|
songPath := backend.GetRandomSongClassic()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -164,7 +164,7 @@ func (m *MusicHandler) GetRandomSongClassic(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} map[string]interface{}
|
// @Success 200 {object} map[string]interface{}
|
||||||
// @Router /music/info [get]
|
// @Router /music/info [get]
|
||||||
func (m *MusicHandler) GetSongInfo(ctx echo.Context) error {
|
func (m *MusicHandler) GetSongInfo(ctx *echo.Context) error {
|
||||||
song := backend.GetSongInfo()
|
song := backend.GetSongInfo()
|
||||||
return ctx.JSON(http.StatusOK, song)
|
return ctx.JSON(http.StatusOK, song)
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ func (m *MusicHandler) GetSongInfo(ctx echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} map[string]interface{}
|
// @Success 200 {array} map[string]interface{}
|
||||||
// @Router /music/list [get]
|
// @Router /music/list [get]
|
||||||
func (m *MusicHandler) GetPlayedSongs(ctx echo.Context) error {
|
func (m *MusicHandler) GetPlayedSongs(ctx *echo.Context) error {
|
||||||
songList := backend.GetPlayedSongs()
|
songList := backend.GetPlayedSongs()
|
||||||
return ctx.JSON(http.StatusOK, songList)
|
return ctx.JSON(http.StatusOK, songList)
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ func (m *MusicHandler) GetPlayedSongs(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/next [get]
|
// @Router /music/next [get]
|
||||||
func (m *MusicHandler) GetNextSong(ctx echo.Context) error {
|
func (m *MusicHandler) GetNextSong(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -199,7 +199,7 @@ func (m *MusicHandler) GetNextSong(ctx echo.Context) error {
|
|||||||
songPath := backend.GetNextSong()
|
songPath := backend.GetNextSong()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -214,7 +214,7 @@ func (m *MusicHandler) GetNextSong(ctx echo.Context) error {
|
|||||||
// @Failure 404 {string} string "Not Found"
|
// @Failure 404 {string} string "Not Found"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/previous [get]
|
// @Router /music/previous [get]
|
||||||
func (m *MusicHandler) GetPreviousSong(ctx echo.Context) error {
|
func (m *MusicHandler) GetPreviousSong(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -222,7 +222,7 @@ func (m *MusicHandler) GetPreviousSong(ctx echo.Context) error {
|
|||||||
songPath := backend.GetPreviousSong()
|
songPath := backend.GetPreviousSong()
|
||||||
file, err := os.Open(songPath)
|
file, err := os.Open(songPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
return ctx.Stream(http.StatusOK, "audio/mpeg", file)
|
||||||
@@ -237,7 +237,7 @@ func (m *MusicHandler) GetPreviousSong(ctx echo.Context) error {
|
|||||||
// @Success 200 {array} map[string]interface{}
|
// @Success 200 {array} map[string]interface{}
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/all/order [get]
|
// @Router /music/all/order [get]
|
||||||
func (m *MusicHandler) GetAllGames(ctx echo.Context) error {
|
func (m *MusicHandler) GetAllGames(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -255,7 +255,7 @@ func (m *MusicHandler) GetAllGames(ctx echo.Context) error {
|
|||||||
// @Success 200 {array} map[string]interface{}
|
// @Success 200 {array} map[string]interface{}
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/all/random [get]
|
// @Router /music/all/random [get]
|
||||||
func (m *MusicHandler) GetAllGamesRandom(ctx echo.Context) error {
|
func (m *MusicHandler) GetAllGamesRandom(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -275,14 +275,14 @@ func (m *MusicHandler) GetAllGamesRandom(ctx echo.Context) error {
|
|||||||
// @Failure 400 {string} string "Bad Request"
|
// @Failure 400 {string} string "Bad Request"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/played [put]
|
// @Router /music/played [put]
|
||||||
func (m *MusicHandler) PutPlayed(ctx echo.Context) error {
|
func (m *MusicHandler) PutPlayed(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
}
|
}
|
||||||
song, err := strconv.Atoi(ctx.QueryParam("song"))
|
song, err := strconv.Atoi(ctx.QueryParam("song"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.JSON(http.StatusBadRequest, err)
|
return ctx.JSON(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
log.Println("song", song)
|
log.Println("song", song)
|
||||||
backend.SetPlayed(song)
|
backend.SetPlayed(song)
|
||||||
@@ -297,7 +297,7 @@ func (m *MusicHandler) PutPlayed(ctx echo.Context) error {
|
|||||||
// @Success 204
|
// @Success 204
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/addQue [get]
|
// @Router /music/addQue [get]
|
||||||
func (m *MusicHandler) AddLatestToQue(ctx echo.Context) error {
|
func (m *MusicHandler) AddLatestToQue(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -314,7 +314,7 @@ func (m *MusicHandler) AddLatestToQue(ctx echo.Context) error {
|
|||||||
// @Success 204
|
// @Success 204
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /music/addPlayed [get]
|
// @Router /music/addPlayed [get]
|
||||||
func (m *MusicHandler) AddLatestPlayed(ctx echo.Context) error {
|
func (m *MusicHandler) AddLatestPlayed(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v5"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v5/middleware"
|
||||||
"github.com/swaggo/echo-swagger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Title MusicServer API
|
// @Title MusicServer API
|
||||||
@@ -34,7 +33,7 @@ func (s *Server) RegisterRoutes() http.Handler {
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
http.ServeFile(w, r, "cmd/docs/swagger.json")
|
http.ServeFile(w, r, "cmd/docs/swagger.json")
|
||||||
})))
|
})))
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.RequestLogger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||||
@@ -53,8 +52,8 @@ func (s *Server) RegisterRoutes() http.Handler {
|
|||||||
|
|
||||||
e.Static("/", "/frontend")
|
e.Static("/", "/frontend")
|
||||||
|
|
||||||
// Swagger UI
|
// Swagger UI - TODO: Update for Echo v5
|
||||||
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
// e.GET("/swagger/*", echoSwagger.WrapHandler)
|
||||||
|
|
||||||
index := NewIndexHandler()
|
index := NewIndexHandler()
|
||||||
e.GET("/version", index.GetVersion)
|
e.GET("/version", index.GetVersion)
|
||||||
@@ -98,13 +97,13 @@ func (s *Server) RegisterRoutes() http.Handler {
|
|||||||
musicGroup.GET("/addQue", music.AddLatestToQue)
|
musicGroup.GET("/addQue", music.AddLatestToQue)
|
||||||
musicGroup.GET("/addPlayed", music.AddLatestPlayed)
|
musicGroup.GET("/addPlayed", music.AddLatestPlayed)
|
||||||
|
|
||||||
routes := e.Routes()
|
routes := e.Router().Routes()
|
||||||
sort.Slice(routes, func(i, j int) bool {
|
sort.Slice(routes, func(i, j int) bool {
|
||||||
return routes[i].Path < routes[j].Path
|
return routes[i].Path < routes[j].Path
|
||||||
})
|
})
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
if (r.Method == "GET" || r.Method == "POST" || r.Method == "PUT" || r.Method == "DELETE") && !strings.Contains(r.Name, "github") {
|
if (r.Method == "GET" || r.Method == "POST" || r.Method == "PUT" || r.Method == "DELETE") && !strings.Contains(r.Name, "github") {
|
||||||
fmt.Printf(" %s %s\n", r.Method, r.Path)
|
fmt.Printf(" %s\t\t%s\n", r.Method, r.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return e
|
return e
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"music-server/internal/backend"
|
"music-server/internal/backend"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncHandler struct {
|
type SyncHandler struct {
|
||||||
@@ -23,7 +23,7 @@ func NewSyncHandler() *SyncHandler {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} map[string]interface{}
|
// @Success 200 {object} map[string]interface{}
|
||||||
// @Router /sync/progress [get]
|
// @Router /sync/progress [get]
|
||||||
func (s *SyncHandler) SyncProgress(ctx echo.Context) error {
|
func (s *SyncHandler) SyncProgress(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Getting progress")
|
log.Println("Getting progress")
|
||||||
response := backend.SyncProgress()
|
response := backend.SyncProgress()
|
||||||
@@ -43,7 +43,7 @@ func (s *SyncHandler) SyncProgress(ctx echo.Context) error {
|
|||||||
// @Success 200 {string} string "Start syncing games"
|
// @Success 200 {string} string "Start syncing games"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /sync [get]
|
// @Router /sync [get]
|
||||||
func (s *SyncHandler) SyncGamesNewOnlyChanges(ctx echo.Context) error {
|
func (s *SyncHandler) SyncGamesNewOnlyChanges(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -62,7 +62,7 @@ func (s *SyncHandler) SyncGamesNewOnlyChanges(ctx echo.Context) error {
|
|||||||
// @Success 200 {string} string "Start syncing games full"
|
// @Success 200 {string} string "Start syncing games full"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /sync/full [get]
|
// @Router /sync/full [get]
|
||||||
func (s *SyncHandler) SyncGamesNewFull(ctx echo.Context) error {
|
func (s *SyncHandler) SyncGamesNewFull(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
@@ -81,7 +81,7 @@ func (s *SyncHandler) SyncGamesNewFull(ctx echo.Context) error {
|
|||||||
// @Success 200 {string} string "Games and songs are deleted from the database"
|
// @Success 200 {string} string "Games and songs are deleted from the database"
|
||||||
// @Failure 423 {string} string "Syncing is in progress"
|
// @Failure 423 {string} string "Syncing is in progress"
|
||||||
// @Router /sync/reset [get]
|
// @Router /sync/reset [get]
|
||||||
func (s *SyncHandler) ResetGames(ctx echo.Context) error {
|
func (s *SyncHandler) ResetGames(ctx *echo.Context) error {
|
||||||
if backend.Syncing {
|
if backend.Syncing {
|
||||||
log.Println("Syncing is in progress")
|
log.Println("Syncing is in progress")
|
||||||
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
|
||||||
|
|||||||
Reference in New Issue
Block a user