mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-21 20:18:47 +08:00
feat: setting model
This commit is contained in:
parent
6bb2b76e25
commit
e4c3ef0262
30
internal/db/setting.go
Normal file
30
internal/db/setting.go
Normal file
@ -0,0 +1,30 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func SaveSettings(items []model.SettingItem) error {
|
||||
return errors.WithStack(db.Save(items).Error)
|
||||
}
|
||||
|
||||
func SaveSetting(item model.SettingItem) error {
|
||||
return errors.WithStack(db.Save(item).Error)
|
||||
}
|
||||
|
||||
func GetSettingsByGroup(group int) ([]model.SettingItem, error) {
|
||||
var items []model.SettingItem
|
||||
if err := db.Where(fmt.Sprintf("%s = ?", columnName("group")), group).Find(&items).Error; err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func DeleteSettingByKey(key string) error {
|
||||
setting := model.SettingItem{
|
||||
Key: key,
|
||||
}
|
||||
return errors.WithStack(db.Delete(&setting).Error)
|
||||
}
|
11
internal/model/setting.go
Normal file
11
internal/model/setting.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
type SettingItem struct {
|
||||
Key string `json:"key" gorm:"primaryKey" binding:"required"` // unique key
|
||||
Value string `json:"value"` // value
|
||||
Help string `json:"help"` // help message
|
||||
Type string `json:"type"` // string, number, bool, select
|
||||
Values string `json:"values"` // values for select
|
||||
Group int `json:"group"` // use to group setting in frontend
|
||||
Access int `json:"access"` // admin/guest/general
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user