From e4d254e4b005d1c0d784b13b6e66ed3deee6bade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Wed, 17 Nov 2021 15:25:31 +0800 Subject: [PATCH] :sparkles: simplify delete account when change name --- drivers/189.go | 1 - drivers/alidrive.go | 3 --- drivers/native.go | 3 --- drivers/onedrive.go | 3 --- server/account.go | 3 +++ 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/189.go b/drivers/189.go index 2eafde1b..768fe772 100644 --- a/drivers/189.go +++ b/drivers/189.go @@ -69,7 +69,6 @@ func (c Cloud189) Items() []Item { func (c Cloud189) Save(account *model.Account, old *model.Account) error { if old != nil && old.Name != account.Name { delete(client189Map, old.Name) - model.DeleteAccountFromMap(old.Name) } if err := c.Login(account); err != nil { account.Status = err.Error() diff --git a/drivers/alidrive.go b/drivers/alidrive.go index 7a827799..6e37ec1b 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -349,9 +349,6 @@ func (a AliDrive) RefreshToken(account *model.Account) error { func (a AliDrive) Save(account *model.Account, old *model.Account) error { if old != nil { conf.Cron.Remove(cron.EntryID(old.CronId)) - if old.Name != account.Name { - model.DeleteAccountFromMap(old.Name) - } } if account.RootFolder == "" { account.RootFolder = "root" diff --git a/drivers/native.go b/drivers/native.go index f0c9afaa..b3b5254a 100644 --- a/drivers/native.go +++ b/drivers/native.go @@ -36,9 +36,6 @@ func (n Native) Proxy(c *gin.Context) { } func (n Native) Save(account *model.Account, old *model.Account) error { - if old != nil { - model.DeleteAccountFromMap(old.Name) - } log.Debugf("save a account: [%s]", account.Name) if !utils.Exists(account.RootFolder) { account.Status = fmt.Sprintf("[%s] not exist", account.RootFolder) diff --git a/drivers/onedrive.go b/drivers/onedrive.go index ea3b9571..6292ec1e 100644 --- a/drivers/onedrive.go +++ b/drivers/onedrive.go @@ -273,9 +273,6 @@ func (o Onedrive) Save(account *model.Account, old *model.Account) error { } if old != nil { conf.Cron.Remove(cron.EntryID(old.CronId)) - if old.Name != account.Name { - model.DeleteAccountFromMap(old.Name) - } } account.RootFolder = utils.ParsePath(account.RootFolder) err := o.RefreshToken(account) diff --git a/server/account.go b/server/account.go index 9cd7bf5f..46615fb6 100644 --- a/server/account.go +++ b/server/account.go @@ -63,6 +63,9 @@ func SaveAccount(c *gin.Context) { } now := time.Now() req.UpdatedAt = &now + if old.Name != req.Name { + model.DeleteAccountFromMap(old.Name) + } if err := model.SaveAccount(&req); err != nil { ErrorResp(c, err, 500) } else {