Skip to content

Commit

Permalink
fix: allow no Last-Modified on upload api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 28, 2023
1 parent b301b79 commit 6c4736f
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions server/handles/fsup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import (
"github.com/gin-gonic/gin"
)

func getLastModified(c *gin.Context) time.Time {
now := time.Now()
lastModifiedStr := c.GetHeader("Last-Modified")
lastModifiedMillisecond, err := strconv.ParseInt(lastModifiedStr, 10, 64)
if err != nil {
return now
}
lastModified := time.UnixMilli(lastModifiedMillisecond)
return lastModified
}

func FsStream(c *gin.Context) {
path := c.GetHeader("File-Path")
path, err := url.PathUnescape(path)
Expand All @@ -35,18 +46,11 @@ func FsStream(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
lastModifiedStr := c.GetHeader("Last-Modified")
lastModifiedMillisecond, err := strconv.ParseInt(lastModifiedStr, 10, 64)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
lastModified := time.UnixMilli(lastModifiedMillisecond)
s := &stream.FileStream{
Obj: &model.Object{
Name: name,
Size: size,
Modified: lastModified,
Modified: getLastModified(c),
},
Reader: c.Request.Body,
Mimetype: c.GetHeader("Content-Type"),
Expand All @@ -72,13 +76,6 @@ func FsForm(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
lastModifiedStr := c.GetHeader("Last-Modified")
lastModifiedMillisecond, err := strconv.ParseInt(lastModifiedStr, 10, 64)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
lastModified := time.UnixMilli(lastModifiedMillisecond)
asTask := c.GetHeader("As-Task") == "true"
user := c.MustGet("user").(*model.User)
path, err = user.JoinPath(path)
Expand Down Expand Up @@ -110,7 +107,7 @@ func FsForm(c *gin.Context) {
Obj: &model.Object{
Name: name,
Size: file.Size,
Modified: lastModified,
Modified: getLastModified(c),
},
Reader: f,
Mimetype: file.Header.Get("Content-Type"),
Expand Down

0 comments on commit 6c4736f

Please sign in to comment.