|
@@ -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) {
|