@@ -0,0 +1,70 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"videoweb/app/service/playletser"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Play 播放页 SSR:GET /api/app/playlet/chapter/detail;seoInfo 直接注入模板。
|
||||
func Play(c *gin.Context) {
|
||||
playletKey := strings.TrimSpace(c.Param("slug"))
|
||||
requestedChapterID := strings.TrimSpace(c.Param("chapterId"))
|
||||
if playletKey == "" {
|
||||
NotFound(c, "未找到可播放内容")
|
||||
return
|
||||
}
|
||||
if requestedChapterID != "" && playletser.ParseDetailID(requestedChapterID) <= 0 {
|
||||
NotFound(c, "未找到该剧集")
|
||||
return
|
||||
}
|
||||
playlet := playletser.FetchDetailOrNilByKey(c, playletKey)
|
||||
if playlet == nil {
|
||||
NotFound(c, "未找到可播放内容")
|
||||
return
|
||||
}
|
||||
q := playletser.ParsePlayQuery(playletKey, c.Param("chapterId"))
|
||||
q.PlayletID = playlet.ID
|
||||
q.PlayletSlug = playlet.Slug
|
||||
|
||||
q.ChapterID = playletser.ResolvePlayChapterID(playlet, q.ChapterID)
|
||||
if q.ChapterID <= 0 {
|
||||
NotFound(c, "未找到可播放内容")
|
||||
return
|
||||
}
|
||||
target := playletser.PlayPath(q.PlayletSlug, q.PlayletID)
|
||||
if q.ChapterID > 0 {
|
||||
target = playletser.ChapterPlayPath(q.PlayletSlug, q.PlayletID, q.ChapterID)
|
||||
}
|
||||
if redirectCanonical(c, target) {
|
||||
return
|
||||
}
|
||||
|
||||
chapter := playletser.FetchChapterDetailOrNil(c, q.ChapterID, q.PlayletID, q.PlayletSlug)
|
||||
if chapter == nil {
|
||||
NotFound(c, "未找到该剧集")
|
||||
return
|
||||
}
|
||||
|
||||
var episodeRanges []playletser.EpisodeRange
|
||||
var chapters []playletser.PlayletChapterData
|
||||
playletID := playlet.ID
|
||||
playletSlug := playlet.Slug
|
||||
chapters = playlet.PlayletChapterInfo
|
||||
episodeRanges = playletser.BuildEpisodeRanges(chapters, playlet.TotalEpisode, 30)
|
||||
|
||||
seoInfo := playletser.ResolvePlayPageSEO(chapter, playlet)
|
||||
|
||||
data := gin.H{
|
||||
"title": playletser.ResolvePlayPageTitle(chapter, playlet),
|
||||
"chapter": chapter,
|
||||
"playlet": playlet,
|
||||
"playletID": playletID,
|
||||
"playletSlug": playletSlug,
|
||||
"seoInfo": seoInfo,
|
||||
"chapters": chapters,
|
||||
"episodeRanges": episodeRanges,
|
||||
}
|
||||
HTMLOK(c, "play.html", data)
|
||||
}
|
||||
Reference in New Issue
Block a user