From a66b0e015168f73d1b24476fe7bb683538e40ae9 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Fri, 9 Jun 2023 23:41:41 +0800 Subject: [PATCH] feat(139): auto extract account from `Authorization` --- drivers/139/driver.go | 11 ++++++++++- drivers/139/meta.go | 2 +- drivers/139/util.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/139/driver.go b/drivers/139/driver.go index 27d1e30c13f..659e13aa96d 100644 --- a/drivers/139/driver.go +++ b/drivers/139/driver.go @@ -2,10 +2,12 @@ package _139 import ( "context" + "encoding/base64" "fmt" "io" "net/http" "strconv" + "strings" "github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/internal/driver" @@ -18,6 +20,7 @@ import ( type Yun139 struct { model.Storage Addition + Account string } func (d *Yun139) Config() driver.Config { @@ -29,7 +32,13 @@ func (d *Yun139) GetAddition() driver.Additional { } func (d *Yun139) Init(ctx context.Context) error { - _, err := d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{ + decode, err := base64.StdEncoding.DecodeString(d.Authorization) + if err != nil { + return err + } + decodeStr := string(decode) + d.Account = strings.Split(decodeStr, ":")[1] + _, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{ "qryUserExternInfoReq": base.Json{ "commonAccountInfo": base.Json{ "account": d.Account, diff --git a/drivers/139/meta.go b/drivers/139/meta.go index f154b4c5cf9..273ba14876d 100644 --- a/drivers/139/meta.go +++ b/drivers/139/meta.go @@ -6,7 +6,7 @@ import ( ) type Addition struct { - Account string `json:"account" required:"true"` + //Account string `json:"account" required:"true"` Authorization string `json:"authorization" type:"text" required:"true"` driver.RootID Type string `json:"type" type:"select" options:"personal,family" default:"personal"` diff --git a/drivers/139/util.go b/drivers/139/util.go index 5dcf8dca3e5..1ff53d6d261 100644 --- a/drivers/139/util.go +++ b/drivers/139/util.go @@ -72,7 +72,7 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba req.SetHeaders(map[string]string{ "Accept": "application/json, text/plain, */*", "CMS-DEVICE": "default", - "Authorization": d.Authorization, + "Authorization": "Basic " + d.Authorization, "mcloud-channel": "1000101", "mcloud-client": "10701", //"mcloud-route": "001",