mirror of https://github.com/Xhofe/alist
				
				
				
			feat(139): auto extract account from `Authorization`
							parent
							
								
									3bfa00d5d2
								
							
						
					
					
						commit
						a66b0e0151
					
				|  | @ -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, | ||||
|  |  | |||
|  | @ -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"` | ||||
|  |  | |||
|  | @ -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",
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Andy Hsu
						Andy Hsu