From b03879403ff1819365124535c295396bd13b9c9f Mon Sep 17 00:00:00 2001 From: Xi Wuuuuuuuuuuuu~~~~~~~~~~~~~~~ Date: Mon, 8 May 2023 15:19:51 +0800 Subject: [PATCH] feat(cloudreve): support use cookie to login (close #4324 in #4339) Co-authored-by: Andy Hsu --- drivers/cloudreve/driver.go | 1 - drivers/cloudreve/meta.go | 5 +++-- drivers/cloudreve/util.go | 12 +++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/cloudreve/driver.go b/drivers/cloudreve/driver.go index 0c9e7cb3..bb581d29 100644 --- a/drivers/cloudreve/driver.go +++ b/drivers/cloudreve/driver.go @@ -16,7 +16,6 @@ import ( type Cloudreve struct { model.Storage Addition - Cookie string } func (d *Cloudreve) Config() driver.Config { diff --git a/drivers/cloudreve/meta.go b/drivers/cloudreve/meta.go index f87c4c26..3c37c6d0 100644 --- a/drivers/cloudreve/meta.go +++ b/drivers/cloudreve/meta.go @@ -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{ diff --git a/drivers/cloudreve/util.go b/drivers/cloudreve/util.go index e2bb5b25..f4a37280 100644 --- a/drivers/cloudreve/util.go +++ b/drivers/cloudreve/util.go @@ -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")