92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
package extctrl
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"91porn-server/common"
|
|
"91porn-server/common/constant"
|
|
"91porn-server/common/constant/redisconst"
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/maths"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/common/ysphone"
|
|
"91porn-server/web/service/vidser"
|
|
"91porn-server/web/webg"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 拓展功能接口 doc
|
|
// @Summary 查看用户验证码
|
|
// @Description 查看用户验证码
|
|
// @Tags Ext-拓展功能
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param mobile formData string true "手机号"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/extend/viewCaptcha [get]
|
|
func ViewCaptcha(ctx *gin.Context) {
|
|
var args struct {
|
|
Mobile string `form:"mobile" json:"mobile" binding:"required"`
|
|
}
|
|
if err := ctx.ShouldBind(&args); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
args.Mobile = strings.TrimSpace(args.Mobile)
|
|
args.Mobile = ysphone.FormatPhoneNumber(args.Mobile)
|
|
redisKey := redisconst.MobileCaptchaKey(args.Mobile)
|
|
redisCode, _ := webg.Redis.Get(redisKey)
|
|
var captcha string
|
|
if redisCode == nil {
|
|
captcha = maths.RandDigits(constant.CaptchaLen)
|
|
if err := webg.Redis.Set(redisKey, captcha, redisconst.MobileCaptchaExpire); err != nil {
|
|
log.Error("SendCaptcha Save Redis error", log.Any("mobile", args.Mobile), log.E(err))
|
|
common.ServeJSON(ctx, stderr.Failure, err.Error())
|
|
return
|
|
}
|
|
} else {
|
|
captcha = *redisCode
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{"captcha": captcha})
|
|
}
|
|
|
|
// 从Server-file同步基础信息 doc
|
|
// @Summary
|
|
// @Description 从Server-file同步基础信息
|
|
// @Tags Ext-拓展功能
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param mobile formData string true "手机号"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/extend/syncServerFile [post]
|
|
func SyncServerFile(ctx *gin.Context) {
|
|
var args struct {
|
|
IDs []string `form:"ids" json:"ids" binding:"required"`
|
|
Token string `form:"token" json:"token" binding:"required"`
|
|
}
|
|
if err := ctx.ShouldBind(&args); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
if args.Token != "q7ydjHVIVBYiTqQ&" {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
var successCnt, failCount int64
|
|
failIds := make([]string, 0, len(args.IDs))
|
|
for _, v := range args.IDs {
|
|
code := vidser.SyncBaseInfoFromFs(v)
|
|
if code != stderr.UpLoadFileComplete {
|
|
failCount++
|
|
failIds = append(failIds, v)
|
|
continue
|
|
}
|
|
successCnt++
|
|
}
|
|
ctx.JSON(http.StatusOK, gin.H{"successCnt": successCnt, "failCount": failCount, "failIds": failIds})
|
|
}
|