瀏覽代碼

wip:身份校验换成token有效期校验

wkyuer 7 月之前
父節點
當前提交
34b41f4430

+ 23 - 13
src/jfw/modules/ossProxy/main.go

@@ -43,23 +43,31 @@ func (this *OssProxy) AttachmentProxy(fileName string) {
 		}
 
 		var (
-			ossSource   = gconv.String(cacheMap["source"])
-			checkUserId = gconv.String(cacheMap["userId"])
-			noPower     = gconv.String(cacheMap["noPower"])
+			ossSource  = gconv.String(cacheMap["source"])
+			timeout    = gconv.Int64(cacheMap["timeout"])
+			outputName = gconv.String(cacheMap["fileName"])
 
-			userId, _ = this.GetSession("userId").(string)
+			noPower = gconv.String(cacheMap["noPower"])
+			//checkUserId = gconv.String(cacheMap["userId"])
+			//userId, _ = this.GetSession("userId").(string)
 		)
-		if checkUserId != "" && userId != checkUserId {
+		//if checkUserId != "" && userId != checkUserId {
+		//	if noPower != "" {
+		//		jump = noPower
+		//	}
+		//	return nil, fmt.Errorf("用户身份校验异常")
+		//}
+		//
+		//if ossSource == "" {
+		//	return nil, fmt.Errorf("下载地址异常")
+		//}
+
+		if time.Now().Unix() > timeout {
 			if noPower != "" {
 				jump = noPower
 			}
-			return nil, fmt.Errorf("用户身份校验异常")
-		}
-
-		if ossSource == "" {
-			return nil, fmt.Errorf("下载地址异常")
+			return nil, fmt.Errorf("文件链接已过期")
 		}
-
 		res, err := http.Get(ossSource)
 		if err != nil {
 			log.Printf("%s 获取下载文件异常 %v", fileName, err)
@@ -74,6 +82,9 @@ func (this *OssProxy) AttachmentProxy(fileName string) {
 		for k, v := range res.Header {
 			w.Header().Set(k, v[0])
 		}
+		if outputName != "" {
+			w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", outputName))
+		}
 		return fileBytes, nil
 	}()
 	if jump != "" {
@@ -85,9 +96,8 @@ func (this *OssProxy) AttachmentProxy(fileName string) {
 		this.ServeJson(map[string]interface{}{
 			"errMsg": err.Error(),
 		})
-	} else {
-		_, _ = w.Write(bytes)
 	}
+	_, _ = w.Write(bytes)
 }
 
 func (this *OssProxy) OssProxy2(fileName string) {

+ 1 - 0
src/jfw/modules/subscribepay/src/config.yaml

@@ -43,4 +43,5 @@ pdfPackPrice:
 ossProxy:
   open: false #默认关闭,开启后走附件下载权限校验
   addr: https://oss.jianyu360.cn #若非新域名,则不用配置此地址,默认使用剑鱼web域名
+  lineTimeout: 18000 #链接过期时间
 

+ 7 - 4
src/jfw/modules/subscribepay/src/service/basePack.go

@@ -94,13 +94,16 @@ func (this *ResourcePack) ConsumePack() {
 				fileName = filepath.Base(ossAddr)
 				fileExt  = filepath.Ext(fileName)
 				cacheKey = fmt.Sprintf("attachment_%s%s", uid, fileExt)
+				timeout  = g.Cfg().MustGet(this.Request.Context(), "ossProxy.lineTimeout", 18000).Int64()
 			)
 			cacheMap := map[string]interface{}{
-				"userId":  userId,                                                                                   //可下载文件用户职位id
-				"source":  ossAddr,                                                                                  //oss文件地址
-				"noPower": fmt.Sprintf("%s/nologin/content/%s.html", config.Config.WebDomain, this.GetString("id")), //未登录或无权限跳转地址
+				"userId":   userId,                                                                                   //可下载文件用户职位id
+				"source":   ossAddr,                                                                                  //oss文件地址
+				"noPower":  fmt.Sprintf("%s/nologin/content/%s.html", config.Config.WebDomain, this.GetString("id")), //未登录或无权限跳转地址
+				"timeout":  time.Now().Unix() + timeout,
+				"fileName": Ret["fileName"],
 			}
-			if !redis.Put("newother", cacheKey, cacheMap, 60*60*24*30) {
+			if !redis.Put("newother", cacheKey, cacheMap, gconv.Int(timeout)*10) {
 				return map[string]interface{}{"code": -2}, "缓存异常"
 			}
 			Ret["downUrl"] = fmt.Sprintf("%s/jyoss/attachment/%s%s", g.Cfg().MustGet(this.Request.Context(), "ossProxy.addr", config.Config.WebDomain), uid, fileExt)