mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 11:36:36 +08:00
b0fe40142a
* Rebrand MMTL to MeBox across codebase and assets Rename the project display name, Go module path, environment variable prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl to MeBox/mebox. Replace logo assets with the new MeBox icon and keep legacy SQLite migration support for existing mmtl.db deployments. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix logo icons: use cube-only crop without truncated text Previous icon generation cropped too much of the source image, including partial MeBox wordmark text that was cut off in square icon containers. Regenerate logo-64/192/512, favicon, and SVG from cube-only region. Co-authored-by: truewhile <truewhile@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Package handler — playlist reordering + per-item-id removal that the
|
|
// Vue UI uses on top of the basic /playlists/:id/items surface.
|
|
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
"github.com/truewhile/MeBox/internal/service"
|
|
)
|
|
|
|
type reorderReq struct {
|
|
// Order is a list of media IDs in the desired playback order.
|
|
Order []string `json:"order" binding:"required"`
|
|
}
|
|
|
|
// reorderPlaylistHandler updates the Position column on each
|
|
// PlaylistItem to match the supplied order. Items missing from the
|
|
// order keep their existing position.
|
|
func reorderPlaylistHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
var req reorderReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
pid := c.Param("id")
|
|
for i, mid := range req.Order {
|
|
if err := svc.Repo.DB.WithContext(c.Request.Context()).
|
|
Model(&model.PlaylistItem{}).
|
|
Where("playlist_id = ? AND media_id = ?", pid, mid).
|
|
Update("position", i).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
}
|
|
|
|
// deletePlaylistItemByIDHandler is the alternate route at
|
|
// /playlists/:id/items/:item_id (vs. the existing /:media_id variant).
|
|
func deletePlaylistItemByIDHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if err := svc.Repo.DB.WithContext(c.Request.Context()).
|
|
Where("playlist_id = ? AND id = ?", c.Param("id"), c.Param("item_id")).
|
|
Delete(&model.PlaylistItem{}).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
}
|