mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-11-03 02:23:45 +08:00
迁移公共组件
This commit is contained in:
@@ -1,129 +0,0 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"x_admin/core"
|
||||
|
||||
config2 "x_admin/util/aj-captcha-go/config"
|
||||
constant "x_admin/util/aj-captcha-go/const"
|
||||
"x_admin/util/aj-captcha-go/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type CaptchaGetParams struct {
|
||||
CaptchaType string `json:"captchaType"`
|
||||
}
|
||||
|
||||
// 客户端参数 看自身业务构建即可
|
||||
type ClientParams struct {
|
||||
Token string `json:"token"`
|
||||
PointJson string `json:"pointJson"`
|
||||
CaptchaType string `json:"captchaType"`
|
||||
}
|
||||
|
||||
// **********************默认配置***************************************************
|
||||
// 默认配置,可以根据项目自行配置,将其他类型配置序列化上去
|
||||
// var config = config2.NewConfig()
|
||||
|
||||
// *********************自定义配置**************************************************
|
||||
// 水印配置(参数可从业务系统自定义)
|
||||
var watermarkConfig = &config2.WatermarkConfig{
|
||||
FontSize: 12,
|
||||
Color: color.RGBA{R: 255, G: 255, B: 255, A: 255},
|
||||
Text: "x_admin",
|
||||
}
|
||||
|
||||
// 点击文字配置(参数可从业务系统自定义)
|
||||
var clickWordConfig = &config2.ClickWordConfig{
|
||||
FontSize: 25,
|
||||
FontNum: 4,
|
||||
}
|
||||
|
||||
// 滑动模块配置(参数可从业务系统自定义)
|
||||
var blockPuzzleConfig = &config2.BlockPuzzleConfig{Offset: 10}
|
||||
|
||||
// 行为校验配置模块(具体参数可从业务系统配置文件自定义)
|
||||
var captcha_config = config2.BuildConfig(constant.RedisCacheKey, constant.DefaultResourceRoot, watermarkConfig,
|
||||
clickWordConfig, blockPuzzleConfig, 2*60)
|
||||
|
||||
// 服务工厂,主要用户注册 获取 缓存和验证服务
|
||||
var factory = service.NewCaptchaServiceFactory(captcha_config)
|
||||
|
||||
func init() {
|
||||
// 这里默认是注册了 内存缓存,但是不足以应对生产环境,希望自行注册缓存驱动 实现缓存接口即可替换(CacheType就是注册进去的 key)
|
||||
// factory.RegisterCache(constant.MemCacheKey, service.NewMemCacheService(200000)) // 这里20指的是缓存阈值
|
||||
|
||||
// //注册自定义配置redis数据库
|
||||
factory.RegisterCache(constant.RedisCacheKey, service.NewConfigRedisCacheService(core.Redis))
|
||||
|
||||
// 注册了两种验证码服务 可以自行实现更多的验证
|
||||
factory.RegisterService(constant.ClickWordCaptcha, service.NewClickWordCaptchaService(factory))
|
||||
factory.RegisterService(constant.BlockPuzzleCaptcha, service.NewBlockPuzzleCaptchaService(factory))
|
||||
}
|
||||
func RegisterRoute(rg *gin.RouterGroup) {
|
||||
|
||||
rg = rg.Group("/common/captcha")
|
||||
rg.POST("/get", func(c *gin.Context) {
|
||||
var captchaGet CaptchaGetParams
|
||||
if err := c.ShouldBind(&captchaGet); err != nil {
|
||||
// 返回错误信息
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
if captchaGet.CaptchaType == "" {
|
||||
c.JSON(200, errorRes(errors.New("验证码类型不能为空")))
|
||||
return
|
||||
}
|
||||
// 根据参数类型获取不同服务即可
|
||||
data, _ := factory.GetService(captchaGet.CaptchaType).Get()
|
||||
//输出json结果给调用方
|
||||
c.JSON(200, successRes(data))
|
||||
})
|
||||
rg.POST("/check", func(c *gin.Context) {
|
||||
var params ClientParams
|
||||
if err := c.ShouldBind(¶ms); err != nil {
|
||||
// 返回错误信息
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
ser := factory.GetService(params.CaptchaType)
|
||||
err := ser.Check(params.Token, params.PointJson)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
//输出json结果给调用方
|
||||
c.JSON(200, successRes(nil))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 登录等验证并删除
|
||||
func Verify(params ClientParams) error {
|
||||
ser := factory.GetService(params.CaptchaType)
|
||||
// 登录验证并删除
|
||||
err := ser.Verification(params.Token, params.PointJson)
|
||||
return err
|
||||
}
|
||||
func successRes(data interface{}) map[string]interface{} {
|
||||
ret := make(map[string]interface{})
|
||||
ret["error"] = false
|
||||
ret["repCode"] = "0000"
|
||||
ret["repData"] = data
|
||||
ret["repMsg"] = nil
|
||||
ret["successRes"] = true
|
||||
|
||||
return ret
|
||||
}
|
||||
func errorRes(err error) map[string]interface{} {
|
||||
ret := make(map[string]interface{})
|
||||
ret["error"] = true
|
||||
ret["repCode"] = "0001"
|
||||
ret["repData"] = nil
|
||||
ret["repMsg"] = err.Error()
|
||||
ret["successRes"] = false
|
||||
return ret
|
||||
}
|
||||
@@ -1,22 +1,17 @@
|
||||
package album
|
||||
package commonController
|
||||
|
||||
import (
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/schema/commonSchema"
|
||||
"x_admin/service/commonService"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AlbumRoute(rg *gin.RouterGroup) {
|
||||
// db := core.GetDB()
|
||||
// permSrv := system.NewSystemAuthPermService(db)
|
||||
// roleSrv := system.NewSystemAuthRoleService(db, permSrv)
|
||||
// adminSrv := system.NewSystemAuthAdminService(db, permSrv, roleSrv)
|
||||
// service := system.NewSystemLoginService(db, adminSrv)
|
||||
|
||||
// server := NewAlbumService(db)
|
||||
|
||||
handle := albumHandler{}
|
||||
|
||||
@@ -37,77 +32,77 @@ type albumHandler struct{}
|
||||
// albumList 相册文件列表
|
||||
func (ah albumHandler) albumList(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq CommonAlbumListReq
|
||||
var listReq commonSchema.CommonAlbumListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.AlbumList(page, listReq)
|
||||
res, err := commonService.AlbumService.AlbumList(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// albumRename 相册文件重命名
|
||||
func (ah albumHandler) albumRename(c *gin.Context) {
|
||||
var rnReq CommonAlbumRenameReq
|
||||
var rnReq commonSchema.CommonAlbumRenameReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &rnReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.AlbumRename(rnReq.ID, rnReq.Name))
|
||||
response.CheckAndResp(c, commonService.AlbumService.AlbumRename(rnReq.ID, rnReq.Name))
|
||||
}
|
||||
|
||||
// albumMove 相册文件移动
|
||||
func (ah albumHandler) albumMove(c *gin.Context) {
|
||||
var mvReq CommonAlbumMoveReq
|
||||
var mvReq commonSchema.CommonAlbumMoveReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &mvReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.AlbumMove(mvReq.Ids, mvReq.Cid))
|
||||
response.CheckAndResp(c, commonService.AlbumService.AlbumMove(mvReq.Ids, mvReq.Cid))
|
||||
}
|
||||
|
||||
// albumDel 相册文件删除
|
||||
func (ah albumHandler) albumDel(c *gin.Context) {
|
||||
var delReq CommonAlbumDelReq
|
||||
var delReq commonSchema.CommonAlbumDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.AlbumDel(delReq.Ids))
|
||||
response.CheckAndResp(c, commonService.AlbumService.AlbumDel(delReq.Ids))
|
||||
}
|
||||
|
||||
// cateList 类目列表
|
||||
func (ah albumHandler) cateList(c *gin.Context) {
|
||||
var listReq CommonCateListReq
|
||||
var listReq commonSchema.CommonCateListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.CateList(listReq)
|
||||
res, err := commonService.AlbumService.CateList(listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// cateAdd 类目新增
|
||||
func (ah albumHandler) cateAdd(c *gin.Context) {
|
||||
var addReq CommonCateAddReq
|
||||
var addReq commonSchema.CommonCateAddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.CateAdd(addReq))
|
||||
response.CheckAndResp(c, commonService.AlbumService.CateAdd(addReq))
|
||||
}
|
||||
|
||||
// cateRename 类目命名
|
||||
func (ah albumHandler) cateRename(c *gin.Context) {
|
||||
var rnReq CommonCateRenameReq
|
||||
var rnReq commonSchema.CommonCateRenameReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &rnReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.CateRename(rnReq.ID, rnReq.Name))
|
||||
response.CheckAndResp(c, commonService.AlbumService.CateRename(rnReq.ID, rnReq.Name))
|
||||
}
|
||||
|
||||
// cateDel 类目删除
|
||||
func (ah albumHandler) cateDel(c *gin.Context) {
|
||||
var delReq CommonCateDelReq
|
||||
var delReq commonSchema.CommonCateDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.CateDel(delReq.ID))
|
||||
response.CheckAndResp(c, commonService.AlbumService.CateDel(delReq.ID))
|
||||
}
|
||||
71
server/controller/admin/commonController/captcha.go
Normal file
71
server/controller/admin/commonController/captcha.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package commonController
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"x_admin/schema/commonSchema"
|
||||
"x_admin/service/commonService"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func CaptchaRoute(rg *gin.RouterGroup) {
|
||||
|
||||
rg = rg.Group("/common/captcha")
|
||||
rg.POST("/get", func(c *gin.Context) {
|
||||
var captchaGet commonSchema.CaptchaGetParams
|
||||
if err := c.ShouldBind(&captchaGet); err != nil {
|
||||
// 返回错误信息
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
if captchaGet.CaptchaType == "" {
|
||||
c.JSON(200, errorRes(errors.New("验证码类型不能为空")))
|
||||
return
|
||||
}
|
||||
// 根据参数类型获取不同服务即可
|
||||
data, err := commonService.CaptchaGet(captchaGet.CaptchaType)
|
||||
if err != nil {
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
//输出json结果给调用方
|
||||
c.JSON(200, successRes(data))
|
||||
})
|
||||
rg.POST("/check", func(c *gin.Context) {
|
||||
var params commonSchema.ClientParams
|
||||
if err := c.ShouldBind(¶ms); err != nil {
|
||||
// 返回错误信息
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
err := commonService.CaptchaCheck(params)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(200, errorRes(err))
|
||||
return
|
||||
}
|
||||
//输出json结果给调用方
|
||||
c.JSON(200, successRes(nil))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func successRes(data interface{}) map[string]interface{} {
|
||||
ret := make(map[string]interface{})
|
||||
ret["error"] = false
|
||||
ret["repCode"] = "0000"
|
||||
ret["repData"] = data
|
||||
ret["repMsg"] = nil
|
||||
ret["successRes"] = true
|
||||
|
||||
return ret
|
||||
}
|
||||
func errorRes(err error) map[string]interface{} {
|
||||
ret := make(map[string]interface{})
|
||||
ret["error"] = true
|
||||
ret["repCode"] = "0001"
|
||||
ret["repData"] = nil
|
||||
ret["repMsg"] = err.Error()
|
||||
ret["successRes"] = false
|
||||
return ret
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package index
|
||||
package commonController
|
||||
|
||||
import (
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/service/commonService"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -20,12 +21,12 @@ type indexHandler struct{}
|
||||
|
||||
// console 控制台
|
||||
func (ih indexHandler) console(c *gin.Context) {
|
||||
res, err := Service.Console()
|
||||
res, err := commonService.IndexService.Console()
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// config 公共配置
|
||||
func (ih indexHandler) config(c *gin.Context) {
|
||||
res, err := Service.Config()
|
||||
res, err := commonService.IndexService.Config()
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package upload
|
||||
package commonController
|
||||
|
||||
import (
|
||||
"x_admin/admin/common/album"
|
||||
"x_admin/config"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/schema/commonSchema"
|
||||
"x_admin/service/commonService"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -22,7 +23,7 @@ type uploadHandler struct{}
|
||||
|
||||
// uploadImage 上传图片
|
||||
func (uh uploadHandler) uploadImage(c *gin.Context) {
|
||||
var uReq album.CommonUploadImageReq
|
||||
var uReq commonSchema.CommonUploadImageReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &uReq)) {
|
||||
return
|
||||
}
|
||||
@@ -30,13 +31,13 @@ func (uh uploadHandler) uploadImage(c *gin.Context) {
|
||||
if response.IsFailWithResp(c, ve) {
|
||||
return
|
||||
}
|
||||
res, err := Service.UploadImage(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
|
||||
res, err := commonService.UploadService.UploadImage(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// uploadVideo 上传视频
|
||||
func (uh uploadHandler) uploadVideo(c *gin.Context) {
|
||||
var uReq album.CommonUploadImageReq
|
||||
var uReq commonSchema.CommonUploadImageReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &uReq)) {
|
||||
return
|
||||
}
|
||||
@@ -44,6 +45,6 @@ func (uh uploadHandler) uploadVideo(c *gin.Context) {
|
||||
if response.IsFailWithResp(c, ve) {
|
||||
return
|
||||
}
|
||||
res, err := Service.UploadVideo(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
|
||||
res, err := commonService.UploadService.UploadVideo(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package systemController
|
||||
|
||||
import (
|
||||
"x_admin/admin/common/captcha"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/schema/commonSchema"
|
||||
. "x_admin/schema/systemSchema"
|
||||
"x_admin/service/commonService"
|
||||
"x_admin/service/systemService"
|
||||
"x_admin/util"
|
||||
|
||||
@@ -24,11 +25,11 @@ type loginHandler struct{}
|
||||
|
||||
// login 登录系统
|
||||
func (lh loginHandler) login(c *gin.Context) {
|
||||
var params captcha.ClientParams
|
||||
var params commonSchema.ClientParams
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, ¶ms)) {
|
||||
return
|
||||
}
|
||||
err := captcha.Verify(params)
|
||||
err := commonService.CaptchaVerify(params)
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.Failed, err.Error())
|
||||
return
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"x_admin/admin/common/album"
|
||||
"x_admin/admin/common/index"
|
||||
"x_admin/admin/common/upload"
|
||||
"x_admin/admin/generator"
|
||||
|
||||
"x_admin/controller/admin/commonController"
|
||||
"x_admin/controller/admin/monitorController"
|
||||
"x_admin/controller/admin/settingController"
|
||||
"x_admin/controller/admin/systemController"
|
||||
@@ -18,9 +16,9 @@ func RegisterRoute(rg *gin.RouterGroup) {
|
||||
rg = rg.Group("/admin")
|
||||
// 所有子路由需要加上前缀 /api/admin
|
||||
|
||||
upload.UploadRoute(rg)
|
||||
album.AlbumRoute(rg)
|
||||
index.IndexRoute(rg)
|
||||
commonController.UploadRoute(rg)
|
||||
commonController.AlbumRoute(rg)
|
||||
commonController.IndexRoute(rg)
|
||||
|
||||
monitorController.RegisterRoute(rg)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"x_admin/admin/common/captcha"
|
||||
"x_admin/controller/admin/commonController"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/router/admin"
|
||||
@@ -24,5 +24,5 @@ func RegisterRoute(api *gin.RouterGroup, rootRouter *gin.Engine) {
|
||||
// /api/admin
|
||||
admin.RegisterRoute(api)
|
||||
// /api/common/captcha 验证码
|
||||
captcha.RegisterRoute(api)
|
||||
commonController.CaptchaRoute(api)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package album
|
||||
package commonSchema
|
||||
|
||||
import "x_admin/core"
|
||||
|
||||
12
server/schema/commonSchema/captchaSchema.go
Normal file
12
server/schema/commonSchema/captchaSchema.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package commonSchema
|
||||
|
||||
type CaptchaGetParams struct {
|
||||
CaptchaType string `json:"captchaType"`
|
||||
}
|
||||
|
||||
// 客户端参数 看自身业务构建即可
|
||||
type ClientParams struct {
|
||||
Token string `json:"token"`
|
||||
PointJson string `json:"pointJson"`
|
||||
CaptchaType string `json:"captchaType"`
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package album
|
||||
package commonService
|
||||
|
||||
import (
|
||||
"path"
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model/common_model"
|
||||
"x_admin/schema/commonSchema"
|
||||
"x_admin/util"
|
||||
"x_admin/util/convert_util"
|
||||
|
||||
@@ -14,18 +15,18 @@ import (
|
||||
)
|
||||
|
||||
type IAlbumService interface {
|
||||
AlbumList(page request.PageReq, listReq CommonAlbumListReq) (res response.PageResp, e error)
|
||||
AlbumList(page request.PageReq, listReq commonSchema.CommonAlbumListReq) (res response.PageResp, e error)
|
||||
AlbumRename(id uint, name string) (e error)
|
||||
AlbumMove(ids []uint, cid int) (e error)
|
||||
AlbumAdd(addReq CommonAlbumAddReq) (res uint, e error)
|
||||
AlbumAdd(addReq commonSchema.CommonAlbumAddReq) (res uint, e error)
|
||||
AlbumDel(ids []uint) (e error)
|
||||
CateList(listReq CommonCateListReq) (mapList []CommonCateListResp, e error)
|
||||
CateAdd(addReq CommonCateAddReq) (e error)
|
||||
CateList(listReq commonSchema.CommonCateListReq) (mapList []commonSchema.CommonCateListResp, e error)
|
||||
CateAdd(addReq commonSchema.CommonCateAddReq) (e error)
|
||||
CateRename(id uint, name string) (e error)
|
||||
CateDel(id uint) (e error)
|
||||
}
|
||||
|
||||
var Service = NewAlbumService()
|
||||
var AlbumService = NewAlbumService()
|
||||
|
||||
// NewAlbumService 初始化
|
||||
func NewAlbumService() IAlbumService {
|
||||
@@ -39,7 +40,7 @@ type albumService struct {
|
||||
}
|
||||
|
||||
// AlbumList 相册文件列表
|
||||
func (albSrv albumService) AlbumList(page request.PageReq, listReq CommonAlbumListReq) (res response.PageResp, e error) {
|
||||
func (albSrv albumService) AlbumList(page request.PageReq, listReq commonSchema.CommonAlbumListReq) (res response.PageResp, e error) {
|
||||
// 分页信息
|
||||
limit := page.PageSize
|
||||
offset := page.PageSize * (page.PageNo - 1)
|
||||
@@ -66,7 +67,7 @@ func (albSrv albumService) AlbumList(page request.PageReq, listReq CommonAlbumLi
|
||||
if e = response.CheckErr(err, "Album列表获取失败"); e != nil {
|
||||
return
|
||||
}
|
||||
albumResps := []CommonAlbumListResp{}
|
||||
albumResps := []commonSchema.CommonAlbumListResp{}
|
||||
convert_util.Copy(&albumResps, albums)
|
||||
// TODO: engine默认local
|
||||
engine := "local"
|
||||
@@ -128,7 +129,7 @@ func (albSrv albumService) AlbumMove(ids []uint, cid int) (e error) {
|
||||
}
|
||||
|
||||
// AlbumAdd 相册文件新增
|
||||
func (albSrv albumService) AlbumAdd(addReq CommonAlbumAddReq) (res uint, e error) {
|
||||
func (albSrv albumService) AlbumAdd(addReq commonSchema.CommonAlbumAddReq) (res uint, e error) {
|
||||
var alb common_model.Album
|
||||
//var params map[string]interface{}
|
||||
//if err := mapstructure.Decode(params, &alb); err != nil {
|
||||
@@ -160,7 +161,7 @@ func (albSrv albumService) AlbumDel(ids []uint) (e error) {
|
||||
}
|
||||
|
||||
// CateList 相册分类列表
|
||||
func (albSrv albumService) CateList(listReq CommonCateListReq) (mapList []CommonCateListResp, e error) {
|
||||
func (albSrv albumService) CateList(listReq commonSchema.CommonCateListReq) (mapList []commonSchema.CommonCateListResp, e error) {
|
||||
var cates []common_model.AlbumCate
|
||||
cateModel := albSrv.db.Where("is_delete = ?", 0).Order("id desc")
|
||||
if listReq.Type > 0 {
|
||||
@@ -173,13 +174,13 @@ func (albSrv albumService) CateList(listReq CommonCateListReq) (mapList []Common
|
||||
if e = response.CheckErr(err, "Cate列表获取失败"); e != nil {
|
||||
return
|
||||
}
|
||||
cateResps := []CommonCateListResp{}
|
||||
cateResps := []commonSchema.CommonCateListResp{}
|
||||
convert_util.Copy(&cateResps, cates)
|
||||
return cateResps, nil
|
||||
}
|
||||
|
||||
// CateAdd 分类新增
|
||||
func (albSrv albumService) CateAdd(addReq CommonCateAddReq) (e error) {
|
||||
func (albSrv albumService) CateAdd(addReq commonSchema.CommonCateAddReq) (e error) {
|
||||
var cate common_model.AlbumCate
|
||||
convert_util.Copy(&cate, addReq)
|
||||
err := albSrv.db.Create(&cate).Error
|
||||
69
server/service/commonService/captchaService.go
Normal file
69
server/service/commonService/captchaService.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package commonService
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"x_admin/core"
|
||||
"x_admin/schema/commonSchema"
|
||||
config2 "x_admin/util/aj-captcha-go/config"
|
||||
constant "x_admin/util/aj-captcha-go/const"
|
||||
"x_admin/util/aj-captcha-go/service"
|
||||
)
|
||||
|
||||
// var config = config2.NewConfig()// 默认配置,可以根据项目自行配置,将其他类型配置序列化上去
|
||||
// var config = config2.WatermarkConfig//自定义配置
|
||||
// 水印配置(参数可从业务系统自定义)
|
||||
var watermarkConfig = &config2.WatermarkConfig{
|
||||
FontSize: 12,
|
||||
Color: color.RGBA{R: 255, G: 255, B: 255, A: 255},
|
||||
Text: "x_admin",
|
||||
}
|
||||
|
||||
// 点击文字配置(参数可从业务系统自定义)
|
||||
var clickWordConfig = &config2.ClickWordConfig{
|
||||
FontSize: 25,
|
||||
FontNum: 5,
|
||||
}
|
||||
|
||||
// 滑动模块配置(参数可从业务系统自定义)
|
||||
var blockPuzzleConfig = &config2.BlockPuzzleConfig{Offset: 10}
|
||||
|
||||
// 行为校验配置模块(具体参数可从业务系统配置文件自定义)
|
||||
var captcha_config = config2.BuildConfig(constant.RedisCacheKey, constant.DefaultResourceRoot, watermarkConfig,
|
||||
clickWordConfig, blockPuzzleConfig, 2*60)
|
||||
|
||||
// 服务工厂,主要用户注册 获取 缓存和验证服务
|
||||
var factory = service.NewCaptchaServiceFactory(captcha_config)
|
||||
|
||||
func init() {
|
||||
// 这里默认是注册了 内存缓存,但是不足以应对生产环境,希望自行注册缓存驱动 实现缓存接口即可替换(CacheType就是注册进去的 key)
|
||||
// factory.RegisterCache(constant.MemCacheKey, service.NewMemCacheService(200000)) // 这里20指的是缓存阈值
|
||||
|
||||
// //注册自定义配置redis数据库
|
||||
factory.RegisterCache(constant.RedisCacheKey, service.NewConfigRedisCacheService(core.Redis))
|
||||
|
||||
// 注册了两种验证码服务 可以自行实现更多的验证
|
||||
factory.RegisterService(constant.ClickWordCaptcha, service.NewClickWordCaptchaService(factory))
|
||||
factory.RegisterService(constant.BlockPuzzleCaptcha, service.NewBlockPuzzleCaptchaService(factory))
|
||||
}
|
||||
|
||||
// 登录等场景验证,并删除
|
||||
func CaptchaVerify(params commonSchema.ClientParams) error {
|
||||
ser := factory.GetService(params.CaptchaType)
|
||||
// 登录验证并删除
|
||||
err := ser.Verification(params.Token, params.PointJson)
|
||||
return err
|
||||
}
|
||||
func CaptchaGet(captchaType string) (interface{}, error) {
|
||||
// 根据参数类型获取不同服务即可
|
||||
data, err := factory.GetService(captchaType).Get()
|
||||
|
||||
return data, err
|
||||
}
|
||||
|
||||
// 检查是否正确
|
||||
func CaptchaCheck(params commonSchema.ClientParams) error {
|
||||
ser := factory.GetService(params.CaptchaType)
|
||||
// 登录验证并删除
|
||||
err := ser.Check(params.Token, params.PointJson)
|
||||
return err
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package index
|
||||
package commonService
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var Service = NewIndexService()
|
||||
var IndexService = NewIndexService()
|
||||
|
||||
// NewIndexService 初始化
|
||||
func NewIndexService() *indexService {
|
||||
@@ -1,18 +1,19 @@
|
||||
package upload
|
||||
package commonService
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
"x_admin/admin/common/album"
|
||||
|
||||
"x_admin/plugin"
|
||||
"x_admin/schema/commonSchema"
|
||||
"x_admin/util/convert_util"
|
||||
)
|
||||
|
||||
type IUploadService interface {
|
||||
UploadImage(file *multipart.FileHeader, cid uint, aid uint) (res album.CommonUploadFileResp, e error)
|
||||
UploadVideo(file *multipart.FileHeader, cid uint, aid uint) (res album.CommonUploadFileResp, e error)
|
||||
UploadImage(file *multipart.FileHeader, cid uint, aid uint) (res commonSchema.CommonUploadFileResp, e error)
|
||||
UploadVideo(file *multipart.FileHeader, cid uint, aid uint) (res commonSchema.CommonUploadFileResp, e error)
|
||||
}
|
||||
|
||||
var Service = NewUploadService()
|
||||
var UploadService = NewUploadService()
|
||||
|
||||
// NewUploadService 初始化
|
||||
func NewUploadService() *uploadService {
|
||||
@@ -23,27 +24,27 @@ func NewUploadService() *uploadService {
|
||||
type uploadService struct{}
|
||||
|
||||
// UploadImage 上传图片
|
||||
func (upSrv uploadService) UploadImage(file *multipart.FileHeader, cid uint, aid uint) (res album.CommonUploadFileResp, e error) {
|
||||
func (upSrv uploadService) UploadImage(file *multipart.FileHeader, cid uint, aid uint) (res commonSchema.CommonUploadFileResp, e error) {
|
||||
return upSrv.uploadFile(file, "image", 10, cid, aid)
|
||||
}
|
||||
|
||||
// UploadVideo 上传视频
|
||||
func (upSrv uploadService) UploadVideo(file *multipart.FileHeader, cid uint, aid uint) (res album.CommonUploadFileResp, e error) {
|
||||
func (upSrv uploadService) UploadVideo(file *multipart.FileHeader, cid uint, aid uint) (res commonSchema.CommonUploadFileResp, e error) {
|
||||
return upSrv.uploadFile(file, "video", 20, cid, aid)
|
||||
}
|
||||
|
||||
// uploadFile 上传文件
|
||||
func (upSrv uploadService) uploadFile(file *multipart.FileHeader, folder string, fileType int, cid uint, aid uint) (res album.CommonUploadFileResp, e error) {
|
||||
func (upSrv uploadService) uploadFile(file *multipart.FileHeader, folder string, fileType int, cid uint, aid uint) (res commonSchema.CommonUploadFileResp, e error) {
|
||||
var upRes *plugin.UploadFile
|
||||
if upRes, e = plugin.StorageDriver.Upload(file, folder, fileType); e != nil {
|
||||
return
|
||||
}
|
||||
var addReq album.CommonAlbumAddReq
|
||||
var addReq commonSchema.CommonAlbumAddReq
|
||||
convert_util.Copy(&addReq, upRes)
|
||||
addReq.Aid = aid
|
||||
addReq.Cid = cid
|
||||
var albumId uint
|
||||
if albumId, e = album.Service.AlbumAdd(addReq); e != nil {
|
||||
if albumId, e = AlbumService.AlbumAdd(addReq); e != nil {
|
||||
return
|
||||
}
|
||||
convert_util.Copy(&res, addReq)
|
||||
Reference in New Issue
Block a user