139 lines
4.0 KiB
Go
139 lines
4.0 KiB
Go
package sharectrl
|
|
|
|
import (
|
|
"91porn-server/app/service/shareser"
|
|
"91porn-server/common"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/e/sharemod"
|
|
"net/http"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GeneratorQrCode doc
|
|
// @Summary 获取视频的分享次数
|
|
// @Description 获取视频的分享次数
|
|
// @Tags share
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param content formData string true "分享的url"
|
|
// @Param videoID formData string false "视频ID;同一用户、视频、自然日最多累计一次真实分享推荐分"
|
|
// @Param eventId formData string false "分享事件ID;同一次事件重试时保持不变,最长128字符"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/share/output [post]
|
|
func GeneratorQrCode(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
param := sharemod.VShareReq{}
|
|
if err = ctx.ShouldBind(¶m); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
if len(param.Content) == 0 {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
if param.ObjType == "drama" {
|
|
requestID := ctx.GetHeader("X-Request-ID")
|
|
if param.MediaID == "" || param.EventID == "" || requestID == "" || len(requestID) > 128 || len(param.EventID) > 128 {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
code, data := shareser.GeneratorDramaQrCodeContext(
|
|
ctx.Request.Context(), uid, param.Content, param.MediaID, param.ContentID, param.EventID,
|
|
)
|
|
common.ServeJSON(ctx, code, data)
|
|
return
|
|
}
|
|
code, data := shareser.GeneratorQrCodeContext(
|
|
ctx.Request.Context(),
|
|
uid,
|
|
param.Content,
|
|
param.VideoID,
|
|
param.EventID,
|
|
)
|
|
common.ServeJSON(ctx, code, data)
|
|
}
|
|
|
|
// GetShareCnt doc
|
|
// @Summary 获取视频的分享次数
|
|
// @Description 获取视频的分享次数
|
|
// @Tags share
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param videoID formData string true "视频id"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/share/count [get]
|
|
func GetShareCnt(ctx *gin.Context) {
|
|
param := sharemod.VShareCntReq{}
|
|
if err := ctx.ShouldBind(¶m); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
if len(param.VideoID) == 0 {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
code, data := shareser.GetShareCnt(param.VideoID)
|
|
common.ServeJSON(ctx, code, data)
|
|
}
|
|
|
|
// Info doc
|
|
// @Summary 获取分享信息
|
|
// @Description 获取分享信息
|
|
// @Tags share
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param id formData string true "视频id"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/share/info [get]
|
|
func Info(ctx *gin.Context) {
|
|
var param struct {
|
|
ID primitive.ObjectID `json:"id"`
|
|
}
|
|
h := gin.H{
|
|
"hash": false,
|
|
"data": "",
|
|
"time": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
|
|
}
|
|
if err := ctx.ShouldBind(¶m); err != nil {
|
|
h["code"] = stderr.ErrParamError
|
|
h["msg"] = stderr.ErrParamError.Msg()
|
|
h["tip"] = stderr.ErrParamError.Tip()
|
|
ctx.JSON(http.StatusOK, h)
|
|
return
|
|
}
|
|
if param.ID.IsZero() {
|
|
h["code"] = stderr.ErrParamError
|
|
h["msg"] = stderr.ErrParamError.Msg()
|
|
h["tip"] = stderr.ErrParamError.Tip()
|
|
ctx.JSON(http.StatusOK, h)
|
|
return
|
|
}
|
|
|
|
ua, _ := common.GetUA(ctx)
|
|
data, sErr := shareser.Info(param.ID, ua.SysType)
|
|
if sErr != nil && sErr.Code != stderr.Success {
|
|
h["code"] = sErr.Code
|
|
h["msg"] = sErr.Msg
|
|
h["tip"] = sErr.Tips
|
|
ctx.JSON(http.StatusOK, h)
|
|
return
|
|
}
|
|
|
|
h["code"] = stderr.Success
|
|
h["msg"] = stderr.Success.Msg()
|
|
h["tip"] = stderr.Success.Tip()
|
|
h["data"] = data
|
|
ctx.JSON(http.StatusOK, h)
|
|
}
|