db

package
v3.0.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SettingItemHooks = map[string]SettingItemHook{
	conf.VideoTypes: {
		Hook: func(item *model.SettingItem) error {
			conf.TypesMap[conf.VideoTypes] = strings.Split(item.Value, ",")
			return nil
		},
	},
	conf.AudioTypes: {
		Hook: func(item *model.SettingItem) error {
			conf.TypesMap[conf.AudioTypes] = strings.Split(item.Value, ",")
			return nil
		},
	},
	conf.ImageTypes: {
		Hook: func(item *model.SettingItem) error {
			conf.TypesMap[conf.ImageTypes] = strings.Split(item.Value, ",")
			return nil
		},
	},
	conf.TextTypes: {
		Hook: func(item *model.SettingItem) error {
			conf.TypesMap[conf.TextTypes] = strings.Split(item.Value, ",")
			return nil
		},
	},

	conf.ProxyTypes: {
		func(item *model.SettingItem) error {
			conf.TypesMap[conf.ProxyTypes] = strings.Split(item.Value, ",")
			return nil
		},
	},
	conf.PrivacyRegs: {
		Hook: func(item *model.SettingItem) error {
			regStrs := strings.Split(item.Value, "\n")
			regs := make([]*regexp.Regexp, 0, len(regStrs))
			for _, regStr := range regStrs {
				reg, err := regexp.Compile(regStr)
				if err != nil {
					return errors.WithStack(err)
				}
				regs = append(regs, reg)
			}
			conf.PrivacyReg = regs
			return nil
		},
	},
}

Functions

func Cancel2FAById

func Cancel2FAById(id uint) error

func Cancel2FAByUser

func Cancel2FAByUser(u *model.User) error

func CreateMeta

func CreateMeta(u *model.Meta) error

func CreateStorage

func CreateStorage(storage *model.Storage) error

CreateStorage just insert storage to database

func CreateUser

func CreateUser(u *model.User) error

func DeleteMetaById

func DeleteMetaById(id uint) error

func DeleteSettingItemByKey

func DeleteSettingItemByKey(key string) error

func DeleteStorageById

func DeleteStorageById(id uint) error

DeleteStorageById just delete storage from database by id

func DeleteUserById

func DeleteUserById(id uint) error

func GetAdmin

func GetAdmin() (*model.User, error)

func GetEnabledStorages

func GetEnabledStorages() ([]model.Storage, error)

func GetGuest

func GetGuest() (*model.User, error)

func GetMetaById

func GetMetaById(id uint) (*model.Meta, error)

func GetMetaByPath

func GetMetaByPath(path string) (*model.Meta, error)

func GetMetas

func GetMetas(pageIndex, pageSize int) ([]model.Meta, int64, error)

func GetNearestMeta

func GetNearestMeta(path string) (*model.Meta, error)

func GetPublicSettingItems

func GetPublicSettingItems() ([]model.SettingItem, error)

func GetPublicSettingsMap

func GetPublicSettingsMap() map[string]string

func GetSettingItemByKey

func GetSettingItemByKey(key string) (*model.SettingItem, error)

func GetSettingItemInKeys

func GetSettingItemInKeys(keys []string) ([]model.SettingItem, error)

func GetSettingItems

func GetSettingItems() ([]model.SettingItem, error)

func GetSettingItemsByGroup

func GetSettingItemsByGroup(group int) ([]model.SettingItem, error)

func GetSettingItemsInGroups

func GetSettingItemsInGroups(groups []int) ([]model.SettingItem, error)

func GetSettingsMap

func GetSettingsMap() map[string]string

func GetStorageById

func GetStorageById(id uint) (*model.Storage, error)

GetStorageById Get Storage by id, used to update storage usually

func GetStorages

func GetStorages(pageIndex, pageSize int) ([]model.Storage, int64, error)

GetStorages Get all storages from database order by index

func GetUserById

func GetUserById(id uint) (*model.User, error)

func GetUserByName

func GetUserByName(username string) (*model.User, error)

func GetUsers

func GetUsers(pageIndex, pageSize int) ([]model.User, int64, error)

func HandleSettingItem

func HandleSettingItem(item *model.SettingItem) (bool, error)

func Init

func Init(d *gorm.DB)

func SaveSettingItem

func SaveSettingItem(item model.SettingItem) error

func SaveSettingItems

func SaveSettingItems(items []model.SettingItem) error

func UpdateMeta

func UpdateMeta(u *model.Meta) error

func UpdateStorage

func UpdateStorage(storage *model.Storage) error

UpdateStorage just update storage in database

func UpdateUser

func UpdateUser(u *model.User) error

Types

type SettingItemHook

type SettingItemHook struct {
	Hook func(item *model.SettingItem) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL