db

package
v4.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MediaMigrateWipeEnv = "OPENLIST_MEDIA_MIGRATE_WIPE"

MediaMigrateWipeEnv 设为 1/true 时,允许升级流程清空旧版 media_items 数据后重建。 旧版本的 folder_path 语义不同,无法原地迁移;但清库是破坏性操作,必须由管理员显式确认。

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(dst ...interface{}) error

func BatchCreateSearchNodes

func BatchCreateSearchNodes(nodes *[]model.SearchNode) error

func ClearMediaItems added in v4.2.8

func ClearMediaItems(mediaType model.MediaType) error

ClearMediaItems 硬删除指定类型的所有媒体条目(真正从数据库删除),并清理对应批注

func ClearMediaItemsByScanPath added in v4.2.8

func ClearMediaItemsByScanPath(scanPathID uint) error

ClearMediaItemsByScanPath 硬删除指定扫描路径的所有媒体条目,并清理对应批注

func ClearMediaScrapedData added in v4.2.8

func ClearMediaScrapedData(mediaType model.MediaType) (int64, error)

ClearMediaScrapedData 清空指定类型的所有刮削数据(保留扫描出的文件记录本身) 仅清空刮削结果相关字段,不删除条目,便于重新刮削。 mediaType 为空时表示对所有类型生效。

func ClearMediaUserDataByUser added in v4.2.8

func ClearMediaUserDataByUser(userID uint) error

ClearMediaUserDataByUser 删除用户全部播放状态

func ClearSearchNodes

func ClearSearchNodes() error

func Close

func Close()

func CountMediaPlaylistItems added in v4.2.8

func CountMediaPlaylistItems(playlistID uint) (int64, error)

CountMediaPlaylistItems 统计条目数

func CreateEmbyDevice added in v4.2.8

func CreateEmbyDevice(d *model.EmbyDevice) error

func CreateMediaAppKey added in v4.2.8

func CreateMediaAppKey(k *model.MediaAppKey) error

func CreateMediaPlaylist added in v4.2.8

func CreateMediaPlaylist(p *model.MediaPlaylist) error

func CreateMediaScanPath added in v4.2.8

func CreateMediaScanPath(p *model.MediaScanPath) error

CreateMediaScanPath 创建扫描路径

func CreateMeta

func CreateMeta(u *model.Meta) error

func CreateOrUpdateMediaItem added in v4.2.8

func CreateOrUpdateMediaItem(item *model.MediaItem) error

CreateOrUpdateMediaItem 创建或更新媒体条目(按 folder_path + file_name + album_name 组合唯一) 更新时保留已有的刮削数据,避免重新扫描时把已刮削的字段清空

注意:使用 Unscoped() 查询是为了把软删除残留记录也包含进来, 否则唯一索引 idx_media_folder_file_album 会与软删除行冲突, 导致新建条目时报 UNIQUE constraint failed。

func CreateSSHPublicKey

func CreateSSHPublicKey(k *model.SSHPublicKey) error

func CreateSearchNode

func CreateSearchNode(node *model.SearchNode) error

func CreateSharing added in v4.1.2

func CreateSharing(s *model.SharingDB) (string, error)

func CreateStorage

func CreateStorage(storage *model.Storage) error

CreateStorage just insert storage to database

func CreateTaskData

func CreateTaskData(t *model.TaskItem) error

func CreateUser

func CreateUser(u *model.User) error

func DeleteEmbyDevice added in v4.2.8

func DeleteEmbyDevice(userID uint, deviceID string) error

func DeleteMediaAppKey added in v4.2.8

func DeleteMediaAppKey(userID, id uint) error

func DeleteMediaItem added in v4.2.8

func DeleteMediaItem(id uint) error

DeleteMediaItem 硬删除媒体条目(真正从数据库删除),并清理该条目的批注

func DeleteMediaItemsByIDs added in v4.2.8

func DeleteMediaItemsByIDs(ids []uint) error

DeleteMediaItemsByIDs 按ID列表硬删除媒体条目,并清理对应批注

func DeleteMediaPlaylist added in v4.2.8

func DeleteMediaPlaylist(id uint) error

func DeleteMediaScanPath added in v4.2.8

func DeleteMediaScanPath(id uint) error

DeleteMediaScanPath 删除扫描路径(硬删除)

func DeleteMetaById

func DeleteMetaById(id uint) error

func DeleteSSHPublicKeyById

func DeleteSSHPublicKeyById(id uint) error

func DeleteSearchNodesByParent

