mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 19:36:36 +08:00
3a2db6bdd9
## Emby/Jellyfin 兼容层 (emby_compat.go / emby.go) - 新增 SystemInfoPublic、FindUser、Items、Item、LatestItems、ResumeItems - 新增 SetFavorite、MarkPlayed、RecordProgress 用户播放状态同步 - 新增 itemPayload、mediaSource、mediaStreams 媒体信息组装 - 双前缀路由 /emby/* 和 / 根路径,兼容 Infuse/Yamby/Senplayer/Kodi - 新增 Ping、SystemEndpoint、AuthByName 端点 - emby.go 扩展对应 handler 函数 ## 站点适配器 (site_adapter.go / site.go) - SiteConfig 扩展 UserAgent/Timeout/Extra/FlareSolverrURL 字段 - doRequest() GET 请求支持 FlareSolverr 代理绕过 Cloudflare/WAF - MTeam api_key 认证改为 Authorization: Bearer 格式 - Search() 重构为 sync.WaitGroup 并发执行,提升多站搜索性能 - siteModelToConfig() 改为 SiteService 方法,按 BrowserEmulation 填充 FlareSolverrURL ## 图片代理 (image_proxy.go) - 重构图片代理服务,支持更多来源和缓存策略 ## 下载管理 (downloads.go / download_clients.go / qbittorrent.go) - 下载任务增强:状态管理、进度追踪优化 - qBittorrent 客户端连接稳定性改进 ## 刮削与数据库 (scraper.go / tmdb.go / repository.go) - 刮削器增强 TMDB 集成,补全元数据字段 - repository 扩展查询方法 ## 前端 (web/src/) - HomePage: 首页布局重构,按媒体库分组展示,系列聚合优化 - DiscoverPage: 发现页增强,错误处理改进(API key 缺失/网络错误分离) - PosterWallPage: 海报墙优化,系列聚合展示 - MediaCard: 媒体卡片优化 - PlayerPage: 播放器改进 - 新增 utils/groupSeries.ts: 系列聚合工具函数 - .gitignore: 添加 .tmp_* 临时文件排除规则
110 lines
3.4 KiB
Go
110 lines
3.4 KiB
Go
// Package handler — HLS / image-proxy / scrape endpoints.
|
||
package handler
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"net/http"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
|
||
"github.com/ShukeBta/MediaStationGo/internal/service"
|
||
)
|
||
|
||
func hlsPlaylistHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
err := svc.Stream.ServeHLSPlaylist(c.Writer, c.Request, c.Param("id"))
|
||
if errors.Is(err, service.ErrMediaNotFound) {
|
||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||
return
|
||
}
|
||
if err != nil {
|
||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
}
|
||
}
|
||
|
||
func hlsSegmentHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
err := svc.Stream.ServeHLSSegment(c.Writer, c.Request, c.Param("id"), c.Param("seg"))
|
||
if err != nil {
|
||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
}
|
||
}
|
||
|
||
func stopTranscodeHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
svc.Transcoder.StopJob(c.Param("id"))
|
||
c.Status(http.StatusNoContent)
|
||
}
|
||
}
|
||
|
||
func imageProxyHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
raw := c.Query("url")
|
||
// Serve handles upstream errors internally by returning a 1×1 PNG
|
||
// placeholder, so the only error we can get back here is a malformed
|
||
// URL. In that case we still return 400 to make the misuse visible.
|
||
if err := svc.ImageProxy.Serve(c.Request.Context(), c.Writer, c.Request, raw); err != nil {
|
||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
}
|
||
}
|
||
|
||
// scrapeOneHandler enriches a single media via TMDb. Admin-only.
|
||
func scrapeOneHandler(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": "not found"})
|
||
return
|
||
}
|
||
if !svc.TMDb.Enabled() {
|
||
c.JSON(http.StatusPreconditionFailed, gin.H{"error": "tmdb api key not configured"})
|
||
return
|
||
}
|
||
if err := svc.Scraper.EnrichOne(c.Request.Context(), m); err != nil {
|
||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
refreshed, _ := svc.Repo.Media.FindByID(c.Request.Context(), m.ID)
|
||
c.JSON(http.StatusOK, refreshed)
|
||
}
|
||
}
|
||
|
||
// scrapeLibraryHandler enriches every pending media in a library. Admin-only.
|
||
func scrapeLibraryHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
if !svc.TMDb.Enabled() {
|
||
c.JSON(http.StatusPreconditionFailed, gin.H{"error": "tmdb api key not configured"})
|
||
return
|
||
}
|
||
// Run in the background so HTTP returns instantly; the WS hub
|
||
// pushes per-item progress on the "scrape" topic.
|
||
go func(libID string) {
|
||
_, _ = svc.Scraper.EnrichLibrary(context.Background(), libID)
|
||
}(c.Param("id"))
|
||
c.JSON(http.StatusAccepted, gin.H{"status": "scraping"})
|
||
}
|
||
}
|
||
|
||
// reprobeHandler re-runs ffprobe against a single media. Admin-only.
|
||
func reprobeHandler(svc *service.Container) gin.HandlerFunc {
|
||
return func(c *gin.Context) {
|
||
if err := svc.Stream.Probe(c.Request.Context(), c.Param("id"), svc.FFprobe); err != nil {
|
||
if errors.Is(err, service.ErrMediaNotFound) {
|
||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||
return
|
||
}
|
||
// ffprobe unavailable or file inaccessible — still 200 with error info
|
||
c.JSON(http.StatusOK, gin.H{"code": 1, "error": err.Error()})
|
||
return
|
||
}
|
||
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "ok"})
|
||
}
|
||
}
|