fix: allow no Last-Modified
on upload api
This commit is contained in:
parent
b301b791c7
commit
6c4736fc8f
@ -14,6 +14,17 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"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) {
|
func FsStream(c *gin.Context) {
|
||||||
path := c.GetHeader("File-Path")
|
path := c.GetHeader("File-Path")
|
||||||
path, err := url.PathUnescape(path)
|
path, err := url.PathUnescape(path)
|
||||||
@ -35,18 +46,11 @@ func FsStream(c *gin.Context) {
|
|||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
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{
|
s := &stream.FileStream{
|
||||||
Obj: &model.Object{
|
Obj: &model.Object{
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: size,
|
Size: size,
|
||||||
Modified: lastModified,
|
Modified: getLastModified(c),
|
||||||
},
|
},
|
||||||
Reader: c.Request.Body,
|
Reader: c.Request.Body,
|
||||||
Mimetype: c.GetHeader("Content-Type"),
|
Mimetype: c.GetHeader("Content-Type"),
|
||||||
@ -72,13 +76,6 @@ func FsForm(c *gin.Context) {
|
|||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
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"
|
asTask := c.GetHeader("As-Task") == "true"
|
||||||
user := c.MustGet("user").(*model.User)
|
user := c.MustGet("user").(*model.User)
|
||||||
path, err = user.JoinPath(path)
|
path, err = user.JoinPath(path)
|
||||||
@ -110,7 +107,7 @@ func FsForm(c *gin.Context) {
|
|||||||
Obj: &model.Object{
|
Obj: &model.Object{
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
Modified: lastModified,
|
Modified: getLastModified(c),
|
||||||
},
|
},
|
||||||
Reader: f,
|
Reader: f,
|
||||||
Mimetype: file.Header.Get("Content-Type"),
|
Mimetype: file.Header.Get("Content-Type"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user