Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions drivers/189pc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,35 @@ func (y *Cloud189PC) Rename(ctx context.Context, srcObj model.Obj, newName strin
queryParam["familyId"] = y.FamilyID
}

var newObj model.Obj
switch f := srcObj.(type) {
switch srcObj.(type) {
case *Cloud189File:
fullUrl += "/renameFile.action"
queryParam["fileId"] = srcObj.GetID()
queryParam["destFileName"] = newName
newObj = &Cloud189File{Icon: f.Icon} // 复用预览
case *Cloud189Folder:
fullUrl += "/renameFolder.action"
queryParam["folderId"] = srcObj.GetID()
queryParam["destFolderName"] = newName
newObj = &Cloud189Folder{}
default:
return nil, errs.NotSupport
}

var resp RenameResp
_, err := y.request(fullUrl, method, func(req *resty.Request) {
req.SetContext(ctx).SetQueryParams(queryParam)
}, nil, newObj, isFamily)
}, nil, resp, isFamily)
if err != nil {
if resp.ResCode == "FileAlreadyExists" {
return nil, errs.ObjectAlreadyExists
}
return nil, err
}
return newObj, nil
switch f := srcObj.(type) {
case *Cloud189File:
return resp.toFile(f), nil
case *Cloud189Folder:
return resp.toFolder(), nil
}
return nil, errs.NotSupport
}

func (y *Cloud189PC) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
Expand Down
38 changes: 38 additions & 0 deletions drivers/189pc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,41 @@ type CapacityResp struct {
} `json:"familyCapacityInfo"`
TotalSize uint64 `json:"totalSize"`
}

type RenameResp struct {
ResMsg string `json:"res_message"`
CreateDate Time `json:"createDate"`
FileCate int `json:"fileCata"`
ID string `json:"id"`
LastOpTime Time `json:"lastOpTime"`
MD5 string `json:"md5"`
MediaType int `json:"mediaType"`
Name string `json:"name"`
Oeientation int `json:"orientation"`
ParentID int64 `json:"parentId"`
Rev string `json:"rev"`
Size int64 `json:"size"`
ResCode string `json:"res_code"`
}

func (r *RenameResp) toFile(f *Cloud189File) *Cloud189File {
return &Cloud189File{
ID: String(r.ID),
Name: r.Name,
Size: r.Size,
Md5: r.MD5,
LastOpTime: r.LastOpTime,
CreateDate: r.CreateDate,
Icon: f.Icon,
}
}

func (r *RenameResp) toFolder() *Cloud189Folder {
return &Cloud189Folder{
ID: String(r.ID),
Name: r.Name,
ParentID: r.ParentID,
LastOpTime: r.LastOpTime,
CreateDate: r.CreateDate,
}
}
14 changes: 7 additions & 7 deletions drivers/cloudflare_imgbed/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
)

type Addition struct {
driver.RootPath
Address string `json:"address" type:"text" required:"true" help:"图床后端 API 地址,例如 https://img.example.com"`
Token string `json:"token" type:"text" required:"true" help:"身份认证 Token"`
SmallChannelName string `json:"smallChannelName" type:"text" help:"普通文件(通常<20MB)上传使用的渠道名称"`
LargeChannelName string `json:"largeChannelName" type:"text" help:"大文件上传使用的渠道名称"`
LargeChannelType string `json:"largeChannelType" type:"select" options:",huggingface" help:"大文件渠道的特殊类型(如需直传 HuggingFace,请选 huggingface)"`
UploadThread int `json:"uploadThread" type:"number" default:"3" help:"HuggingFace 分片直传时的并发线程数"`
driver.RootPath
Address string `json:"address" type:"text" required:"true" help:"Backend API address of the image hosting service, e.g., https://img.example.com"`
Token string `json:"token" type:"text" required:"true" help:"Authentication Token"`
SmallChannelName string `json:"smallChannelName" type:"text" help:"Channel name for regular files (typically <20MB)"`
LargeChannelName string `json:"largeChannelName" type:"text" help:"Channel name for large files"`
LargeChannelType string `json:"largeChannelType" type:"select" options:",huggingface" help:"Special type for large file channels (select 'huggingface' for direct upload to HuggingFace)"`
UploadThread int `json:"uploadThread" type:"number" default:"3" help:"Concurrent thread count for HuggingFace chunked direct upload"`
}

var config = driver.Config{
Expand Down
4 changes: 4 additions & 0 deletions drivers/cloudreve_v4/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
CodeLoginRequired = http.StatusUnauthorized
CodePathNotExist = 40016 // Path not exist
CodeCredentialInvalid = 40020 // Failed to issue token
CodeObjectExisted = 40004 // Object existed
// IncorrectSharePassword = 40069 // Incorrect share password
)

Expand Down Expand Up @@ -107,6 +108,9 @@ func (d *CloudreveV4) _request(method string, path string, callback base.ReqCall
if r.Code == CodePathNotExist {
return errs.ObjectNotFound
}
if r.Code == CodeObjectExisted {
return errs.ObjectAlreadyExists
}
return fmt.Errorf("%d: %s", r.Code, r.Msg)
}

