feat(upload): support rapid upload on web (#7851)

pull/7859/merge
KirCute_ECT 2025-01-27 20:20:09 +08:00 committed by GitHub
parent d5ec998699
commit 5eff8cc7bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -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("Authorization", d.Token)
req.Header.Set("File-Path", path.Join(dstDir.GetPath(), stream.GetName())) req.Header.Set("File-Path", path.Join(dstDir.GetPath(), stream.GetName()))
req.Header.Set("Password", d.MetaPassword) 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() req.ContentLength = stream.GetSize()
// client := base.NewHttpClient() // client := base.NewHttpClient()

View File

@ -2,6 +2,7 @@ package handles
import ( import (
"github.com/alist-org/alist/v3/internal/task" "github.com/alist-org/alist/v3/internal/task"
"github.com/alist-org/alist/v3/pkg/utils"
"io" "io"
"net/url" "net/url"
stdpath "path" stdpath "path"
@ -55,11 +56,22 @@ func FsStream(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return 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{ s := &stream.FileStream{
Obj: &model.Object{ Obj: &model.Object{
Name: name, Name: name,
Size: size, Size: size,
Modified: getLastModified(c), Modified: getLastModified(c),
HashInfo: utils.NewHashInfoByMap(h),
}, },
Reader: c.Request.Body, Reader: c.Request.Body,
Mimetype: c.GetHeader("Content-Type"), Mimetype: c.GetHeader("Content-Type"),
@ -128,11 +140,22 @@ func FsForm(c *gin.Context) {
} }
defer f.Close() defer f.Close()
dir, name := stdpath.Split(path) 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{ s := stream.FileStream{
Obj: &model.Object{ Obj: &model.Object{
Name: name, Name: name,
Size: file.Size, Size: file.Size,
Modified: getLastModified(c), Modified: getLastModified(c),
HashInfo: utils.NewHashInfoByMap(h),
}, },
Reader: f, Reader: f,
Mimetype: file.Header.Get("Content-Type"), Mimetype: file.Header.Get("Content-Type"),