🐛 fix can't delete and get meta

pull/548/head
微凉 2021-11-13 17:10:44 +08:00
parent 5f34b8ab80
commit 48a65784c7
4 changed files with 25 additions and 13 deletions

View File

@ -1,7 +1,6 @@
package model
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/robfig/cron/v3"
"time"
@ -54,11 +53,13 @@ func CreateAccount(account Account) error {
return nil
}
func DeleteAccount(name string) error {
account, ok := GetAccount(name)
if !ok {
return fmt.Errorf("no [%s] account", name)
func DeleteAccount(id uint) error {
var account Account
account.ID = id
if err := conf.DB.First(&account).Error; err != nil {
return err
}
name := account.Name
conf.Cron.Remove(cron.EntryID(account.CronId))
if err := conf.DB.Delete(&account).Error; err != nil {
return err

View File

@ -14,8 +14,7 @@ type Meta struct {
func GetMetaByPath(path string) (*Meta, error) {
var meta Meta
meta.Path = path
err := conf.DB.First(&meta).Error
err := conf.DB.Where("path = ?", path).First(&meta).Error
if err != nil {
return nil, err
}
@ -30,8 +29,8 @@ func CreateMeta(meta Meta) error {
return conf.DB.Create(&meta).Error
}
func DeleteMeta(path string) error {
meta := Meta{Path: path}
func DeleteMeta(id uint) error {
meta := Meta{ID: id}
log.Debugf("delete meta: %+v", meta)
return conf.DB.Delete(&meta).Error
}

View File

@ -5,6 +5,7 @@ import (
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
"strconv"
"time"
)
@ -73,8 +74,13 @@ func SaveAccount(c *gin.Context) {
}
func DeleteAccount(c *gin.Context) {
name := c.Query("name")
if err := model.DeleteAccount(name); err != nil {
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
ErrorResp(c, err, 400)
return
}
if err := model.DeleteAccount(uint(id)); err != nil {
ErrorResp(c, err, 500)
return
}

View File

@ -4,6 +4,7 @@ import (
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
"strconv"
)
func GetMetas(c *gin.Context) {
@ -44,9 +45,14 @@ func SaveMeta(c *gin.Context) {
}
func DeleteMeta(c *gin.Context) {
path := c.Query("path")
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
ErrorResp(c, err, 400)
return
}
//path = utils.ParsePath(path)
if err := model.DeleteMeta(path); err != nil {
if err := model.DeleteMeta(uint(id)); err != nil {
ErrorResp(c, err, 500)
return
}