Browse Source

add:增加链接重定向

zqbao 13 hours ago
parent
commit
4938116e12
4 changed files with 24 additions and 7 deletions
  1. 1 3
      controllers/report.go
  2. 0 4
      models/report.go
  3. 4 0
      routers/router.go
  4. 19 0
      services/report_v2.go

+ 1 - 3
controllers/report.go

@@ -2049,11 +2049,9 @@ func (this *ReportCommonController) ShareTransform() {
 		return
 	}
 
-	resp := new(models.ReportShartOriginUrlResp)
-	resp.Url = link
+	this.Ctx.Redirect(302, link)
 
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
-	br.Data = resp
 }

+ 0 - 4
models/report.go

@@ -1851,7 +1851,3 @@ type ReportShartUrlReq struct {
 type ReportShartUrlResp struct {
 	UrlToken string `description:"分享链接token"`
 }
-
-type ReportShartOriginUrlResp struct {
-	Url string `description:"分享链接token"`
-}

+ 4 - 0
routers/router.go

@@ -31,6 +31,8 @@ import (
 	"eta/eta_mobile/controllers/smart_report"
 	"eta/eta_mobile/controllers/speech_recognition"
 	"eta/eta_mobile/controllers/trade_analysis"
+	"eta/eta_mobile/services"
+
 	"github.com/beego/beego/v2/server/web"
 	"github.com/beego/beego/v2/server/web/filter/cors"
 )
@@ -44,6 +46,8 @@ func init() {
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
 		AllowCredentials: true,
 	}))
+
+	web.InsertFilter("/v1/share/*", web.BeforeRouter, services.FilterShareUrl())
 	ns := web.NewNamespace("/v1",
 		web.NSNamespace("/ppt",
 			web.NSInclude(

+ 19 - 0
services/report_v2.go

@@ -12,8 +12,11 @@ import (
 	"os"
 	"path"
 	"strconv"
+	"strings"
 	"time"
 
+	"github.com/beego/beego/v2/server/web"
+	"github.com/beego/beego/v2/server/web/context"
 	"github.com/go-redis/redis/v8"
 	"github.com/rdlucklib/rdluck_tools/file"
 	"github.com/rdlucklib/rdluck_tools/http"
@@ -1488,3 +1491,19 @@ func TransfromToOriginUrl(linkToken string) (originLink string, msg string, err
 	}
 	return
 }
+
+func FilterShareUrl() web.FilterFunc {
+	return func(c *context.Context) {
+		path := c.Input.Context.Request.URL.Path
+		tokenArr := strings.Split(path, "/")
+		token := tokenArr[len(tokenArr)-1]
+
+		newPath := "/v1/report/share/link"
+		q := c.Input.Context.Request.URL.Query()
+		q.Add("Token", token)
+		c.Input.Context.Request.URL.Path = newPath
+		c.Input.Context.Request.URL.RawQuery = q.Encode()
+
+		utils.ApiLog.Info(fmt.Sprintf("原始请求为:%s, 已修改请求路径为:%s?%s", path, newPath, q.Encode()))
+	}
+}