🎇 execute save while delete account

pull/548/head
微凉 2022-01-15 19:36:37 +08:00
parent 21ca2f11b7
commit 2473309a51
17 changed files with 60 additions and 6 deletions

View File

@ -65,6 +65,9 @@ func (driver Pan123) Items() []base.Item {
}
func (driver Pan123) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
if account.RootFolder == "" {
account.RootFolder = "0"
}

View File

@ -64,6 +64,9 @@ func (driver Cloud139) Items() []base.Item {
}
func (driver Cloud139) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
_, err := driver.Request("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Post, nil, nil, nil, base.Json{
"qryUserExternInfoReq": base.Json{
"commonAccountInfo": base.Json{

View File

@ -73,9 +73,12 @@ func (driver Cloud189) Items() []base.Item {
}
func (driver Cloud189) Save(account *model.Account, old *model.Account) error {
if old != nil && old.Name != account.Name {
if old != nil {
delete(client189Map, old.Name)
}
if account == nil {
return nil
}
if err := driver.Login(account); err != nil {
account.Status = err.Error()
_ = model.SaveAccount(account)

View File

@ -67,6 +67,9 @@ func (driver AliDrive) Save(account *model.Account, old *model.Account) error {
if old != nil {
conf.Cron.Remove(cron.EntryID(old.CronId))
}
if account == nil {
return nil
}
if account.RootFolder == "" {
account.RootFolder = "root"
}

View File

@ -48,6 +48,9 @@ func (driver Alist) Items() []base.Item {
}
func (driver Alist) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
account.SiteUrl = strings.TrimRight(account.SiteUrl, "/")
if account.RootFolder == "" {
account.RootFolder = "/"

View File

@ -61,6 +61,9 @@ func (driver FTP) Save(account *model.Account, old *model.Account) error {
delete(connMap, old.Name)
}
}
if account == nil {
return nil
}
if account.RootFolder == "" {
account.RootFolder = "/"
}

View File

@ -67,6 +67,9 @@ func (driver GoogleDrive) Items() []base.Item {
}
func (driver GoogleDrive) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
account.Proxy = true
err := driver.RefreshToken(account)
if err != nil {

View File

@ -53,6 +53,9 @@ func (driver Lanzou) Items() []base.Item {
}
func (driver Lanzou) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
if account.InternalType == "cookie" {
if account.RootFolder == "" {
account.RootFolder = "-1"

View File

@ -62,6 +62,9 @@ func (driver MediaTrack) Items() []base.Item {
}
func (driver MediaTrack) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
return nil
}

View File

@ -39,6 +39,9 @@ func (driver Native) Items() []base.Item {
}
func (driver Native) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
log.Debugf("save a account: [%s]", account.Name)
if !utils.Exists(account.RootFolder) {
account.Status = fmt.Sprintf("[%s] not exist", account.RootFolder)

View File

@ -92,13 +92,16 @@ func (driver Onedrive) Items() []base.Item {
}
func (driver Onedrive) Save(account *model.Account, old *model.Account) error {
if old != nil {
conf.Cron.Remove(cron.EntryID(old.CronId))
}
if account == nil {
return nil
}
_, ok := onedriveHostMap[account.Zone]
if !ok {
return fmt.Errorf("no [%s] zone", account.Zone)
}
if old != nil {
conf.Cron.Remove(cron.EntryID(old.CronId))
}
account.RootFolder = utils.ParsePath(account.RootFolder)
err := driver.RefreshToken(account)
if err != nil {

View File

@ -51,6 +51,9 @@ func (driver PikPak) Items() []base.Item {
}
func (driver PikPak) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
err := driver.Login(account)
return err
}

View File

@ -79,6 +79,9 @@ func (driver S3) Items() []base.Item {
}
func (driver S3) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
if account.Limit == 0 {
account.Limit = 4
}

View File

@ -48,6 +48,9 @@ func (driver Shandian) Items() []base.Item {
}
func (driver Shandian) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
if account.RootFolder == "" {
account.RootFolder = "0"
}

View File

@ -64,6 +64,9 @@ func (driver Teambition) Items() []base.Item {
}
func (driver Teambition) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
_, err := driver.Request("/api/v2/roles", base.Get, nil, nil, nil, nil, nil, account)
return err
}

View File

@ -45,6 +45,9 @@ func (driver WebDav) Items() []base.Item {
}
func (driver WebDav) Save(account *model.Account, old *model.Account) error {
if account == nil {
return nil
}
account.Status = "work"
_ = model.SaveAccount(account)
return nil

View File

@ -2,7 +2,8 @@ package model
import (
"github.com/Xhofe/alist/conf"
"github.com/robfig/cron/v3"
"github.com/Xhofe/alist/drivers/base"
log "github.com/sirupsen/logrus"
"time"
)
@ -71,7 +72,12 @@ func DeleteAccount(id uint) error {
return err
}
name := account.Name
conf.Cron.Remove(cron.EntryID(account.CronId))
driver, ok := base.GetDriver(account.Type)
if ok {
_ = driver.Save(nil, &account)
} else {
log.Errorf("no driver: %s", account.Type)
}
if err := conf.DB.Delete(&account).Error; err != nil {
return err
}