func DeleteSearchNodesByParent(path string) error

func DeleteSettingItemByKey

func DeleteSettingItemByKey(key string) error

func DeleteSharingById added in v4.1.2

func DeleteSharingById(id string) error

func DeleteSharingsByCreatorId added in v4.1.5

func DeleteSharingsByCreatorId(creatorId uint) error

func DeleteStorageById

func DeleteStorageById(id uint) error

DeleteStorageById just delete storage from database by id

func DeleteUserById

func DeleteUserById(id uint) error

func GetAlbumTracks added in v4.2.8

func GetAlbumTracks(albumName, albumArtist string) ([]model.MediaItem, error)

GetAlbumTracks 获取专辑曲目列表 支持两种模式:

  1. 普通模式(is_folder=false):直接返回独立文件记录
  2. 合并文件夹模式(is_folder=true):把 episodes 展开成虚拟 MediaItem 列表 展开后每条记录的 folder_path = 原folder_path/file_name(文件夹实际路径),file_name = episode.FileName

func GetAllMediaConfigs added in v4.2.8

func GetAllMediaConfigs() ([]model.MediaConfig, error)

GetAllMediaConfigs 获取所有媒体库配置

func GetAllMetas added in v4.2.6

func GetAllMetas() ([]model.Meta, error)

func GetDb

func GetDb() *gorm.DB

func GetEmbyDeviceByTokenHash added in v4.2.8

func GetEmbyDeviceByTokenHash(hash string) (*model.EmbyDevice, error)

func GetEnabledStorages

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

func GetMediaAppKey added in v4.2.8

func GetMediaAppKey(id uint) (*model.MediaAppKey, error)

func GetMediaConfig added in v4.2.8

func GetMediaConfig(mediaType model.MediaType) (*model.MediaConfig, error)

GetMediaConfig 获取指定类型的媒体库配置,不存在则返回默认值

func GetMediaItemByFolderPath added in v4.2.8

func GetMediaItemByFolderPath(folderPath string) (*model.MediaItem, error)

GetMediaItemByFolderPath 按文件夹路径获取媒体条目(用于合并模式)

func GetMediaItemByID added in v4.2.8

func GetMediaItemByID(id uint) (*model.MediaItem, error)

GetMediaItemByID 按ID获取媒体条目

func GetMediaPlaylist added in v4.2.8

func GetMediaPlaylist(id uint) (*model.MediaPlaylist, error)

func GetMediaScanPath added in v4.2.8

func GetMediaScanPath(id uint) (*model.MediaScanPath, error)

GetMediaScanPath 按ID获取扫描路径

func GetMediaUserData added in v4.2.8

func GetMediaUserData(userID, itemID uint, episodeIndex int) (*model.MediaUserData, 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) (metas []model.Meta, count int64, err error)

func GetPublicSettingItems

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

func GetSSHPublicKeyById

func GetSSHPublicKeyById(id uint) (*model.SSHPublicKey, error)

func GetSSHPublicKeyByUserId

func GetSSHPublicKeyByUserId(userId uint, pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)

func GetSSHPublicKeyByUserTitle

func GetSSHPublicKeyByUserTitle(userId uint, title string) (*model.SSHPublicKey, error)

func GetSSHPublicKeys

func GetSSHPublicKeys(pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)

func GetSearchNodesByParent

func GetSearchNodesByParent(parent string) ([]model.SearchNode, error)

func GetSettingItemByKey

