🐛 fix delete account when change name

pull/548/head
微凉 2021-11-17 15:21:51 +08:00
parent 69514668cc
commit e8d27a30b4
5 changed files with 15 additions and 7 deletions

View File

@ -67,8 +67,9 @@ func (c Cloud189) Items() []Item {
}
func (c Cloud189) Save(account *model.Account, old *model.Account) error {
if old != nil {
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()

View File

@ -349,8 +349,10 @@ 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"
}

View File

@ -9,9 +9,9 @@ import (
type Driver interface {
Items() []Item
Save(account *model.Account, old *model.Account) error
Path(path string, account *model.Account) (*model.File, []*model.File, error)
Link(path string, account *model.Account) (string, error)
Save(account *model.Account, old *model.Account) error
Proxy(c *gin.Context)
Preview(path string, account *model.Account) (interface{}, error)
// TODO

View File

@ -36,6 +36,9 @@ 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)

View File

@ -273,8 +273,10 @@ 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)
if err != nil {