Skip to content

Commit

Permalink
feat(139): auto extract account from Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 9, 2023
1 parent 3bfa00d commit a66b0e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion drivers/139/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,6 +20,7 @@ import (
type Yun139 struct {
model.Storage
Addition
Account string
}

func (d *Yun139) Config() driver.Config {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/139/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/139/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a66b0e0

Please sign in to comment.