alist/model/meta.go

37 lines
705 B
Go
Raw Normal View History

2021-10-26 14:28:37 +00:00
package model
2021-10-28 14:50:09 +00:00
import "github.com/Xhofe/alist/conf"
2021-10-26 14:28:37 +00:00
type Meta struct {
2021-11-13 07:53:26 +00:00
Path string `json:"path" gorm:"primaryKey" binding:"required"`
2021-10-26 14:28:37 +00:00
Password string `json:"password"`
2021-11-02 11:25:54 +00:00
Hide string `json:"hide"`
2021-10-26 14:28:37 +00:00
}
2021-10-28 14:50:09 +00:00
2021-11-02 11:25:54 +00:00
func GetMetaByPath(path string) (*Meta, error) {
2021-10-28 14:50:09 +00:00
var meta Meta
meta.Path = path
err := conf.DB.First(&meta).Error
if err != nil {
return nil, err
}
return &meta, nil
2021-11-02 11:25:54 +00:00
}
func SaveMeta(meta Meta) error {
return conf.DB.Save(meta).Error
}
func DeleteMeta(path string) error {
meta := Meta{Path: path}
return conf.DB.Delete(&meta).Error
}
func GetMetas() (*[]Meta, error) {
var metas []Meta
if err := conf.DB.Find(&metas).Error; err != nil {
return nil, err
}
return &metas, nil
}