Skip to content

Commit

Permalink
feat(upload): support rapid upload on web
Browse files Browse the repository at this point in the history
  • Loading branch information
KirCute committed Jan 20, 2025
1 parent 11b6a60 commit 6854db5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/alist_v3/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ func (d *AListV3) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
req.Header.Set("Authorization", d.Token)
req.Header.Set("File-Path", path.Join(dstDir.GetPath(), stream.GetName()))
req.Header.Set("Password", d.MetaPassword)
if md5 := stream.GetHash().GetHash(utils.MD5); len(md5) > 0 {
req.Header.Set("X-File-Md5", md5)
}
if sha1 := stream.GetHash().GetHash(utils.SHA1); len(sha1) > 0 {
req.Header.Set("X-File-Sha1", sha1)
}
if sha256 := stream.GetHash().GetHash(utils.SHA256); len(sha256) > 0 {
req.Header.Set("X-File-Sha256", sha256)
}

req.ContentLength = stream.GetSize()
// client := base.NewHttpClient()
Expand Down
23 changes: 23 additions & 0 deletions server/handles/fsup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handles

import (
"github.com/alist-org/alist/v3/internal/task"
"github.com/alist-org/alist/v3/pkg/utils"
"io"
"net/url"
stdpath "path"
Expand Down Expand Up @@ -55,11 +56,22 @@ func FsStream(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
h := make(map[*utils.HashType]string)
if md5 := c.GetHeader("X-File-Md5"); md5 != "" {
h[utils.MD5] = md5
}
if sha1 := c.GetHeader("X-File-Sha1"); sha1 != "" {
h[utils.SHA1] = sha1
}
if sha256 := c.GetHeader("X-File-Sha256"); sha256 != "" {
h[utils.SHA256] = sha256
}
s := &stream.FileStream{
Obj: &model.Object{
Name: name,
Size: size,
Modified: getLastModified(c),
HashInfo: utils.NewHashInfoByMap(h),
},
Reader: c.Request.Body,
Mimetype: c.GetHeader("Content-Type"),
Expand Down Expand Up @@ -128,11 +140,22 @@ func FsForm(c *gin.Context) {
}
defer f.Close()
dir, name := stdpath.Split(path)
h := make(map[*utils.HashType]string)
if md5 := c.GetHeader("X-File-Md5"); md5 != "" {
h[utils.MD5] = md5
}
if sha1 := c.GetHeader("X-File-Sha1"); sha1 != "" {
h[utils.SHA1] = sha1
}
if sha256 := c.GetHeader("X-File-Sha256"); sha256 != "" {
h[utils.SHA256] = sha256
}
s := stream.FileStream{
Obj: &model.Object{
Name: name,
Size: file.Size,
Modified: getLastModified(c),
HashInfo: utils.NewHashInfoByMap(h),
},
Reader: f,
Mimetype: file.Header.Get("Content-Type"),
Expand Down

0 comments on commit 6854db5

Please sign in to comment.