diff --git a/drivers/teambition/driver.go b/drivers/teambition/driver.go index d4fcc401bad..c75d2ac00b6 100644 --- a/drivers/teambition/driver.go +++ b/drivers/teambition/driver.go @@ -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" ) @@ -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 diff --git a/drivers/teambition/help.go b/drivers/teambition/help.go new file mode 100644 index 00000000000..8581c3e827c --- /dev/null +++ b/drivers/teambition/help.go @@ -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 +} diff --git a/drivers/teambition/util.go b/drivers/teambition/util.go index c39ffb18286..79de7007c78 100644 --- a/drivers/teambition/util.go +++ b/drivers/teambition/util.go @@ -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 }