alist/model/meta.go

45 lines
898 B
Go
Raw Normal View History

2021-10-26 14:28:37 +00:00
package model
2021-11-13 08:49:03 +00:00
import (
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
)
2021-10-28 14:50:09 +00:00
2021-10-26 14:28:37 +00:00
type Meta struct {
2021-11-13 08:49:03 +00:00
ID uint `json:"id" gorm:"primaryKey"`
Path string `json:"path" gorm:"unique" 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
2021-11-13 09:10:44 +00:00
err := conf.DB.Where("path = ?", path).First(&meta).Error
2021-10-28 14:50:09 +00:00
if err != nil {
return nil, err
}
return &meta, nil
2021-11-02 11:25:54 +00:00
}
func SaveMeta(meta Meta) error {
2021-11-13 08:49:03 +00:00
return conf.DB.Save(&meta).Error
}
func CreateMeta(meta Meta) error {
return conf.DB.Create(&meta).Error
2021-11-02 11:25:54 +00:00
}
2021-11-13 09:10:44 +00:00
func DeleteMeta(id uint) error {
meta := Meta{ID: id}
2021-11-13 08:49:03 +00:00
log.Debugf("delete meta: %+v", meta)
2021-11-02 11:25:54 +00:00
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
}