feat(cloudreve): support use cookie to login (close #4324 in #4339)

Co-authored-by: Andy Hsu <i@nn.ci>
pull/4341/head
Xi Wuuuuuuuuuuuu~~~~~~~~~~~~~~~ 2023-05-08 15:19:51 +08:00 committed by GitHub
parent ee4ac81677
commit b03879403f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -16,7 +16,6 @@ import (
type Cloudreve struct {
model.Storage
Addition
Cookie string
}
func (d *Cloudreve) Config() driver.Config {

View File

@ -10,8 +10,9 @@ type Addition struct {
driver.RootPath
// define other
Address string `json:"address" required:"true"`
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
Username string `json:"username"`
Password string `json:"password"`
Cookie string `json:"cookie"`
}
var config = driver.Config{

View File

@ -49,13 +49,15 @@ func (d *Cloudreve) request(method string, path string, callback base.ReqCallbac
// 刷新 cookie
if r.Code == http.StatusUnauthorized && path != loginPath {
err = d.login()
if err != nil {
return err
if d.Username != "" && d.Password != "" {
err = d.login()
if err != nil {
return err
}
return d.request(method, path, callback, out)
}
return d.request(method, path, callback, out)
}
return errors.New(r.Msg)
}
sess := cookie.GetCookie(resp.Cookies(), "cloudreve-session")