mirror of https://github.com/Xhofe/alist
				
				
				
			🚧 give up 189 family cloud
							parent
							
								
									10f06fde5c
								
							
						
					
					
						commit
						c03a4f83d1
					
				| 
						 | 
					@ -107,6 +107,10 @@ func (driver Cloud189) Login(account *model.Account) error {
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// 已经登陆
 | 
				
			||||||
 | 
							if res.StatusCode() == 302 {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		b = res.String()
 | 
							b = res.String()
 | 
				
			||||||
		ltTextArr := ltText.FindStringSubmatch(b)
 | 
							ltTextArr := ltText.FindStringSubmatch(b)
 | 
				
			||||||
		if len(ltTextArr) > 0 {
 | 
							if len(ltTextArr) > 0 {
 | 
				
			||||||
| 
						 | 
					@ -207,39 +211,32 @@ type Cloud189Files struct {
 | 
				
			||||||
	} `json:"fileListAO"`
 | 
						} `json:"fileListAO"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (driver Cloud189) isFamily(account *model.Account) bool {
 | 
				
			||||||
 | 
						return account.InternalType == "Family"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud189File, error) {
 | 
					func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud189File, error) {
 | 
				
			||||||
	client, ok := client189Map[account.Name]
 | 
					 | 
				
			||||||
	if !ok {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("can't find [%s] client", account.Name)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	res := make([]Cloud189File, 0)
 | 
						res := make([]Cloud189File, 0)
 | 
				
			||||||
	pageNum := 1
 | 
						pageNum := 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		var e Cloud189Error
 | 
					 | 
				
			||||||
		var resp Cloud189Files
 | 
							var resp Cloud189Files
 | 
				
			||||||
		_, err := client.R().SetResult(&resp).SetError(&e).
 | 
							body, err := driver.Request("https://cloud.189.cn/api/open/file/listFiles.action", base.Get, map[string]string{
 | 
				
			||||||
			SetHeader("Accept", "application/json;charset=UTF-8").
 | 
								//"noCache":    random(),
 | 
				
			||||||
			SetQueryParams(map[string]string{
 | 
								"pageSize":   "60",
 | 
				
			||||||
				"noCache":    random(),
 | 
								"pageNum":    strconv.Itoa(pageNum),
 | 
				
			||||||
				"pageSize":   "60",
 | 
								"mediaType":  "0",
 | 
				
			||||||
				"pageNum":    strconv.Itoa(pageNum),
 | 
								"folderId":   fileId,
 | 
				
			||||||
				"mediaType":  "0",
 | 
								"iconOption": "5",
 | 
				
			||||||
				"folderId":   fileId,
 | 
								"orderBy":    account.OrderBy,
 | 
				
			||||||
				"iconOption": "5",
 | 
								"descending": account.OrderDirection,
 | 
				
			||||||
				"orderBy":    account.OrderBy,
 | 
							}, nil, nil, account)
 | 
				
			||||||
				"descending": account.OrderDirection,
 | 
					 | 
				
			||||||
			}).Get("https://cloud.189.cn/api/open/file/listFiles.action")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if e.ErrorCode != "" {
 | 
							err = utils.Json.Unmarshal(body, &resp)
 | 
				
			||||||
			if e.ErrorCode == "InvalidSessionKey" {
 | 
							if err != nil {
 | 
				
			||||||
				err = driver.Login(account)
 | 
								return nil, err
 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					return nil, err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				return driver.GetFiles(fileId, account)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if resp.ResCode != 0 {
 | 
							if resp.ResCode != 0 {
 | 
				
			||||||
			return nil, fmt.Errorf(resp.ResMessage)
 | 
								return nil, fmt.Errorf(resp.ResMessage)
 | 
				
			||||||
| 
						 | 
					@ -261,18 +258,30 @@ func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud1
 | 
				
			||||||
	return res, nil
 | 
						return res, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (driver Cloud189) Request(url string, method string, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
 | 
					func (driver Cloud189) Request(url string, method int, query, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
 | 
				
			||||||
	client, ok := client189Map[account.Name]
 | 
						client, ok := client189Map[account.Name]
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return nil, fmt.Errorf("can't find [%s] client", account.Name)
 | 
							return nil, fmt.Errorf("can't find [%s] client", account.Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//var resp base.Json
 | 
						//var resp base.Json
 | 
				
			||||||
 | 
						if driver.isFamily(account) {
 | 
				
			||||||
 | 
							url = strings.Replace(url, "/api/open", "/api/open/family", 1)
 | 
				
			||||||
 | 
							if query != nil {
 | 
				
			||||||
 | 
								query["familyId"] = account.SiteId
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if form != nil {
 | 
				
			||||||
 | 
								form["familyId"] = account.SiteId
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	var e Cloud189Error
 | 
						var e Cloud189Error
 | 
				
			||||||
	req := client.R().SetError(&e).
 | 
						req := client.R().SetError(&e).
 | 
				
			||||||
		SetHeader("Accept", "application/json;charset=UTF-8").
 | 
							SetHeader("Accept", "application/json;charset=UTF-8").
 | 
				
			||||||
		SetQueryParams(map[string]string{
 | 
							SetQueryParams(map[string]string{
 | 
				
			||||||
			"noCache": random(),
 | 
								"noCache": random(),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
						if query != nil {
 | 
				
			||||||
 | 
							req = req.SetQueryParams(query)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if form != nil {
 | 
						if form != nil {
 | 
				
			||||||
		req = req.SetFormData(form)
 | 
							req = req.SetFormData(form)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -281,24 +290,27 @@ func (driver Cloud189) Request(url string, method string, form map[string]string
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	var res *resty.Response
 | 
						var res *resty.Response
 | 
				
			||||||
	if strings.ToUpper(method) == "GET" {
 | 
						switch method {
 | 
				
			||||||
 | 
						case base.Get:
 | 
				
			||||||
		res, err = req.Get(url)
 | 
							res, err = req.Get(url)
 | 
				
			||||||
	} else {
 | 
						case base.Post:
 | 
				
			||||||
		res, err = req.Post(url)
 | 
							res, err = req.Post(url)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return nil, base.ErrNotSupport
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						log.Debug(res.String())
 | 
				
			||||||
	if e.ErrorCode != "" {
 | 
						if e.ErrorCode != "" {
 | 
				
			||||||
		if e.ErrorCode == "InvalidSessionKey" {
 | 
							if e.ErrorCode == "InvalidSessionKey" {
 | 
				
			||||||
			err = driver.Login(account)
 | 
								err = driver.Login(account)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return driver.Request(url, method, form, nil, account)
 | 
								return driver.Request(url, method, query, form, nil, account)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//log.Debug(res, jsoniter.Get(res.Body(),"res_code").ToInt())
 | 
					 | 
				
			||||||
	if jsoniter.Get(res.Body(), "res_code").ToInt() != 0 {
 | 
						if jsoniter.Get(res.Body(), "res_code").ToInt() != 0 {
 | 
				
			||||||
		err = errors.New(jsoniter.Get(res.Body(), "res_message").ToString())
 | 
							err = errors.New(jsoniter.Get(res.Body(), "res_message").ToString())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -306,7 +318,7 @@ func (driver Cloud189) Request(url string, method string, form map[string]string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (driver Cloud189) GetSessionKey(account *model.Account) (string, error) {
 | 
					func (driver Cloud189) GetSessionKey(account *model.Account) (string, error) {
 | 
				
			||||||
	resp, err := driver.Request("https://cloud.189.cn/v2/getUserBriefInfo.action", "GET", nil, nil, account)
 | 
						resp, err := driver.Request("https://cloud.189.cn/v2/getUserBriefInfo.action", base.Get, nil, nil, nil, account)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -314,7 +326,7 @@ func (driver Cloud189) GetSessionKey(account *model.Account) (string, error) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (driver Cloud189) GetResKey(account *model.Account) (string, string, error) {
 | 
					func (driver Cloud189) GetResKey(account *model.Account) (string, string, error) {
 | 
				
			||||||
	resp, err := driver.Request("https://cloud.189.cn/api/security/generateRsaKey.action", "GET", nil, nil, account)
 | 
						resp, err := driver.Request("https://cloud.189.cn/api/security/generateRsaKey.action", base.Get, nil, nil, nil, account)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", "", err
 | 
							return "", "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,18 @@ func (driver Cloud189) Items() []base.Item {
 | 
				
			||||||
			Type:     base.TypeString,
 | 
								Type:     base.TypeString,
 | 
				
			||||||
			Required: true,
 | 
								Required: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							//{
 | 
				
			||||||
 | 
							//	Name:     "internal_type",
 | 
				
			||||||
 | 
							//	Label:    "189cloud type",
 | 
				
			||||||
 | 
							//	Type:     base.TypeSelect,
 | 
				
			||||||
 | 
							//	Required: true,
 | 
				
			||||||
 | 
							//	Values:   "Personal,Family",
 | 
				
			||||||
 | 
							//},
 | 
				
			||||||
 | 
							//{
 | 
				
			||||||
 | 
							//	Name:  "site_id",
 | 
				
			||||||
 | 
							//	Label: "family id",
 | 
				
			||||||
 | 
							//	Type:  base.TypeString,
 | 
				
			||||||
 | 
							//},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Name:     "order_by",
 | 
								Name:     "order_by",
 | 
				
			||||||
			Label:    "order_by",
 | 
								Label:    "order_by",
 | 
				
			||||||
| 
						 | 
					@ -144,29 +156,17 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
 | 
				
			||||||
	if file.Type == conf.FOLDER {
 | 
						if file.Type == conf.FOLDER {
 | 
				
			||||||
		return nil, base.ErrNotFile
 | 
							return nil, base.ErrNotFile
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	client, ok := client189Map[account.Name]
 | 
					 | 
				
			||||||
	if !ok {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("can't find [%s] client", account.Name)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	var e Cloud189Error
 | 
					 | 
				
			||||||
	var resp Cloud189Down
 | 
						var resp Cloud189Down
 | 
				
			||||||
	_, err = client.R().SetResult(&resp).SetError(&e).
 | 
						u := "https://cloud.189.cn/api/open/file/getFileDownloadUrl.action"
 | 
				
			||||||
		SetHeader("Accept", "application/json;charset=UTF-8").
 | 
						body, err := driver.Request(u, base.Get, map[string]string{
 | 
				
			||||||
		SetQueryParams(map[string]string{
 | 
							"fileId": file.Id,
 | 
				
			||||||
			"noCache": random(),
 | 
						}, nil, nil, account)
 | 
				
			||||||
			"fileId":  file.Id,
 | 
					 | 
				
			||||||
		}).Get("https://cloud.189.cn/api/open/file/getFileDownloadUrl.action")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if e.ErrorCode != "" {
 | 
						err = utils.Json.Unmarshal(body, &resp)
 | 
				
			||||||
		if e.ErrorCode == "InvalidSessionKey" {
 | 
						if err != nil {
 | 
				
			||||||
			err = driver.Login(account)
 | 
							return nil, err
 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return nil, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return driver.Link(args, account)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if resp.ResCode != 0 {
 | 
						if resp.ResCode != 0 {
 | 
				
			||||||
		return nil, fmt.Errorf(resp.ResMessage)
 | 
							return nil, fmt.Errorf(resp.ResMessage)
 | 
				
			||||||
| 
						 | 
					@ -222,7 +222,7 @@ func (driver Cloud189) MakeDir(path string, account *model.Account) error {
 | 
				
			||||||
		"parentFolderId": parent.Id,
 | 
							"parentFolderId": parent.Id,
 | 
				
			||||||
		"folderName":     name,
 | 
							"folderName":     name,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", "POST", form, nil, account)
 | 
						_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", base.Post, nil, form, nil, account)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -256,7 +256,7 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
 | 
				
			||||||
		"targetFolderId": dstDirFile.Id,
 | 
							"targetFolderId": dstDirFile.Id,
 | 
				
			||||||
		"taskInfos":      string(taskInfosBytes),
 | 
							"taskInfos":      string(taskInfosBytes),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
 | 
						_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -278,7 +278,7 @@ func (driver Cloud189) Rename(src string, dst string, account *model.Account) er
 | 
				
			||||||
		idKey:   srcFile.Id,
 | 
							idKey:   srcFile.Id,
 | 
				
			||||||
		nameKey: dstName,
 | 
							nameKey: dstName,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = driver.Request(url, "POST", form, nil, account)
 | 
						_, err = driver.Request(url, base.Post, nil, form, nil, account)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -312,7 +312,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
 | 
				
			||||||
		"targetFolderId": dstDirFile.Id,
 | 
							"targetFolderId": dstDirFile.Id,
 | 
				
			||||||
		"taskInfos":      string(taskInfosBytes),
 | 
							"taskInfos":      string(taskInfosBytes),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
 | 
						_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -342,7 +342,7 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
 | 
				
			||||||
		"targetFolderId": "",
 | 
							"targetFolderId": "",
 | 
				
			||||||
		"taskInfos":      string(taskInfosBytes),
 | 
							"taskInfos":      string(taskInfosBytes),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
 | 
						_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue