mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 19:36:36 +08:00
1dbd73b30b
== New domain models (7) ==
- UserPermission: per-user feature toggles (13 booleans)
- StorageConfig: encrypted Alist/S3/WebDAV adapters
- LicenseKey + LicenseActivation: offline license issuance
- DownloadClient: multi-client downloader configs
- AssistantSession + AssistantMessage: multi-turn AI chat persistence
== New services (5) ==
- PermissionService: admin grants always-true; user defaults seeded
- StorageConfigService: AES-GCM encryption + per-type connection probe
- LicenseService: 24-char hyphenated key generation, activation/heartbeat
- DownloadClientService: qB/Aria2/Transmission CRUD + WebUI test
- AssistantService: chat history + execute/undo stubs (op_id tracking)
== Extended AIService.Chat ==
- Multi-turn LLM call with chat history; offline fallback reply
== New endpoints (60+) ==
Auth:
POST /auth/refresh, /auth/logout, /auth/change-password
PATCH /auth/profile
GET /auth/permissions, /auth/me
Permissions admin:
GET/PUT /admin/users/:id/permissions
POST /admin/users/:id/permissions/reset
Search:
GET /search, /search/advanced, /search/tmdb, /search/sites
System:
GET /system/config, /settings/schema, /system/events/ticket
POST /admin/system/scheduler/:name/trigger
Stats:
GET /stats/user/:id, /stats/top-users
POST /stats/play
Sites:
GET /sites/:id/resource, /sites/:id/userdata
Subscriptions:
PUT /subscriptions/:id, POST /subscriptions/:id/search
Playlists:
POST /playlists/:id/reorder
DELETE /playlists/:id/items/by-id/:item_id
DLNA per-renderer:
POST /dlna/:uuid/{play,pause,stop}, GET /dlna/:uuid/status
Media:
POST/DELETE /media/:id/favorite, GET /media/:id/favorite/status
POST /media/:id/ai-scrape, /media/scrape/test, /media/organize
GET /favorites (alias)
Playback:
GET /playback/:id/info, /playback/:id/external-players, /playback/:id/external-url
POST /playback/:id/progress
GET /playback/transcode/:job_id/status
Downloads:
POST /download/:id/{pause,resume,organize}
POST /download/{organize,sync,start-auto-sync}
GET /download/tasks
Admin: full CRUD on /admin/download/clients + /admin/download/aria2/stats
License:
POST /license/{activate,heartbeat}
GET /license/{status,heartbeat-status}
Admin: /admin/license/{generate,list,:id/activations,:id/revoke,activation/:id/unbind}
Storage:
GET /admin/storage/{status,:type}
PUT /admin/storage/:type, POST /admin/storage/:type/test
Assistant (multi-turn AI):
GET/POST /admin/assistant/sessions
GET/DELETE /admin/assistant/session/:id
POST /admin/assistant/{chat,execute}
POST /admin/assistant/undo/:op_id
GET /admin/assistant/history
== New React pages (4) ==
- AssistantChatPage (/assistant): full multi-turn chat UI with sessions
sidebar, optimistic user-turn append, live AI response.
- DownloadClientsPage (/download-clients): typed CRUD form for
qBittorrent / Aria2 / Transmission + per-row Test action.
- LicensePage (/license): generate keys, list activations, revoke,
unbind individual devices.
- StorageConfigPage (/storage-config): tabbed Alist/WebDAV/S3 form
with secret-aware redaction + connection probe.
== New API helpers (5) ==
- assistant, download_clients, license, permissions, storage_config
== Layout ==
- Sidebar gains 4 new admin links (AI 对话, 下载器, 外部存储, 许可证).
131 lines
4.2 KiB
Go
131 lines
4.2 KiB
Go
// Package handler — playback metadata endpoints expected by the Vue UI:
|
|
//
|
|
// GET /playback/:id/info
|
|
// POST /playback/:id/progress
|
|
// GET /playback/:id/external-players
|
|
// GET /playback/:id/external-url
|
|
// GET /playback/transcode/:job_id/status
|
|
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/middleware"
|
|
"github.com/ShukeBta/MediaStationGo/internal/model"
|
|
"github.com/ShukeBta/MediaStationGo/internal/service"
|
|
)
|
|
|
|
// playbackInfoHandler returns the media row + a `stream_url` the React
|
|
// player can hit. Mirrors the Python project's surface.
|
|
func playbackInfoHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
m, err := svc.Repo.Media.FindByID(c.Request.Context(), c.Param("id"))
|
|
if err != nil || m == nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "media not found"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"media": m,
|
|
"stream_url": "/api/stream/" + m.ID,
|
|
"hls_url": "/api/hls/" + m.ID + "/index.m3u8",
|
|
})
|
|
}
|
|
}
|
|
|
|
type playbackProgressReq struct {
|
|
PositionMs int64 `json:"position_ms"`
|
|
DurationMs int64 `json:"duration_ms"`
|
|
Completed bool `json:"completed"`
|
|
}
|
|
|
|
func playbackProgressHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
var req playbackProgressReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
uid, _ := c.Get(middleware.CtxUserID)
|
|
if err := svc.Playback.RecordProgress(
|
|
c.Request.Context(), toString(uid), c.Param("id"),
|
|
req.PositionMs, req.DurationMs,
|
|
); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
}
|
|
|
|
// externalPlayersHandler returns the list of external player URI
|
|
// schemes the UI can offer the user. We lookup the media row to
|
|
// produce the per-player launch URL.
|
|
func externalPlayersHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
m, err := svc.Repo.Media.FindByID(c.Request.Context(), c.Param("id"))
|
|
if err != nil || m == nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "media not found"})
|
|
return
|
|
}
|
|
streamURL := "/api/stream/" + m.ID
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"players": []gin.H{
|
|
{"name": "VLC", "scheme": "vlc://", "url": "vlc://" + streamURL},
|
|
{"name": "PotPlayer", "scheme": "potplayer://", "url": "potplayer://" + streamURL},
|
|
{"name": "MX Player", "scheme": "intent://", "url": "intent://" + streamURL + "#Intent;package=com.mxtech.videoplayer.ad;end"},
|
|
{"name": "IINA", "scheme": "iina://", "url": "iina://weblink?url=" + streamURL},
|
|
{"name": "nPlayer", "scheme": "nplayer-", "url": "nplayer-" + streamURL},
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// externalURLHandler returns just the raw stream URL plus the auth
|
|
// token query string the external player needs.
|
|
func externalURLHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
m, err := svc.Repo.Media.FindByID(c.Request.Context(), c.Param("id"))
|
|
if err != nil || m == nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "media not found"})
|
|
return
|
|
}
|
|
// Re-issue a short-lived token for this stream.
|
|
uid, _ := c.Get(middleware.CtxUserID)
|
|
u, err := svc.Repo.User.FindByID(c.Request.Context(), toString(uid))
|
|
if err != nil || u == nil {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "user not found"})
|
|
return
|
|
}
|
|
token, err := svc.Auth.IssueToken(u)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"url": "/api/stream/" + m.ID + "?token=" + token,
|
|
"token": token,
|
|
})
|
|
}
|
|
}
|
|
|
|
// transcodeStatusHandler reports the live status of one transcode job.
|
|
// We surface the active jobs the transcoder knows about.
|
|
func transcodeStatusHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
jobID := c.Param("job_id")
|
|
for _, j := range svc.Transcoder.Active() {
|
|
if j.MediaID == jobID {
|
|
c.JSON(http.StatusOK, gin.H{"job_id": jobID, "status": "running", "job": j})
|
|
return
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"job_id": jobID, "status": "idle"})
|
|
}
|
|
}
|
|
|
|
// _ keeps imports tidy when the model package isn't otherwise used.
|
|
var _ = model.Media{}
|
|
var _ = service.Container{}
|