mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 04:06:18 +08:00
chore(api):Add online api refresh method (#143)
* Add Official API Refresh Interface(Baiduyun) * add UseOnlineAPI & APIAddress add _refreshToken using APIAddress * fix return * Modify the frontend display using the default API refresh method * Fixed display and operation related issues * fixed aliyundrive_open old refresh --------- Co-authored-by: Suyunmeng <sumengjing@outlook.com>
This commit is contained in:
@ -10,8 +10,10 @@ type Addition struct {
|
||||
OrderBy string `json:"order_by" type:"select" options:"name,path,created,modified,size" default:"name"`
|
||||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
|
||||
driver.RootPath
|
||||
ClientID string `json:"client_id" required:"true" default:"a78d5a69054042fa936f6c77f9a0ae8b"`
|
||||
ClientSecret string `json:"client_secret" required:"true" default:"9c119bbb04b346d2a52aa64401936b2b"`
|
||||
UseOnlineAPI bool `json:"use_online_api" default:"true"`
|
||||
APIAddress string `json:"api_url_address" default:"https://api.oplist.org/yandexui/renewapi"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
|
@ -14,6 +14,37 @@ import (
|
||||
// do others that not defined in Driver interface
|
||||
|
||||
func (d *YandexDisk) refreshToken() error {
|
||||
// 使用在线API刷新Token,无需ClientID和ClientSecret
|
||||
if d.UseOnlineAPI && len(d.APIAddress) > 0 {
|
||||
u := d.APIAddress
|
||||
var resp struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
_, err := base.RestyClient.R().
|
||||
SetResult(&resp).
|
||||
SetQueryParams(map[string]string{
|
||||
"refresh_ui": d.RefreshToken,
|
||||
"server_use": "true",
|
||||
"driver_txt": "yandexui_go",
|
||||
}).
|
||||
Get(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.RefreshToken == "" || resp.AccessToken == "" {
|
||||
return fmt.Errorf("empty token returned from official API")
|
||||
}
|
||||
d.AccessToken = resp.AccessToken
|
||||
d.RefreshToken = resp.RefreshToken
|
||||
op.MustSaveDriverStorage(d)
|
||||
return nil
|
||||
}
|
||||
// 使用本地客户端的情况下检查是否为空
|
||||
if d.ClientID == "" || d.ClientSecret == "" {
|
||||
return fmt.Errorf("empty ClientID or ClientSecret")
|
||||
}
|
||||
// 走原有的刷新逻辑
|
||||
u := "https://oauth.yandex.com/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenErrResp
|
||||
|
Reference in New Issue
Block a user