Expand Down
5 changes: 2 additions & 3 deletions drivers/lenovonas_share/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
stdpath "path"
"strings"
"time"

Expand Down Expand Up @@ -32,6 +33,7 @@ func (d *LenovoNasShare) GetAddition() driver.Additional {
}

func (d *LenovoNasShare) Init(ctx context.Context) error {
d.ShareId = stdpath.Base(d.ShareId)
if err := d.getStoken(); err != nil {
return err
}
Expand Down Expand Up @@ -98,9 +100,6 @@ func (d *LenovoNasShare) getStoken() error { // 获取stoken
d.Host = "https://siot-share.lenovo.com.cn"
}

parts := strings.Split(d.ShareId, "/")
d.ShareId = parts[len(parts)-1]

query := map[string]string{
"code": d.ShareId,
"password": d.SharePwd,
Expand Down
5 changes: 4 additions & 1 deletion drivers/quark_uc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ func (d *QuarkOrUC) MakeDir(ctx context.Context, parentDir model.Obj, dirName st
_, err := d.request("/file", http.MethodPost, func(req *resty.Request) {
req.SetBody(data)
}, nil)
if err == nil {
if err == nil || err.Error() == "file is doloading[同名冲突]" {
time.Sleep(time.Second)
}
if err != nil && err.Error() == "file is doloading[同名冲突]" {
return errs.ObjectAlreadyExists
}
return err
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/strm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (d *Strm) Init(ctx context.Context) error {
return errors.New("SaveStrmLocalPath is required")
}
d.pathMap = make(map[string][]string)
for _, path := range strings.Split(d.Paths, "\n") {
for path := range strings.SplitSeq(d.Paths, "\n") {
path = strings.TrimSpace(path)
if path == "" {
continue
Expand Down Expand Up @@ -97,17 +97,17 @@ func (d *Strm) Init(ctx context.Context) error {
}

if d.Version != 5 {
types := strings.Split("mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac", ",")
for _, ext := range types {
types := strings.SplitSeq("mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac", ",")
for ext := range types {
if _, ok := d.supportSuffix[ext]; !ok {
d.supportSuffix[ext] = struct{}{}
supportTypes = append(supportTypes, ext)
}
}
d.FilterFileTypes = strings.Join(supportTypes, ",")

types = strings.Split("ass,srt,vtt,sub,strm", ",")
for _, ext := range types {
types = strings.SplitSeq("ass,srt,vtt,sub,strm", ",")
for ext := range types {
if _, ok := d.downloadSuffix[ext]; !ok {
d.downloadSuffix[ext] = struct{}{}
downloadTypes = append(downloadTypes, ext)
Expand All @@ -127,7 +127,7 @@ func (d *Strm) Drop(ctx context.Context) error {
d.pathMap = nil
d.downloadSuffix = nil
d.supportSuffix = nil
for _, path := range strings.Split(d.Paths, "\n") {
for path := range strings.SplitSeq(d.Paths, "\n") {
RemoveStrm(utils.FixAndCleanPath(strings.TrimSpace(path)), d)
}
return nil
Expand Down
7 changes: 2 additions & 5 deletions drivers/url_tree/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import (
*/
// if there are no name, use the last segment of url as name
func BuildTree(text string, headSize bool) (*Node, error) {
lines := strings.Split(text, "\n")
var root = &Node{Level: -1, Name: "root"}
stack := []*Node{root}
for _, line := range lines {
for line := range strings.SplitSeq(text, "\n") {
// calculate indent
indent := 0
for i := 0; i < len(line); i++ {
Expand Down Expand Up @@ -153,9 +152,7 @@ func splitPath(path string) []string {
if path == "/" {
return []string{"root"}
}
if strings.HasSuffix(path, "/") {
path = path[:len(path)-1]
}
path = strings.TrimSuffix(path, "/")
parts := strings.Split(path, "/")
parts[0] = "root"
return parts
Expand Down
3 changes: 1 addition & 2 deletions drivers/webdav/odrvcookie/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ func getLoginUrl(endpoint string) (string, error) {
if err != nil {
return "", err
}
domains := strings.Split(spRoot.Host, ".")
tld := domains[len(domains)-1]
tld := spRoot.Host[strings.LastIndex(spRoot.Host, ".")+1:]
loginUrl, ok := loginUrlsMap[tld]
if !ok {
return "", fmt.Errorf("tld %s is not supported", tld)
Expand Down
4 changes: 2 additions & 2 deletions internal/archive/iso9660/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func getObj(img *iso9660.Image, path string) (*iso9660.File, error) {
if path == "/" {
return obj, nil
}
paths := strings.Split(strings.TrimPrefix(path, "/"), "/")
for _, p := range paths {
paths := strings.SplitSeq(strings.TrimPrefix(path, "/"), "/")
for p := range paths {
if !obj.IsDir() {
return nil, errs.ObjectNotFound
}
Expand Down
4 changes: 4 additions & 0 deletions internal/errs/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ var (
func IsObjectNotFound(err error) bool {
return errors.Is(pkgerr.Cause(err), ObjectNotFound)
}

func IsObjectAlreadyExists(err error) bool {
return errors.Is(pkgerr.Cause(err), ObjectAlreadyExists)
}
19 changes: 8 additions & 11 deletions internal/net/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"io"
"net/http"
stdpath "path"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -490,30 +490,27 @@ func (d *downloader) checkTotalBytes(resp *http.Response) error {
totalBytes = resp.ContentLength
}
} else {
parts := strings.Split(contentRange, "/")

total := int64(-1)

// Checking for whether a numbered total exists
// If one does not exist, we will assume the total to be -1, undefined,
// and sequentially download each chunk until hitting a 416 error
totalStr := parts[len(parts)-1]

totalStr := stdpath.Base(contentRange)
if totalStr != "*" {
total, err = strconv.ParseInt(totalStr, 10, 64)
if err != nil {
err = fmt.Errorf("failed extracting file size")
if total, err := strconv.ParseInt(totalStr, 10, 64); err != nil {
err = fmt.Errorf("failed extracting file size: %s", totalStr)
} else {
totalBytes = total
}
} else {
err = fmt.Errorf("file size unknown")
err = fmt.Errorf("file size unknown: %s", contentRange)
}

totalBytes = total
}
if totalBytes != d.params.Size && err == nil {
err = fmt.Errorf("expect file size=%d unmatch remote report size=%d, need refresh cache", d.params.Size, totalBytes)
}
if err != nil {
// _ = d.interrupt()
d.setErr(err)
d.cancel(err)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func list(ctx context.Context, storage driver.Driver, path string, args model.Li

customCachePolicies := storage.GetStorage().CustomCachePolicies
if len(customCachePolicies) > 0 {
configPolicies := strings.Split(customCachePolicies, "\n")
for _, configPolicy := range configPolicies {
for configPolicy := range strings.SplitSeq(customCachePolicies, "\n") {
pattern, ttlstr, ok := strings.Cut(strings.TrimSpace(configPolicy), ":")
if !ok {
log.Warnf("Malformed custom cache policy entry: %s in storage %s for path %s. Expected format: pattern:ttl", configPolicy, storage.GetStorage().MountPath, path)
Expand Down Expand Up @@ -330,6 +329,9 @@ func MakeDir(ctx context.Context, storage driver.Driver, path string) error {
if err != nil {
return nil, errors.WithMessagef(err, "failed to get parent dir [%s]", parentPath)
}
if !parentDir.IsDir() {
return nil, errs.NotFolder
}
if model.ObjHasMask(parentDir, model.NoWrite) {
return nil, errors.WithStack(errs.PermissionDenied)
}
Expand All @@ -343,7 +345,7 @@ func MakeDir(ctx context.Context, storage driver.Driver, path string) error {
default:
return nil, errs.NotImplement
}
if err != nil {
if err != nil && !errs.IsObjectAlreadyExists(err) {
return nil, errors.WithStack(err)
}
if storage.Config().NoCache {
Expand Down Expand Up @@ -640,7 +642,7 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file mod
}
}
err = MakeDir(ctx, storage, dstDirPath)
if err != nil {
if err != nil && !errs.IsObjectAlreadyExists(err) {
return errors.WithMessagef(err, "failed to make dir [%s]", dstDirPath)
}
parentDir, err := GetUnwrap(ctx, storage, dstDirPath)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gowebdav/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) {
return nil
}
if status == 409 {
paths := strings.Split(path, "/")
paths := strings.SplitSeq(path, "/")
sub := "/"
for _, e := range paths {
for e := range paths {
if e == "" {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/gowebdav/digestAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func digestParts(resp *http.Response) map[string]string {
result := map[string]string{}
if len(resp.Header["Www-Authenticate"]) > 0 {
wantedHeaders := []string{"nonce", "realm", "qop", "opaque", "algorithm", "entityBody"}
responseHeaders := strings.Split(resp.Header["Www-Authenticate"][0], ",")
for _, r := range responseHeaders {
responseHeaders := strings.SplitSeq(resp.Header["Www-Authenticate"][0], ",")
for r := range responseHeaders {
for _, w := range wantedHeaders {
if strings.Contains(r, w) {
result[w] = strings.Trim(
Expand Down
8 changes: 4 additions & 4 deletions pkg/http_range/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ func ParseRange(s string, size int64) ([]Range, error) { // nolint:gocognit
}
var ranges []Range
noOverlap := false
for _, ra := range strings.Split(s[len(b):], ",") {
for ra := range strings.SplitSeq(s[len(b):], ",") {
ra = textproto.TrimString(ra)
if ra == "" {
continue
}
i := strings.Index(ra, "-")
if i < 0 {
before, after, ok := strings.Cut(ra, "-")
if !ok {
return nil, ErrInvalid
}
start, end := textproto.TrimString(ra[:i]), textproto.TrimString(ra[i+1:])
start, end := textproto.TrimString(before), textproto.TrimString(after)
var r Range
if start == "" {
// If no start is specified, end specifies the
Expand Down
Loading
Loading