var switch, fmt, npe fix

This commit is contained in:
2026-03-12 19:22:14 +01:00
parent 8c06024fe5
commit d007569f93
6 changed files with 21 additions and 29 deletions

View File

@@ -37,16 +37,6 @@ type Server struct {
v1.UnimplementedMusicBackendServer
}
func (s *Server) registerRoutes() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/api/v1/audio/{filepath}", s.songFile)
mux.HandleFunc("/api/v1/image/{filepath}", s.imageFile)
mux.HandleFunc("/api/v1/callback", s.callback)
return mux
}
func logRequests(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL.Path)
@@ -73,10 +63,6 @@ func (s *Server) Ping(ctx context.Context, req *v1.PingRequest) (*v1.PingRespons
return &v1.PingResponse{Pong: "pong"}, nil
}
func (s *Server) login(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://proxy.illegalesachen.download/login", http.StatusTemporaryRedirect)
}
func (s *Server) Song(ctx context.Context, req *v1.SongRequest) (*v1.SongResponse, error) {
hash := req.Hash
@@ -153,9 +139,9 @@ func (s *Server) Collections(ctx context.Context, req *v1.CollectionRequest) (*v
}
c, err := s.Sqlc.GetCollectionByOffset(ctx, sqlcdb.GetCollectionByOffsetParams{
Offset: int64(req.Index),
Limit: int64(limit),
Offset_2: int64(offset),
Offset: int64(offset),
Limit: int64(limit),
Index: int64(req.Index),
})
if err != nil {
fmt.Println(err)
@@ -196,8 +182,7 @@ func (s *Server) Search(ctx context.Context, req *v1.SearchSharedRequest) (*v1.S
func (s *Server) SearchCollections(ctx context.Context, req *v1.SearchCollectionRequest) (*v1.SearchCollectionResponse, error) {
q := req.Query
q = "%" + q + "%"
//limit := defaultLimit(int(req.Limit))
limit := 10000
limit := defaultLimit(int(req.Limit))
offset := int(req.Offset)
preview, err := s.Sqlc.SearchCollection(ctx, sqlcdb.SearchCollectionParams{

View File

@@ -223,7 +223,8 @@ func (q *Queries) SearchArtists(ctx context.Context, arg SearchArtistsParams) ([
const searchBeatmaps = `-- name: SearchBeatmaps :many
SELECT beatmapid, artist, artistunicode, title, titleunicode, creator, difficulty, audio, md5hash, file, rankedstatus, lastmodifiedtime, totaltime, audiopreviewtime, beatmapsetid, source, tags, lastplayed, folder
FROM Beatmap
WHERE Title LIKE ? OR Artist LIKE ?
WHERE Title LIKE ? OR Artist LIKE ?
GROUP BY Folder
LIMIT ? OFFSET ?
`

View File

@@ -92,13 +92,13 @@ WHERE c.Name = (
ORDER BY Name
LIMIT 1 OFFSET ?1
)
LIMIT ?2 OFFSET ?3
LIMIT ?3 OFFSET ?2
`
type GetCollectionByOffsetParams struct {
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
Offset_2 int64 `json:"offset_2"`
Index int64 `json:"index"`
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}
type GetCollectionByOffsetRow struct {
@@ -115,7 +115,7 @@ type GetCollectionByOffsetRow struct {
}
func (q *Queries) GetCollectionByOffset(ctx context.Context, arg GetCollectionByOffsetParams) ([]GetCollectionByOffsetRow, error) {
rows, err := q.db.QueryContext(ctx, getCollectionByOffset, arg.Offset, arg.Limit, arg.Offset_2)
rows, err := q.db.QueryContext(ctx, getCollectionByOffset, arg.Index, arg.Offset, arg.Limit)
if err != nil {
return nil, err
}

View File

@@ -22,7 +22,8 @@ FROM Beatmap GROUP BY Folder ORDER BY LastModifiedTime DESC LIMIT ? OFFSET ?;
-- name: SearchBeatmaps :many
SELECT *
FROM Beatmap
WHERE Title LIKE ? OR Artist LIKE ?
WHERE Title LIKE ? OR Artist LIKE ?
GROUP BY Folder
LIMIT ? OFFSET ?;
-- name: SearchArtists :many

View File

@@ -35,9 +35,9 @@ WHERE c.Name = (
FROM Collection
GROUP BY Name
ORDER BY Name
LIMIT 1 OFFSET ?1
LIMIT 1 OFFSET @index
)
LIMIT ?2 OFFSET ?3;
LIMIT @limit OFFSET @offset;
-- name: GetCollectionByName :many
SELECT c.Name, b.BeatmapId, b.MD5Hash, b.Title, b.Artist, b.Creator, b.Folder, b.File, b.Audio, b.TotalTime

View File

@@ -70,8 +70,13 @@ func toProtoCollectionoffsetSqlc(rows []db.GetCollectionByOffsetRow) *v1.Collect
})
}
name := "Empty Collection"
if len(rows) > 0 {
name = rows[0].Name.String
}
return &v1.CollectionResponse{
Name: rows[0].Name.String,
Name: name,
Items: int32(len(rows)),
Songs: songs,
}