Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+203
View File
@@ -0,0 +1,203 @@
package dramactrl
import (
"errors"
"time"
"91porn-server/app/service/dramaser"
"91porn-server/app/service/m3u8ticket"
"91porn-server/common"
"91porn-server/common/stderr"
"91porn-server/models/v/walletmod"
"github.com/gin-gonic/gin"
)
// ChannelConfig doc
// @Summary 短剧频道配置
// @Tags 移动端-短剧
// @Success 200 {object} dramaser.ChannelConfig
// @Router /api/app/media/drama/channel/config [get]
func ChannelConfig(ctx *gin.Context) {
if _, err := common.GetUID(ctx); err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
data, err := dramaser.GetChannelConfig(time.Now())
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
// Feed doc
// @Summary AI短剧沉浸式推荐Feed
// @Tags 移动端-短剧
// @Param q query dramaser.FeedRequest true "请求参数"
// @Success 200 {object} dramaser.FeedResponse
// @Router /api/app/media/drama/feed [get]
func Feed(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req dramaser.FeedRequest
if err = ctx.ShouldBindQuery(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := dramaser.GetFeed(ctx.Request.Context(), uid, req.PageSize, time.Now())
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
return
}
for i := range data.List {
m3u8ticket.SignURL(ctx, uid, &data.List[i].Content.VideoUrl, true, false)
m3u8ticket.SignURL(ctx, uid, &data.List[i].Content.H265Url, true, false)
m3u8ticket.SignURL(ctx, uid, &data.List[i].Content.AudioUrl, true, false)
m3u8ticket.SignURL(ctx, uid, &data.List[i].Content.PreviewVideoUrl, false, true)
m3u8ticket.SignURL(ctx, uid, &data.List[i].Content.PreviewH265Url, false, true)
}
common.ServeJSON(ctx, stderr.Success, data)
}
// List doc
// @Summary 热门短剧双列列表
// @Tags 移动端-短剧
// @Param q query dramaser.ListRequest true "请求参数"
// @Success 200 {object} dramaser.ListResponse
// @Router /api/app/media/drama/list [get]
func List(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req dramaser.ListRequest
if err = ctx.ShouldBindQuery(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := dramaser.GetList(uid, req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
// Topics doc
// @Summary 短剧专题列表
// @Tags 移动端-短剧
// @Success 200 {object} dramaser.TopicListResponse
// @Router /api/app/media/drama/topics [get]
func Topics(ctx *gin.Context) {
if _, err := common.GetUID(ctx); err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
data, err := dramaser.GetTopics(time.Now())
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
// TopicWorks doc
// @Summary 短剧专题作品
// @Tags 移动端-短剧
// @Param q query dramaser.TopicWorksRequest true "请求参数"
// @Success 200 {object} dramaser.TopicWorksResponse
// @Router /api/app/media/drama/topic/works [get]
func TopicWorks(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req dramaser.TopicWorksRequest
if err = ctx.ShouldBindQuery(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := dramaser.GetTopicWorks(uid, req, time.Now())
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
// DownloadAuthorize doc
// @Summary 申请短剧单集下载并扣除下载次数
// @Tags 移动端-短剧
// @Param X-Request-ID header string true "幂等请求ID"
// @Param body body dramaser.DownloadAuthorizeRequest true "请求参数"
// @Success 200 {object} dramaser.DownloadAuthorizeResponse
// @Router /api/app/media/drama/download/authorize [post]
func DownloadAuthorize(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req dramaser.DownloadAuthorizeRequest
if err = ctx.ShouldBindJSON(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := dramaser.AuthorizeDownload(ctx.Request.Context(), uid, ctx.GetHeader("X-Request-ID"), req, time.Now())
if err != nil {
serveDownloadAuthorizeError(ctx, err)
return
}
m3u8ticket.SignURL(ctx, uid, &data.DownloadURL, true, false)
m3u8ticket.SignURL(ctx, uid, &data.H265DownloadURL, true, false)
common.ServeJSON(ctx, stderr.Success, data)
}
func serveDownloadAuthorizeError(ctx *gin.Context, err error) {
switch {
case errors.Is(err, dramaser.ErrDramaEntitlementRequired):
common.ServeJsonWithExtra(ctx, stderr.ErrAccessForbid,
gin.H{"reason": "DRAMA_ENTITLEMENT_REQUIRED"}, gin.H{"msg": "", "tip": ""})
case errors.Is(err, walletmod.ErrDownloadCountNotEnough):
common.ServeJsonWithExtra(ctx, stderr.DownloadCountIsNotEnough,
gin.H{"reason": "DOWNLOAD_COUNT_NOT_ENOUGH", "remainingDownloadCount": 0}, gin.H{"msg": "", "tip": ""})
case errors.Is(err, walletmod.ErrDownloadRequestConflict):
common.ServeJSON(ctx, stderr.ErrInvalidRequest, err)
case errors.Is(err, dramaser.ErrDownloadResourceInvalid):
common.ServeJSON(ctx, stderr.ErrParamError, err)
default:
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err)
}
}
// SaveEvents doc
// @Summary 批量上报短剧一期埋点
// @Tags 移动端-短剧
// @Param X-Request-ID header string true "幂等请求ID"
// @Param body body dramaser.EventsRequest true "请求参数"
// @Success 200 {object} dramaser.EventsResponse
// @Router /api/app/media/drama/events [post]
func SaveEvents(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req dramaser.EventsRequest
if err = ctx.ShouldBindJSON(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := dramaser.SaveEvents(uid, ctx.GetHeader("X-Request-ID"), req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
common.ServeJSON(ctx, stderr.Success, data)
}