Skip to content

Commit

Permalink
fix(teambition): international upload (close #5360)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Nov 29, 2023
1 parent f4dcf45 commit b99e709
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
22 changes: 17 additions & 5 deletions drivers/teambition/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package teambition
import (
"context"
"errors"
"github.com/alist-org/alist/v3/pkg/utils"
"net/http"

"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/utils"
"github.com/go-resty/resty/v2"
)

Expand Down Expand Up @@ -128,11 +128,23 @@ func (d *Teambition) Put(ctx context.Context, dstDir model.Obj, stream model.Fil
if d.UseS3UploadMethod {
return d.newUpload(ctx, dstDir, stream, up)
}
res, err := d.request("/api/v2/users/me", http.MethodGet, nil, nil)
if err != nil {
return err
var (
token string
err error
)
if d.isInternational() {
res, err := d.request("/projects", http.MethodGet, nil, nil)
if err != nil {
return err
}
token = getBetweenStr(string(res), "strikerAuth":"", "","phoneForLogin")
} else {
res, err := d.request("/api/v2/users/me", http.MethodGet, nil, nil)
if err != nil {
return err
}
token = utils.Json.Get(res, "strikerAuth").ToString()
}
token := utils.Json.Get(res, "strikerAuth").ToString()
var newFile *FileUpload
if stream.GetSize() <= 20971520 {
// post upload
Expand Down
18 changes: 18 additions & 0 deletions drivers/teambition/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package teambition

import "strings"

func getBetweenStr(str, start, end string) string {
n := strings.Index(str, start)
if n == -1 {
return ""
}
n = n + len(start)
str = string([]byte(str)[n:])
m := strings.Index(str, end)
if m == -1 {
return ""
}
str = string([]byte(str)[:m])
return str
}
11 changes: 6 additions & 5 deletions drivers/teambition/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ func (d *Teambition) upload(ctx context.Context, file model.FileStreamer, token
prefix = "us-tcs"
}
var newFile FileUpload
_, err := base.RestyClient.R().
res, err := base.RestyClient.R().
SetContext(ctx).
SetResult(&newFile).SetHeader("Authorization", token).
SetMultipartFormData(map[string]string{
"name": file.GetName(),
"type": file.GetMimetype(),
"size": strconv.FormatInt(file.GetSize(), 10),
//"lastModifiedDate": "",
"name": file.GetName(),
"type": file.GetMimetype(),
"size": strconv.FormatInt(file.GetSize(), 10),
"lastModifiedDate": time.Now().Format("Mon Jan 02 2006 15:04:05 GMT+0800 (中国标准时间)"),
}).SetMultipartField("file", file.GetName(), file.GetMimetype(), file).
Post(fmt.Sprintf("https://%s.teambition.net/upload", prefix))
if err != nil {
return nil, err
}
log.Debugf("[teambition] upload response: %s", res.String())
return &newFile, nil
}

Expand Down

0 comments on commit b99e709

Please sign in to comment.