func GetSettingItemByKey(key 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 GetSharingById added in v4.1.2

func GetSharingById(id string) (*model.SharingDB, error)

func GetSharings added in v4.1.2

func GetSharings(pageIndex, pageSize int) (sharings []model.SharingDB, count int64, err error)

func GetSharingsByCreatorId added in v4.1.2

func GetSharingsByCreatorId(creator uint, pageIndex, pageSize int) (sharings []model.SharingDB, count int64, err error)

func GetStorageById

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

GetStorageById Get Storage by id, used to update storage usually

func GetStorageByMountPath

func GetStorageByMountPath(mountPath string) (*model.Storage, error)

GetStorageByMountPath Get Storage by mountPath, 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 GetTaskDataByType

func GetTaskDataByType(type_s string) (*model.TaskItem, error)

func GetTaskDataFunc

func GetTaskDataFunc(type_s string, enabled bool) func() ([]byte, error)

func GetUnscrappedItems added in v4.2.8

func GetUnscrappedItems(mediaType model.MediaType, limit int) ([]model.MediaItem, error)

GetUnscrappedItems 获取未刮削或刮削不完整的媒体条目 只要 scraped_at 为空,或 cover/scraped_name/plot 任一为空,就需要重新刮削 limit <= 0 表示不限制数量,返回所有未刮削条目

func GetUserById

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

func GetUserByName

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

func GetUserByRole

func GetUserByRole(role int) (*model.User, error)

func GetUserBySSOID

func GetUserBySSOID(ssoID string) (*model.User, error)

func GetUsers

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

func ImportMediaItems added in v4.2.8

func ImportMediaItems(items []model.MediaItem, scanPathIDOverride *uint) (created, updated int, err error)

ImportMediaItems 批量导入媒体条目 策略:按 (folder_path, file_name, album_name) 唯一键 upsert:

  • 已存在则覆盖刮削字段(导入是用户主动行为,覆盖优先于保留)
  • 不存在则新建

注意:导入数据中的 ID/CreatedAt/UpdatedAt 会被忽略,由数据库重新分配, 避免和现有记录的主键冲突。

func ImportMediaScanPaths added in v4.2.8

func ImportMediaScanPaths(paths []model.MediaScanPath) (idMap map[uint]uint, created, updated int, err error)

ImportMediaScanPaths 批量导入扫描路径 策略:按 (media_type, path) 唯一对去重:

  • 已存在则更新名称/标签等可编辑字段
  • 不存在则新建并返回新ID

返回值 idMap:导入数据中的原始ID -> 数据库实际ID 的映射, 供随后的 MediaItem 导入用于把 scan_path_id 重新指向新ID。

func Init

func Init(d *gorm.DB)

func ListAllMediaItems added in v4.2.8

func ListAllMediaItems(mediaType model.MediaType) ([]model.MediaItem, error)

ListAllMediaItems 列出指定媒体类型下的所有条目(不分页,用于导出) mediaType 为空时返回全部类型的所有条目

func ListAllMediaScanPaths added in v4.2.8

func ListAllMediaScanPaths() ([]model.MediaScanPath, error)

ListAllMediaScanPaths 列出所有扫描路径(不区分类型,用于全量导出)

func ListAllValidMediaItemsForCheck added in v4.2.8

func ListAllValidMediaItemsForCheck(mediaType model.MediaType) ([]model.MediaItem, error)

ListAllValidMediaItemsForCheck 列出指定类型下所有未删除的媒体条目(仅取必要字段,用于失效检查) mediaType 为空时返回所有类型条目。

func ListFolderPaths added in v4.2.8

func ListFolderPaths(mediaType model.MediaType) ([]string, error)

ListFolderPaths 列出指定媒体类型下的所有文件夹路径(目录浏览模式)

func ListMediaAnnotations added in v4.2.8

func ListMediaAnnotations(userID, itemID uint) ([]model.MediaAnnotation, error)

ListMediaAnnotations 列出某用户对某个条目的全部批注

func ListMediaAppKeys added in v4.2.8

func ListMediaAppKeys(userID uint) ([]model.MediaAppKey, error)

func ListMediaAppKeysByPrefix added in v4.2.8

func ListMediaAppKeysByPrefix(prefix string) ([]model.MediaAppKey, error)

ListMediaAppKeysByPrefix 认证时按明文前缀预筛选候选密钥

func ListMediaFavorites added in v4.2.8

func ListMediaFavorites(userID uint) ([]model.MediaUserData, error)

ListMediaFavorites 用户收藏的条目

func ListMediaItems added in v4.2.8

func ListMediaItems(q MediaItemQuery) ([]model.MediaItem, int64, error)

ListMediaItems 分页查询媒体条目

func ListMediaItemsByScanPath added in v4.2.8

func ListMediaItemsByScanPath(scanPathID uint) ([]model.MediaItem, error)

ListMediaItemsByScanPath 列出指定扫描路径下的所有条目(不分页,用于导出)

func ListMediaPlaylistItems added in v4.2.8

func ListMediaPlaylistItems(playlistID uint) ([]model.MediaPlaylistItem, error)

func ListMediaPlaylists added in v4.2.8

func ListMediaPlaylists(userID uint) ([]model.MediaPlaylist, error)

func ListMediaResume added in v4.2.8

func ListMediaResume(userID uint, limit int) ([]model.MediaUserData, error)

ListMediaResume 继续观看:未看完且有进度

func ListMediaScanPaths added in v4.2.8

func ListMediaScanPaths(mediaType model.MediaType) ([]model.MediaScanPath, error)

ListMediaScanPaths 获取指定媒体类型的所有扫描路径

func ListMediaUserDataByItems added in v4.2.8

func ListMediaUserDataByItems(userID uint, itemIDs []uint) ([]model.MediaUserData, error)

ListMediaUserDataByItems 批量取用户对一组条目的播放状态

func RegisterAuthn

func RegisterAuthn(u *model.User, credential *webauthn.Credential) error

func RemoveAuthn

func RemoveAuthn(u *model.User, id string) error

func ReplaceMediaPlaylistItems added in v4.2.8

func ReplaceMediaPlaylistItems(playlistID uint, items []model.MediaPlaylistItem) error

ReplaceMediaPlaylistItems 覆盖式写入播放列表条目

func SaveMediaConfig added in v4.2.8

func SaveMediaConfig(cfg *model.MediaConfig) error

SaveMediaConfig 保存媒体库配置(upsert)

func SaveMediaUserData added in v4.2.8

func SaveMediaUserData(d *model.MediaUserData) error

func SaveSettingItem

func SaveSettingItem(item *model.SettingItem) error

func SaveSettingItems

func SaveSettingItems(items []model.SettingItem) (err error)

func SearchNode

func SearchNode(req model.SearchReq, useFullText bool) ([]model.SearchNode, int64, error)

func SyncMediaAnnotations added in v4.2.8

func SyncMediaAnnotations(userID, itemID uint, upserts []model.MediaAnnotation, deletes []string) error

SyncMediaAnnotations 增量保存批注:upserts 覆盖同一 remote_id 的记录,deletes 按 remote_id 删除。 放在一个事务里,避免多设备同时保存时出现半新半旧的状态。

func TouchEmbyDevice added in v4.2.8

func TouchEmbyDevice(id uint)

func TouchMediaAppKey added in v4.2.8

func TouchMediaAppKey(id uint)

func UpdateAuthn

func UpdateAuthn(userID uint, authn string) error

func UpdateMediaItem added in v4.2.8

func UpdateMediaItem(item *model.MediaItem) error

UpdateMediaItem 更新媒体条目 使用 Unscoped 确保即使存在软删除标记也能正确更新(避免命中唯一索引但行不可见的诡异情况)。

func UpdateMediaPlaylist added in v4.2.8

func UpdateMediaPlaylist(p *model.MediaPlaylist) error

func UpdateMediaScanPath added in v4.2.8

func UpdateMediaScanPath(p *model.MediaScanPath) error

UpdateMediaScanPath 更新扫描路径

func UpdateMeta

func UpdateMeta(u *model.Meta) error

func UpdateSSHPublicKey

func UpdateSSHPublicKey(k *model.SSHPublicKey) error

func UpdateSharing added in v4.1.2

func UpdateSharing(s *model.SharingDB) error

func UpdateSharingId added in v4.2.2

func UpdateSharingId(oldId, newId string) error

func UpdateStorage

func UpdateStorage(storage *model.Storage) error

UpdateStorage just update storage in database

func UpdateTaskData

func UpdateTaskData(t *model.TaskItem) error

func UpdateTaskDataFunc

func UpdateTaskDataFunc(type_s string, enabled bool) func([]byte) error

func UpdateUser

func UpdateUser(u *model.User) error

Types

type AlbumInfo added in v4.2.8

type AlbumInfo struct {
	AlbumName   string `json:"album_name"`
	AlbumArtist string `json:"album_artist"`
	Cover       string `json:"cover"`
	ReleaseDate string `json:"release_date"`
	TrackCount  int    `json:"track_count"`
	ScanPathID  uint   `json:"scan_path_id"`
}

AlbumInfo 专辑信息

func ListAlbums added in v4.2.8

func ListAlbums(q MediaItemQuery) ([]AlbumInfo, int64, error)

ListAlbums 列出所有专辑(音乐专用)

type MediaItemQuery added in v4.2.8

type MediaItemQuery struct {
	MediaType  model.MediaType
	ScanPathID uint   // 按扫描路径ID筛选
	FolderPath string // 按文件夹路径筛选
	TypeTag    string // 按类型标签筛选(电影、电视剧等)
	ContentTag string // 按内容标签筛选(喜剧、惊悚等)
	PathPrefix string // 按文件夹路径前缀筛选(用于用户 base_path 隔离)
	Hidden     *bool
	Keyword    string
	OrderBy    string // "name", "date", "size"
	OrderDir   string // "asc", "desc"
	Page       int
	PageSize   int
}

MediaItemQuery 媒体条目查询参数

Jump to

Keyboard shortcuts

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