|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package comm
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md/comm"
- "applet/app/svc"
- "applet/app/utils/cache"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
- "github.com/aliyun/aliyun-oss-go-sdk/oss"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- // GetOssUrl
- // @Summary 通用请求-对象存储-上传许可链接(获取)
- // @Tags 对象存储
- // @Description 上传许可链接(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body comm.ImgReqUploadReq true "签名上传url"
- // @Success 200 {string} "许可链接"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/comm/getOssUrl [POST]
- func GetOssUrl(c *gin.Context) {
- var args comm.ImgReqUploadReq
- err := c.ShouldBindJSON(&args)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- sysCfgs, err := sysCfgDb.SysCfgGetAll()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if sysCfgs == nil {
- e.OutErr(c, e.ERR_CFG_CACHE, nil)
- return
- }
-
- cfgMap := make(map[string]string, len(*sysCfgs))
- for _, cfg := range *sysCfgs {
- cfgMap[cfg.Key] = cfg.Val
- }
- endpoint := cfgMap[enum2.AliyunOssEndpoint]
- bucketName := cfgMap[enum2.AliyunOssBucketName]
- ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
- accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
- accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
-
- // 创建OSSClient实例。
- client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- // 获取存储空间。
- bucket, err := client.Bucket(bucketName)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- options := []oss.Option{
- oss.ContentType(args.ContentType),
- }
-
- signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
- if err != nil {
- e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
- return
- }
-
- e.OutSuc(c, signedURL, nil)
- }
-
- // AccessRecords
- // @Summary 通用请求-访问记录-页面记录
- // @Tags 访问记录
- // @Description 页面记录
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body comm.AccessRecordsReq true "页面标识"
- // @Success 200 {string} "success"
- // @Success 200 {string} "data exist"
- // @Failure 400 {object} md.Response "具体错误"
- func AccessRecords(c *gin.Context) {
- var req *comm.AccessRecordsReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- user := svc.GetUser(c)
- date := time.Now().Format("2006-01-02")
- recordsDb := implement.NewEggAccessRecordsDb(db.Db)
- exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, nil)
- }
- if exist {
- e.OutSuc(c, "data exist", nil)
- return
- }
-
- m := model.EggAccessRecords{
- Uid: user.Id,
- PageIndex: req.Index,
- Date: date,
- }
- _, err = recordsDb.EggAccessRecordsInsert(&m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, nil)
- return
- }
-
- e.OutSuc(c, "success", nil)
- }
|