mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 20:26:26 +08:00
fix(115open) fixed rate_limit bugs (#161)
* fixed 115 bugs Signed-off-by: Suyunmeng <sumengjing@outlook.com> * Fixed 115 open bugs * fixed bugs --------- Signed-off-by: Suyunmeng <sumengjing@outlook.com>
This commit is contained in:
@ -11,9 +11,7 @@ type Addition struct {
|
|||||||
// define other
|
// define other
|
||||||
OrderBy string `json:"order_by" type:"select" options:"file_name,file_size,user_utime,file_type"`
|
OrderBy string `json:"order_by" type:"select" options:"file_name,file_size,user_utime,file_type"`
|
||||||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"`
|
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"`
|
||||||
LimitRate float64 `json:"limit_rate" type:"float" default:"1" help:"limit all api request rate ([limit]r/1s)"`
|
LimitRate float64 `json:"limit_rate,string" type:"float" default:"1" help:"limit all api request rate ([limit]r/1s)"`
|
||||||
UseOnlineAPI bool `json:"use_online_api" default:"true"`
|
|
||||||
APIAddress string `json:"api_url_address" default:"https://api.oplist.org/115cloud/renewapi"`
|
|
||||||
AccessToken string `json:"access_token" required:"true"`
|
AccessToken string `json:"access_token" required:"true"`
|
||||||
RefreshToken string `json:"refresh_token" required:"true"`
|
RefreshToken string `json:"refresh_token" required:"true"`
|
||||||
}
|
}
|
||||||
|
@ -1,49 +1,3 @@
|
|||||||
package _115_open
|
package _115_open
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/OpenListTeam/OpenList/drivers/base"
|
|
||||||
"github.com/OpenListTeam/OpenList/internal/errs"
|
|
||||||
"github.com/OpenListTeam/OpenList/internal/op"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (d *Open115) refreshToken() error {
|
|
||||||
err := d._refreshToken()
|
|
||||||
if err != nil && errors.Is(err, errs.EmptyToken) {
|
|
||||||
err = d._refreshToken()
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Open115) _refreshToken() error {
|
|
||||||
// 使用在线API刷新Token,无需ClientID和ClientSecret
|
|
||||||
if d.Addition.UseOnlineAPI && len(d.Addition.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.Addition.RefreshToken,
|
|
||||||
"server_use": "true",
|
|
||||||
"driver_txt": "115cloud_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
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// do others that not defined in Driver interface
|
// do others that not defined in Driver interface
|
Reference in New Issue
Block a user