feat(sftp): support range header
This commit is contained in:
@ -3,16 +3,13 @@ package smb
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/drivers/base"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/http_range"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
|
||||
"github.com/hirochachacha/go-smb2"
|
||||
@ -86,22 +83,7 @@ func (d *SMB) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*m
|
||||
link := &model.Link{
|
||||
Data: remoteFile,
|
||||
}
|
||||
if args.Header.Get("Range") != "" {
|
||||
r, err := http_range.ParseRange(args.Header.Get("Range"), file.GetSize())
|
||||
if err == nil && len(r) > 0 {
|
||||
_, err := remoteFile.Seek(r[0].Start, io.SeekStart)
|
||||
if err == nil {
|
||||
link.Data = utils.NewLimitReadCloser(remoteFile, func() error {
|
||||
return remoteFile.Close()
|
||||
}, r[0].Length)
|
||||
link.Status = 206
|
||||
link.Header = http.Header{
|
||||
"Content-Range": []string{r[0].ContentRange(file.GetSize())},
|
||||
"Content-Length": []string{strconv.FormatInt(r[0].Length, 10)},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
base.HandleRange(link, remoteFile, args.Header, file.GetSize())
|
||||
d.updateLastConnTime()
|
||||
return link, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user