fix: improve media grouping and bot startup

This commit is contained in:
ShukeBta
2026-07-02 20:36:45 +08:00
parent 77b6e448e0
commit c07290619c
21 changed files with 508 additions and 220 deletions
+20 -4
View File
@@ -144,8 +144,24 @@ func embyResumeItemsHandler(svc *service.Container) gin.HandlerFunc {
}
}
func embyItemsCountsHandler(_ *service.Container) gin.HandlerFunc {
func embyItemsCountsHandler(svc *service.Container) gin.HandlerFunc {
return func(c *gin.Context) {
if svc != nil && svc.Emby != nil {
uid := firstQueryValue(c, "UserId", "userId")
if uid == "" {
uid = c.Param("userId")
}
if uid == "" {
uid = embyUserID(c)
}
out, err := svc.Emby.ItemCounts(c.Request.Context(), uid)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, out)
return
}
c.JSON(http.StatusOK, gin.H{
"MovieCount": 0,
"SeriesCount": 0,
@@ -166,18 +182,18 @@ func embyDisplayPreferencesHandler(_ *service.Container) gin.HandlerFunc {
"RememberIndexing": false,
"PrimaryImageHeight": 250,
"PrimaryImageWidth": 250,
"ScrollDirection": "Horizontal",
"ScrollDirection": "Vertical",
"ShowSidebar": true,
"CustomPrefs": gin.H{
"homeexploresection": "1",
"homesection0": "smalllibrarytiles",
"homesection1": "resume",
"homesection2": "latestmedia",
"homesection2": "none",
"homesection3": "nextup",
"homesection4": "none",
"homesection5": "none",
"homesection6": "none",
"latestItems": "true",
"latestItems": "false",
"landing-livetv": "false",
},
})
+5 -2
View File
@@ -146,8 +146,11 @@ func TestEmbyDisplayPreferencesAllowsAnonymousCompatibility(t *testing.T) {
if !ok {
t.Fatalf("missing CustomPrefs: %#v", body)
}
if customPrefs["homesection0"] != "smalllibrarytiles" || customPrefs["homesection2"] != "latestmedia" {
t.Fatalf("homepage sections should expose library tiles and latest media: %#v", customPrefs)
if customPrefs["homesection0"] != "smalllibrarytiles" || customPrefs["homesection2"] != "none" || customPrefs["latestItems"] != "false" {
t.Fatalf("homepage sections should expose library tiles without duplicate latest rails: %#v", customPrefs)
}
if body["ScrollDirection"] != "Vertical" {
t.Fatalf("homepage should prefer vertical library browsing, got %#v", body)
}
req = httptest.NewRequest(http.MethodPost, "/emby/displaypreferences/usersettings", strings.NewReader(`{}`))
+1 -1
View File
@@ -18,7 +18,7 @@ func recentMediaHandler(svc *service.Container) gin.HandlerFunc {
if limit <= 0 || limit > 100 {
limit = 12
}
items, err := svc.Media.SearchMediaVisible(c.Request.Context(), "", limit, mediaVisibilityForRequest(c, svc))
items, err := svc.Media.ListRecentSeriesCards(c.Request.Context(), limit, mediaVisibilityForRequest(c, svc))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
+6 -1
View File
@@ -4,8 +4,10 @@
package handler
import (
"context"
"io"
"net/http"
"time"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
@@ -83,7 +85,10 @@ func telegramGetWebhookHandler(svc *service.Container) gin.HandlerFunc {
// 路由:POST /api/admin/telegram/polling/start (需 admin 认证)
func telegramStartPollingHandler(svc *service.Container) gin.HandlerFunc {
return func(c *gin.Context) {
result := svc.TelegramBot.StartPolling(c.Request.Context())
setupCtx, cancel := context.WithTimeout(svc.Context(), 30*time.Second)
defer cancel()
result := svc.TelegramBot.StartPolling(setupCtx)
c.JSON(http.StatusOK, result)
}
}