(c *gin.Context)
| 39 | } |
| 40 | |
| 41 | func FsStream(c *gin.Context) { |
| 42 | defer func() { |
| 43 | if n, _ := io.ReadFull(c.Request.Body, []byte{0}); n == 1 { |
| 44 | _, _ = utils.CopyWithBuffer(io.Discard, c.Request.Body) |
| 45 | } |
| 46 | _ = c.Request.Body.Close() |
| 47 | }() |
| 48 | path := c.GetHeader("File-Path") |
| 49 | path, err := url.PathUnescape(path) |
| 50 | if err != nil { |
| 51 | common.ErrorResp(c, err, 400) |
| 52 | return |
| 53 | } |
| 54 | asTask := c.GetHeader("As-Task") == "true" |
| 55 | overwrite := c.GetHeader("Overwrite") != "false" |
| 56 | user := c.Request.Context().Value(conf.UserKey).(*model.User) |
| 57 | path, err = user.JoinPath(path) |
| 58 | if err != nil { |
| 59 | common.ErrorResp(c, err, 403) |
| 60 | return |
| 61 | } |
| 62 | if !overwrite { |
| 63 | if res, _ := fs.Get(c.Request.Context(), path, &fs.GetArgs{NoLog: true}); res != nil { |
| 64 | common.ErrorStrResp(c, "file exists", 403) |
| 65 | return |
| 66 | } |
| 67 | } |
| 68 | dir, name := stdpath.Split(path) |
| 69 | // Check if system file should be ignored |
| 70 | if shouldIgnoreSystemFile(name) { |
| 71 | common.ErrorStrResp(c, errs.IgnoredSystemFile.Error(), 403) |
| 72 | return |
| 73 | } |
| 74 | // 如果请求头 Content-Length 和 X-File-Size 都没有,则 size=-1,表示未知大小的流式上传 |
| 75 | size := c.Request.ContentLength |
| 76 | if size < 0 { |
| 77 | sizeStr := c.GetHeader("X-File-Size") |
| 78 | if sizeStr != "" { |
| 79 | size, err = strconv.ParseInt(sizeStr, 10, 64) |
| 80 | if err != nil { |
| 81 | common.ErrorResp(c, err, 400) |
| 82 | return |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | h := make(map[*utils.HashType]string) |
| 87 | if md5 := c.GetHeader("X-File-Md5"); md5 != "" { |
| 88 | h[utils.MD5] = md5 |
| 89 | } |
| 90 | if sha1 := c.GetHeader("X-File-Sha1"); sha1 != "" { |
| 91 | h[utils.SHA1] = sha1 |
| 92 | } |
| 93 | if sha256 := c.GetHeader("X-File-Sha256"); sha256 != "" { |
| 94 | h[utils.SHA256] = sha256 |
| 95 | } |
| 96 | mimetype := c.GetHeader("Content-Type") |
| 97 | if len(mimetype) == 0 { |
| 98 | mimetype = utils.GetMimeType(name) |
nothing calls this directly
no test coverage detected