package sourcectrl import ( "91porn-server/common" "91porn-server/common/constant" "91porn-server/common/constant/redisconst" "91porn-server/common/stderr" "91porn-server/models/l/operatorlgmod" "91porn-server/models/v/sourcemod" "91porn-server/web/webg" "encoding/json" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) // SourceAdd doc // @Summary 资源域名 // @Description 添加资源域名 // @Tags source // @Accept mpfd,json // @Produce json,html // @Param domain formData string true "域名" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /web/source/add [post] func SourceAdd(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := sourcemod.Source{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = sourcemod.Insert(&p); err != nil { common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error()) return } if p.Type == sourcemod.Vid { common.Go(func() { _, _ = webg.Redis.Del(redisconst.CdnCacheKey) }) } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.VideoManageSource, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, nil) } // SourceList doc // @Summary 资源域名 // @Description 资源域名列表 // @Tags source // @Accept mpfd,json // @Produce json,html // @Param pageNumber query integer true "当前页" mininum(1) // @Param pageSize query integer true "每页条数" mininum(1) // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /web/source/list [post] func SourceList(ctx *gin.Context) { result := sourcemod.WebList() common.ServeJSON(ctx, stderr.Success, result) } // SourceDel doc // @Summary 资源域名 // @Description 删除资源域名 // @Tags source // @Accept mpfd,json // @Produce json,html // @Param ids formData array true "id数组 字符串数组"" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /web/source/del [delete] func SourceDel(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } type args struct { IDs []primitive.ObjectID `form:"ids" json:"ids"` } param := args{} if err = ctx.ShouldBind(¶m); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = sourcemod.Remove(param.IDs); err != nil { common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error()) return } common.Go(func() { _, _ = webg.Redis.Del(redisconst.CdnCacheKey) }) log, _ := json.Marshal(param) _ = operatorlgmod.RecordOperation(manager, constant.VideoManageSource, constant.Delete, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, nil) } // SourceEdit doc // @Summary 资源域名修改 // @Description 资源域名修改 // @Tags source // @Accept mpfd,json // @Produce json,html // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /web/source/edit [post] func SourceEdit(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var param struct { ID primitive.ObjectID `form:"id" json:"id" binding:"required"` sourcemod.SourceEdit } if err = ctx.ShouldBind(¶m); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = sourcemod.EditDomain(param.ID, ¶m.SourceEdit); err != nil { common.ServeJSON(ctx, stderr.ErrDbUpdateError, "") return } common.Go(func() { _, _ = webg.Redis.Del(redisconst.CdnCacheKey) _, _ = webg.Redis.Del(redisconst.LandDomainCacheKey) }) log, _ := json.Marshal(param) _ = operatorlgmod.RecordOperation(manager, constant.VideoManageSource, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, nil) }