mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-30 03:36:37 +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 对话, 下载器, 外部存储, 许可证).
107 lines
3.2 KiB
Go
107 lines
3.2 KiB
Go
// Package handler — unified search surface that mirrors the Python
|
|
// project's /api/search* endpoints. Internally we delegate to the
|
|
// existing media + site adapters; advanced/tmdb/sites variants exist
|
|
// so the upstream Vue UI's queries don't need rewriting.
|
|
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/service"
|
|
)
|
|
|
|
// searchUnifiedHandler is the basic /api/search endpoint.
|
|
func searchUnifiedHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
q := c.Query("q")
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "30"))
|
|
if limit <= 0 || limit > 200 {
|
|
limit = 30
|
|
}
|
|
items, err := svc.Media.SearchMedia(c.Request.Context(), q, limit)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"items": items, "total": len(items)})
|
|
}
|
|
}
|
|
|
|
// searchAdvancedHandler accepts query + optional filters
|
|
// (year, type, library_id) — currently it ignores the filters in the
|
|
// SQL but threads them through to the response so the UI can echo
|
|
// them back. This keeps API parity without a giant query builder.
|
|
func searchAdvancedHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
q := c.Query("q")
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "30"))
|
|
if limit <= 0 || limit > 200 {
|
|
limit = 30
|
|
}
|
|
items, err := svc.Media.SearchMedia(c.Request.Context(), q, limit)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"items": items,
|
|
"filters": gin.H{
|
|
"year": c.Query("year"),
|
|
"type": c.Query("type"),
|
|
"library_id": c.Query("library_id"),
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// searchTMDbHandler proxies the TMDb /search endpoint via the existing
|
|
// SearchMovie helper. Movies and TV use different URLs upstream but
|
|
// only the movie path is wired today; TV is best-effort.
|
|
func searchTMDbHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
q := c.Query("query")
|
|
if q == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "query required"})
|
|
return
|
|
}
|
|
if svc.TMDb == nil || !svc.TMDb.Enabled() {
|
|
c.JSON(http.StatusOK, gin.H{"items": []any{}, "note": "tmdb disabled"})
|
|
return
|
|
}
|
|
match, err := svc.TMDb.SearchMovie(c.Request.Context(), q, 0)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
out := make([]any, 0, 1)
|
|
if match != nil {
|
|
out = append(out, match)
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"items": out})
|
|
}
|
|
}
|
|
|
|
// searchSitesHandler mirrors the existing /sites/search but at the
|
|
// /search/sites alias the Vue UI uses.
|
|
func searchSitesHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
keyword := c.Query("keyword")
|
|
if keyword == "" {
|
|
keyword = c.Query("q")
|
|
}
|
|
if keyword == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "keyword required"})
|
|
return
|
|
}
|
|
results, err := svc.Site.Search(c.Request.Context(), keyword)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"items": results})
|
|
}
|
|
}
|