Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"videoweb/app/service/playletser"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/useragent"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// History 观看历史 SSR:GET /api/app/playlet/history/list。
|
||||
func History(c *gin.Context) {
|
||||
if useragent.TokenFromRequest(c.Request) == "" {
|
||||
RedirectToLogin(c)
|
||||
return
|
||||
}
|
||||
|
||||
q := playletser.ParseHistoryListQuery(routeOrQuery(c, "page", "page"))
|
||||
if redirectCanonical(c, playletser.HistoryCanonicalPath(q)) {
|
||||
return
|
||||
}
|
||||
raw, code, err := playletser.FetchHistoryList(c, q)
|
||||
if err != nil {
|
||||
aborted, retry := AbortSSRIfSessionExpired(c, code)
|
||||
if aborted {
|
||||
return
|
||||
}
|
||||
if retry {
|
||||
raw, _, err = playletser.FetchHistoryList(c, q)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("fetch playlet history list failed", log.E(err))
|
||||
raw = &playletser.PlayletHistoryListResp{PageNum: q.PageNum, PageSize: q.PageSize}
|
||||
}
|
||||
}
|
||||
if raw == nil {
|
||||
raw = &playletser.PlayletHistoryListResp{PageNum: q.PageNum, PageSize: q.PageSize}
|
||||
}
|
||||
|
||||
data := gin.H{
|
||||
"title": "观看历史",
|
||||
"description": "查看黄果短剧观看历史,快速回到上次看到的剧集继续观看。",
|
||||
"navActive": "userCenter",
|
||||
"list": raw.List,
|
||||
"pageNum": raw.PageNum,
|
||||
"pageSize": raw.PageSize,
|
||||
"totalCount": raw.TotalCount,
|
||||
"pagination": playletser.BuildHistoryPagination(q, raw.TotalCount),
|
||||
"emptyTitle": "暂无观看历史",
|
||||
"emptyDesc": "开始播放短剧后,记录会出现在这里",
|
||||
}
|
||||
setNoIndex(data, false)
|
||||
HTMLOK(c, "history.html", data)
|
||||
}
|
||||
|
||||
// HistoryClear 代理上游 POST /api/app/playlet/history/clear。
|
||||
func HistoryClear(c *gin.Context) {
|
||||
if useragent.TokenFromRequest(c.Request) == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 401,
|
||||
"msg": "unauthorized",
|
||||
"tip": "请先登录",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
env, err := playletser.HistoryClear(c)
|
||||
if err != nil {
|
||||
log.Error("playlet history clear upstream failed", log.E(err))
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"msg": "history clear failed",
|
||||
"tip": "清空失败,请稍后重试",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
if env != nil && TryJSONSessionRecover(c, env.Code) {
|
||||
env, err = playletser.HistoryClear(c)
|
||||
if err != nil {
|
||||
log.Error("playlet history clear retry failed", log.E(err))
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"msg": "history clear failed",
|
||||
"tip": "清空失败,请稍后重试",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if env == nil || env.Code != 200 {
|
||||
tip := "清空失败"
|
||||
msg := ""
|
||||
code := 500
|
||||
if env != nil {
|
||||
code = env.Code
|
||||
msg = env.Msg
|
||||
tip = firstNonEmpty(env.Tip, env.Msg, tip)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": code,
|
||||
"msg": msg,
|
||||
"tip": tip,
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": firstNonEmpty(env.Msg, "success"),
|
||||
"tip": firstNonEmpty(env.Tip, "已清空观看历史"),
|
||||
"data": env.Data,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user