🐛 fix can't delete and get meta
This commit is contained in:
parent
5f34b8ab80
commit
48a65784c7
@ -1,7 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"time"
|
"time"
|
||||||
@ -54,11 +53,13 @@ func CreateAccount(account Account) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteAccount(name string) error {
|
func DeleteAccount(id uint) error {
|
||||||
account, ok := GetAccount(name)
|
var account Account
|
||||||
if !ok {
|
account.ID = id
|
||||||
return fmt.Errorf("no [%s] account", name)
|
if err := conf.DB.First(&account).Error; err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
name := account.Name
|
||||||
conf.Cron.Remove(cron.EntryID(account.CronId))
|
conf.Cron.Remove(cron.EntryID(account.CronId))
|
||||||
if err := conf.DB.Delete(&account).Error; err != nil {
|
if err := conf.DB.Delete(&account).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -14,8 +14,7 @@ type Meta struct {
|
|||||||
|
|
||||||
func GetMetaByPath(path string) (*Meta, error) {
|
func GetMetaByPath(path string) (*Meta, error) {
|
||||||
var meta Meta
|
var meta Meta
|
||||||
meta.Path = path
|
err := conf.DB.Where("path = ?", path).First(&meta).Error
|
||||||
err := conf.DB.First(&meta).Error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -30,8 +29,8 @@ func CreateMeta(meta Meta) error {
|
|||||||
return conf.DB.Create(&meta).Error
|
return conf.DB.Create(&meta).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteMeta(path string) error {
|
func DeleteMeta(id uint) error {
|
||||||
meta := Meta{Path: path}
|
meta := Meta{ID: id}
|
||||||
log.Debugf("delete meta: %+v", meta)
|
log.Debugf("delete meta: %+v", meta)
|
||||||
return conf.DB.Delete(&meta).Error
|
return conf.DB.Delete(&meta).Error
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/Xhofe/alist/drivers"
|
"github.com/Xhofe/alist/drivers"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,8 +74,13 @@ func SaveAccount(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DeleteAccount(c *gin.Context) {
|
func DeleteAccount(c *gin.Context) {
|
||||||
name := c.Query("name")
|
idStr := c.Query("id")
|
||||||
if err := model.DeleteAccount(name); err != nil {
|
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)
|
ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetMetas(c *gin.Context) {
|
func GetMetas(c *gin.Context) {
|
||||||
@ -44,9 +45,14 @@ func SaveMeta(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DeleteMeta(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)
|
//path = utils.ParsePath(path)
|
||||||
if err := model.DeleteMeta(path); err != nil {
|
if err := model.DeleteMeta(uint(id)); err != nil {
|
||||||
ErrorResp(c, err, 500)
|
ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user