/
fs.go
47 lines (36 loc) · 1.07 KB
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package handler
import (
"fmt"
"net/http"
"github.com/uxff/flexdrive/pkg/dao"
"github.com/gin-gonic/gin"
)
func Fs(c *gin.Context) {
fileHash := c.Param("fileHash")
fileName := c.Param("fileName")
fileIndex, err := dao.GetFileIndexByFileHash(fileHash)
if err != nil {
c.Status(http.StatusNotFound)
//StdErrMsgResponse(c, ErrInternal, "文件读取错误")
return
}
if fileIndex == nil {
c.Status(http.StatusNotFound)
//StdErrMsgResponse(c, ErrInternal, "文件不存在或已被删除")
return
}
if fileName == "" {
fileName = fileIndex.FileName
}
// node := storagemodel.GetCurrentNode()
// if node == nil {
// StdErrMsgResponse(c, ErrInternal, "文件集群状态异常")
// return
// }
//physicalFilePath := node.FileHashToStoragePath(fileHash)
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileName))
//fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/octet-stream")
//c.File(physicalFilePath)
c.File(fileIndex.InnerPath)
}