mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Model refactor (#3915)
* Add mockery config file * Move basic file/folder structs to models * Fix hack due to import loop * Move file interfaces to models * Move folder interfaces to models * Move scene interfaces to models * Move scene marker interfaces to models * Move image interfaces to models * Move gallery interfaces to models * Move gallery chapter interfaces to models * Move studio interfaces to models * Move movie interfaces to models * Move performer interfaces to models * Move tag interfaces to models * Move autotag interfaces to models * Regenerate mocks
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
)
|
||||
@@ -31,17 +30,17 @@ const (
|
||||
)
|
||||
|
||||
type basicFileRow struct {
|
||||
ID file.ID `db:"id" goqu:"skipinsert"`
|
||||
Basename string `db:"basename"`
|
||||
ZipFileID null.Int `db:"zip_file_id"`
|
||||
ParentFolderID file.FolderID `db:"parent_folder_id"`
|
||||
Size int64 `db:"size"`
|
||||
ModTime Timestamp `db:"mod_time"`
|
||||
CreatedAt Timestamp `db:"created_at"`
|
||||
UpdatedAt Timestamp `db:"updated_at"`
|
||||
ID models.FileID `db:"id" goqu:"skipinsert"`
|
||||
Basename string `db:"basename"`
|
||||
ZipFileID null.Int `db:"zip_file_id"`
|
||||
ParentFolderID models.FolderID `db:"parent_folder_id"`
|
||||
Size int64 `db:"size"`
|
||||
ModTime Timestamp `db:"mod_time"`
|
||||
CreatedAt Timestamp `db:"created_at"`
|
||||
UpdatedAt Timestamp `db:"updated_at"`
|
||||
}
|
||||
|
||||
func (r *basicFileRow) fromBasicFile(o file.BaseFile) {
|
||||
func (r *basicFileRow) fromBasicFile(o models.BaseFile) {
|
||||
r.ID = o.ID
|
||||
r.Basename = o.Basename
|
||||
r.ZipFileID = nullIntFromFileIDPtr(o.ZipFileID)
|
||||
@@ -53,20 +52,20 @@ func (r *basicFileRow) fromBasicFile(o file.BaseFile) {
|
||||
}
|
||||
|
||||
type videoFileRow struct {
|
||||
FileID file.ID `db:"file_id"`
|
||||
Format string `db:"format"`
|
||||
Width int `db:"width"`
|
||||
Height int `db:"height"`
|
||||
Duration float64 `db:"duration"`
|
||||
VideoCodec string `db:"video_codec"`
|
||||
AudioCodec string `db:"audio_codec"`
|
||||
FrameRate float64 `db:"frame_rate"`
|
||||
BitRate int64 `db:"bit_rate"`
|
||||
Interactive bool `db:"interactive"`
|
||||
InteractiveSpeed null.Int `db:"interactive_speed"`
|
||||
FileID models.FileID `db:"file_id"`
|
||||
Format string `db:"format"`
|
||||
Width int `db:"width"`
|
||||
Height int `db:"height"`
|
||||
Duration float64 `db:"duration"`
|
||||
VideoCodec string `db:"video_codec"`
|
||||
AudioCodec string `db:"audio_codec"`
|
||||
FrameRate float64 `db:"frame_rate"`
|
||||
BitRate int64 `db:"bit_rate"`
|
||||
Interactive bool `db:"interactive"`
|
||||
InteractiveSpeed null.Int `db:"interactive_speed"`
|
||||
}
|
||||
|
||||
func (f *videoFileRow) fromVideoFile(ff file.VideoFile) {
|
||||
func (f *videoFileRow) fromVideoFile(ff models.VideoFile) {
|
||||
f.FileID = ff.ID
|
||||
f.Format = ff.Format
|
||||
f.Width = ff.Width
|
||||
@@ -81,13 +80,13 @@ func (f *videoFileRow) fromVideoFile(ff file.VideoFile) {
|
||||
}
|
||||
|
||||
type imageFileRow struct {
|
||||
FileID file.ID `db:"file_id"`
|
||||
Format string `db:"format"`
|
||||
Width int `db:"width"`
|
||||
Height int `db:"height"`
|
||||
FileID models.FileID `db:"file_id"`
|
||||
Format string `db:"format"`
|
||||
Width int `db:"width"`
|
||||
Height int `db:"height"`
|
||||
}
|
||||
|
||||
func (f *imageFileRow) fromImageFile(ff file.ImageFile) {
|
||||
func (f *imageFileRow) fromImageFile(ff models.ImageFile) {
|
||||
f.FileID = ff.ID
|
||||
f.Format = ff.Format
|
||||
f.Width = ff.Width
|
||||
@@ -110,8 +109,8 @@ type videoFileQueryRow struct {
|
||||
InteractiveSpeed null.Int `db:"interactive_speed"`
|
||||
}
|
||||
|
||||
func (f *videoFileQueryRow) resolve() *file.VideoFile {
|
||||
return &file.VideoFile{
|
||||
func (f *videoFileQueryRow) resolve() *models.VideoFile {
|
||||
return &models.VideoFile{
|
||||
Format: f.Format.String,
|
||||
Width: int(f.Width.Int64),
|
||||
Height: int(f.Height.Int64),
|
||||
@@ -159,8 +158,8 @@ func (imageFileQueryRow) columns(table *table) []interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *imageFileQueryRow) resolve() *file.ImageFile {
|
||||
return &file.ImageFile{
|
||||
func (f *imageFileQueryRow) resolve() *models.ImageFile {
|
||||
return &models.ImageFile{
|
||||
Format: f.Format.String,
|
||||
Width: int(f.Width.Int64),
|
||||
Height: int(f.Height.Int64),
|
||||
@@ -186,15 +185,15 @@ type fileQueryRow struct {
|
||||
imageFileQueryRow
|
||||
}
|
||||
|
||||
func (r *fileQueryRow) resolve() file.File {
|
||||
basic := &file.BaseFile{
|
||||
ID: file.ID(r.FileID.Int64),
|
||||
DirEntry: file.DirEntry{
|
||||
func (r *fileQueryRow) resolve() models.File {
|
||||
basic := &models.BaseFile{
|
||||
ID: models.FileID(r.FileID.Int64),
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: nullIntFileIDPtr(r.ZipFileID),
|
||||
ModTime: r.ModTime.Timestamp,
|
||||
},
|
||||
Path: filepath.Join(r.FolderPath.String, r.Basename.String),
|
||||
ParentFolderID: file.FolderID(r.ParentFolderID.Int64),
|
||||
ParentFolderID: models.FolderID(r.ParentFolderID.Int64),
|
||||
Basename: r.Basename.String,
|
||||
Size: r.Size.Int64,
|
||||
CreatedAt: r.CreatedAt.Timestamp,
|
||||
@@ -202,14 +201,14 @@ func (r *fileQueryRow) resolve() file.File {
|
||||
}
|
||||
|
||||
if basic.ZipFileID != nil && r.ZipFolderPath.Valid && r.ZipBasename.Valid {
|
||||
basic.ZipFile = &file.BaseFile{
|
||||
basic.ZipFile = &models.BaseFile{
|
||||
ID: *basic.ZipFileID,
|
||||
Path: filepath.Join(r.ZipFolderPath.String, r.ZipBasename.String),
|
||||
Basename: r.ZipBasename.String,
|
||||
}
|
||||
}
|
||||
|
||||
var ret file.File = basic
|
||||
var ret models.File = basic
|
||||
|
||||
if r.videoFileQueryRow.Format.Valid {
|
||||
vf := r.videoFileQueryRow.resolve()
|
||||
@@ -228,7 +227,7 @@ func (r *fileQueryRow) resolve() file.File {
|
||||
return ret
|
||||
}
|
||||
|
||||
func appendFingerprintsUnique(vs []file.Fingerprint, v ...file.Fingerprint) []file.Fingerprint {
|
||||
func appendFingerprintsUnique(vs []models.Fingerprint, v ...models.Fingerprint) []models.Fingerprint {
|
||||
for _, vv := range v {
|
||||
found := false
|
||||
for _, vsv := range vs {
|
||||
@@ -245,7 +244,7 @@ func appendFingerprintsUnique(vs []file.Fingerprint, v ...file.Fingerprint) []fi
|
||||
return vs
|
||||
}
|
||||
|
||||
func (r *fileQueryRow) appendRelationships(i *file.BaseFile) {
|
||||
func (r *fileQueryRow) appendRelationships(i *models.BaseFile) {
|
||||
if r.fingerprintQueryRow.valid() {
|
||||
i.Fingerprints = appendFingerprintsUnique(i.Fingerprints, r.fingerprintQueryRow.resolve())
|
||||
}
|
||||
@@ -253,16 +252,16 @@ func (r *fileQueryRow) appendRelationships(i *file.BaseFile) {
|
||||
|
||||
type fileQueryRows []fileQueryRow
|
||||
|
||||
func (r fileQueryRows) resolve() []file.File {
|
||||
var ret []file.File
|
||||
var last file.File
|
||||
var lastID file.ID
|
||||
func (r fileQueryRows) resolve() []models.File {
|
||||
var ret []models.File
|
||||
var last models.File
|
||||
var lastID models.FileID
|
||||
|
||||
for _, row := range r {
|
||||
if last == nil || lastID != file.ID(row.FileID.Int64) {
|
||||
if last == nil || lastID != models.FileID(row.FileID.Int64) {
|
||||
f := row.resolve()
|
||||
last = f
|
||||
lastID = file.ID(row.FileID.Int64)
|
||||
lastID = models.FileID(row.FileID.Int64)
|
||||
ret = append(ret, last)
|
||||
continue
|
||||
}
|
||||
@@ -295,7 +294,7 @@ func (qb *FileStore) table() exp.IdentifierExpression {
|
||||
return qb.tableMgr.table
|
||||
}
|
||||
|
||||
func (qb *FileStore) Create(ctx context.Context, f file.File) error {
|
||||
func (qb *FileStore) Create(ctx context.Context, f models.File) error {
|
||||
var r basicFileRow
|
||||
r.fromBasicFile(*f.Base())
|
||||
|
||||
@@ -304,15 +303,15 @@ func (qb *FileStore) Create(ctx context.Context, f file.File) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fileID := file.ID(id)
|
||||
fileID := models.FileID(id)
|
||||
|
||||
// create extended stuff here
|
||||
switch ef := f.(type) {
|
||||
case *file.VideoFile:
|
||||
case *models.VideoFile:
|
||||
if err := qb.createVideoFile(ctx, fileID, *ef); err != nil {
|
||||
return err
|
||||
}
|
||||
case *file.ImageFile:
|
||||
case *models.ImageFile:
|
||||
if err := qb.createImageFile(ctx, fileID, *ef); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -333,7 +332,7 @@ func (qb *FileStore) Create(ctx context.Context, f file.File) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) Update(ctx context.Context, f file.File) error {
|
||||
func (qb *FileStore) Update(ctx context.Context, f models.File) error {
|
||||
var r basicFileRow
|
||||
r.fromBasicFile(*f.Base())
|
||||
|
||||
@@ -345,11 +344,11 @@ func (qb *FileStore) Update(ctx context.Context, f file.File) error {
|
||||
|
||||
// create extended stuff here
|
||||
switch ef := f.(type) {
|
||||
case *file.VideoFile:
|
||||
case *models.VideoFile:
|
||||
if err := qb.updateOrCreateVideoFile(ctx, id, *ef); err != nil {
|
||||
return err
|
||||
}
|
||||
case *file.ImageFile:
|
||||
case *models.ImageFile:
|
||||
if err := qb.updateOrCreateImageFile(ctx, id, *ef); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -362,11 +361,11 @@ func (qb *FileStore) Update(ctx context.Context, f file.File) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) Destroy(ctx context.Context, id file.ID) error {
|
||||
func (qb *FileStore) Destroy(ctx context.Context, id models.FileID) error {
|
||||
return qb.tableMgr.destroyExisting(ctx, []int{int(id)})
|
||||
}
|
||||
|
||||
func (qb *FileStore) createVideoFile(ctx context.Context, id file.ID, f file.VideoFile) error {
|
||||
func (qb *FileStore) createVideoFile(ctx context.Context, id models.FileID, f models.VideoFile) error {
|
||||
var r videoFileRow
|
||||
r.fromVideoFile(f)
|
||||
r.FileID = id
|
||||
@@ -377,7 +376,7 @@ func (qb *FileStore) createVideoFile(ctx context.Context, id file.ID, f file.Vid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) updateOrCreateVideoFile(ctx context.Context, id file.ID, f file.VideoFile) error {
|
||||
func (qb *FileStore) updateOrCreateVideoFile(ctx context.Context, id models.FileID, f models.VideoFile) error {
|
||||
exists, err := videoFileTableMgr.idExists(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -397,7 +396,7 @@ func (qb *FileStore) updateOrCreateVideoFile(ctx context.Context, id file.ID, f
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) createImageFile(ctx context.Context, id file.ID, f file.ImageFile) error {
|
||||
func (qb *FileStore) createImageFile(ctx context.Context, id models.FileID, f models.ImageFile) error {
|
||||
var r imageFileRow
|
||||
r.fromImageFile(f)
|
||||
r.FileID = id
|
||||
@@ -408,7 +407,7 @@ func (qb *FileStore) createImageFile(ctx context.Context, id file.ID, f file.Ima
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) updateOrCreateImageFile(ctx context.Context, id file.ID, f file.ImageFile) error {
|
||||
func (qb *FileStore) updateOrCreateImageFile(ctx context.Context, id models.FileID, f models.ImageFile) error {
|
||||
exists, err := imageFileTableMgr.idExists(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -515,7 +514,7 @@ func (qb *FileStore) countDataset() *goqu.SelectDataset {
|
||||
)
|
||||
}
|
||||
|
||||
func (qb *FileStore) get(ctx context.Context, q *goqu.SelectDataset) (file.File, error) {
|
||||
func (qb *FileStore) get(ctx context.Context, q *goqu.SelectDataset) (models.File, error) {
|
||||
ret, err := qb.getMany(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -528,7 +527,7 @@ func (qb *FileStore) get(ctx context.Context, q *goqu.SelectDataset) (file.File,
|
||||
return ret[0], nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]file.File, error) {
|
||||
func (qb *FileStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]models.File, error) {
|
||||
const single = false
|
||||
var rows fileQueryRows
|
||||
if err := queryFunc(ctx, q, single, func(r *sqlx.Rows) error {
|
||||
@@ -546,8 +545,8 @@ func (qb *FileStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]file
|
||||
return rows.resolve(), nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) Find(ctx context.Context, ids ...file.ID) ([]file.File, error) {
|
||||
var files []file.File
|
||||
func (qb *FileStore) Find(ctx context.Context, ids ...models.FileID) ([]models.File, error) {
|
||||
var files []models.File
|
||||
for _, id := range ids {
|
||||
file, err := qb.find(ctx, id)
|
||||
if err != nil {
|
||||
@@ -564,7 +563,7 @@ func (qb *FileStore) Find(ctx context.Context, ids ...file.ID) ([]file.File, err
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (qb *FileStore) find(ctx context.Context, id file.ID) (file.File, error) {
|
||||
func (qb *FileStore) find(ctx context.Context, id models.FileID) (models.File, error) {
|
||||
q := qb.selectDataset().Where(qb.tableMgr.byID(id))
|
||||
|
||||
ret, err := qb.get(ctx, q)
|
||||
@@ -576,7 +575,7 @@ func (qb *FileStore) find(ctx context.Context, id file.ID) (file.File, error) {
|
||||
}
|
||||
|
||||
// FindByPath returns the first file that matches the given path. Wildcard characters are supported.
|
||||
func (qb *FileStore) FindByPath(ctx context.Context, p string) (file.File, error) {
|
||||
func (qb *FileStore) FindByPath(ctx context.Context, p string) (models.File, error) {
|
||||
|
||||
ret, err := qb.FindAllByPath(ctx, p)
|
||||
|
||||
@@ -593,7 +592,7 @@ func (qb *FileStore) FindByPath(ctx context.Context, p string) (file.File, error
|
||||
|
||||
// FindAllByPath returns all the files that match the given path.
|
||||
// Wildcard characters are supported.
|
||||
func (qb *FileStore) FindAllByPath(ctx context.Context, p string) ([]file.File, error) {
|
||||
func (qb *FileStore) FindAllByPath(ctx context.Context, p string) ([]models.File, error) {
|
||||
// separate basename from path
|
||||
basename := filepath.Base(p)
|
||||
dirName := filepath.Dir(p)
|
||||
@@ -646,7 +645,7 @@ func (qb *FileStore) allInPaths(q *goqu.SelectDataset, p []string) *goqu.SelectD
|
||||
// FindAllByPaths returns the all files that are within any of the given paths.
|
||||
// Returns all if limit is < 0.
|
||||
// Returns all files if p is empty.
|
||||
func (qb *FileStore) FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]file.File, error) {
|
||||
func (qb *FileStore) FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]models.File, error) {
|
||||
table := qb.table()
|
||||
folderTable := folderTableMgr.table
|
||||
|
||||
@@ -680,7 +679,7 @@ func (qb *FileStore) CountAllInPaths(ctx context.Context, p []string) (int, erro
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *FileStore) findBySubquery(ctx context.Context, sq *goqu.SelectDataset) ([]file.File, error) {
|
||||
func (qb *FileStore) findBySubquery(ctx context.Context, sq *goqu.SelectDataset) ([]models.File, error) {
|
||||
table := qb.table()
|
||||
|
||||
q := qb.selectDataset().Prepared(true).Where(
|
||||
@@ -692,7 +691,7 @@ func (qb *FileStore) findBySubquery(ctx context.Context, sq *goqu.SelectDataset)
|
||||
return qb.getMany(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *FileStore) FindByFingerprint(ctx context.Context, fp file.Fingerprint) ([]file.File, error) {
|
||||
func (qb *FileStore) FindByFingerprint(ctx context.Context, fp models.Fingerprint) ([]models.File, error) {
|
||||
fingerprintTable := fingerprintTableMgr.table
|
||||
|
||||
fingerprints := fingerprintTable.As("fp")
|
||||
@@ -705,7 +704,7 @@ func (qb *FileStore) FindByFingerprint(ctx context.Context, fp file.Fingerprint)
|
||||
return qb.findBySubquery(ctx, sq)
|
||||
}
|
||||
|
||||
func (qb *FileStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]file.File, error) {
|
||||
func (qb *FileStore) FindByZipFileID(ctx context.Context, zipFileID models.FileID) ([]models.File, error) {
|
||||
table := qb.table()
|
||||
|
||||
q := qb.selectDataset().Prepared(true).Where(
|
||||
@@ -716,7 +715,7 @@ func (qb *FileStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]
|
||||
}
|
||||
|
||||
// FindByFileInfo finds files that match the base name, size, and mod time of the given file.
|
||||
func (qb *FileStore) FindByFileInfo(ctx context.Context, info fs.FileInfo, size int64) ([]file.File, error) {
|
||||
func (qb *FileStore) FindByFileInfo(ctx context.Context, info fs.FileInfo, size int64) ([]models.File, error) {
|
||||
table := qb.table()
|
||||
|
||||
modTime := info.ModTime().Format(time.RFC3339)
|
||||
@@ -730,7 +729,7 @@ func (qb *FileStore) FindByFileInfo(ctx context.Context, info fs.FileInfo, size
|
||||
return qb.getMany(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *FileStore) CountByFolderID(ctx context.Context, folderID file.FolderID) (int, error) {
|
||||
func (qb *FileStore) CountByFolderID(ctx context.Context, folderID models.FolderID) (int, error) {
|
||||
table := qb.table()
|
||||
|
||||
q := qb.countDataset().Prepared(true).Where(
|
||||
@@ -740,7 +739,7 @@ func (qb *FileStore) CountByFolderID(ctx context.Context, folderID file.FolderID
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *FileStore) IsPrimary(ctx context.Context, fileID file.ID) (bool, error) {
|
||||
func (qb *FileStore) IsPrimary(ctx context.Context, fileID models.FileID) (bool, error) {
|
||||
joinTables := []exp.IdentifierExpression{
|
||||
scenesFilesJoinTable,
|
||||
galleriesFilesJoinTable,
|
||||
@@ -867,9 +866,9 @@ func (qb *FileStore) Query(ctx context.Context, options models.FileQueryOptions)
|
||||
return nil, fmt.Errorf("error finding IDs: %w", err)
|
||||
}
|
||||
|
||||
result.IDs = make([]file.ID, len(idsResult))
|
||||
result.IDs = make([]models.FileID, len(idsResult))
|
||||
for i, id := range idsResult {
|
||||
result.IDs[i] = file.ID(id)
|
||||
result.IDs[i] = models.FileID(id)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -929,10 +928,10 @@ func (qb *FileStore) captionRepository() *captionRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *FileStore) GetCaptions(ctx context.Context, fileID file.ID) ([]*models.VideoCaption, error) {
|
||||
func (qb *FileStore) GetCaptions(ctx context.Context, fileID models.FileID) ([]*models.VideoCaption, error) {
|
||||
return qb.captionRepository().get(ctx, fileID)
|
||||
}
|
||||
|
||||
func (qb *FileStore) UpdateCaptions(ctx context.Context, fileID file.ID, captions []*models.VideoCaption) error {
|
||||
func (qb *FileStore) UpdateCaptions(ctx context.Context, fileID models.FileID, captions []*models.VideoCaption) error {
|
||||
return qb.captionRepository().replace(ctx, fileID, captions)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -17,10 +17,10 @@ func getFilePath(folderIdx int, basename string) string {
|
||||
return filepath.Join(folderPaths[folderIdx], basename)
|
||||
}
|
||||
|
||||
func makeZipFileWithID(index int) file.File {
|
||||
func makeZipFileWithID(index int) models.File {
|
||||
f := makeFile(index)
|
||||
|
||||
return &file.BaseFile{
|
||||
return &models.BaseFile{
|
||||
ID: fileIDs[index],
|
||||
Basename: f.Base().Basename,
|
||||
Path: getFilePath(fileFolders[index], getFileBaseName(index)),
|
||||
@@ -49,13 +49,13 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
newObject file.File
|
||||
newObject models.File
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"full",
|
||||
&file.BaseFile{
|
||||
DirEntry: file.DirEntry{
|
||||
&models.BaseFile{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -64,7 +64,7 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -77,9 +77,9 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"video file",
|
||||
&file.VideoFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
DirEntry: file.DirEntry{
|
||||
&models.VideoFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -88,7 +88,7 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -110,9 +110,9 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"image file",
|
||||
&file.ImageFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
DirEntry: file.DirEntry{
|
||||
&models.ImageFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -121,7 +121,7 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -138,15 +138,15 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"duplicate path",
|
||||
&file.BaseFile{
|
||||
DirEntry: file.DirEntry{
|
||||
&models.BaseFile{
|
||||
DirEntry: models.DirEntry{
|
||||
ModTime: fileModTime,
|
||||
},
|
||||
Path: getFilePath(folderIdxWithFiles, getFileBaseName(fileIdxZip)),
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: getFileBaseName(fileIdxZip),
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -159,22 +159,22 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"empty basename",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"missing folder id",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
Basename: basename,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"invalid folder id",
|
||||
&file.BaseFile{
|
||||
DirEntry: file.DirEntry{},
|
||||
&models.BaseFile{
|
||||
DirEntry: models.DirEntry{},
|
||||
ParentFolderID: invalidFolderID,
|
||||
Basename: basename,
|
||||
},
|
||||
@@ -182,8 +182,8 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid zip file id",
|
||||
&file.BaseFile{
|
||||
DirEntry: file.DirEntry{
|
||||
&models.BaseFile{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &invalidFileID,
|
||||
},
|
||||
Basename: basename,
|
||||
@@ -210,15 +210,15 @@ func Test_fileFileStore_Create(t *testing.T) {
|
||||
|
||||
assert.NotZero(s.Base().ID)
|
||||
|
||||
var copy file.File
|
||||
var copy models.File
|
||||
switch t := s.(type) {
|
||||
case *file.BaseFile:
|
||||
case *models.BaseFile:
|
||||
v := *t
|
||||
copy = &v
|
||||
case *file.VideoFile:
|
||||
case *models.VideoFile:
|
||||
v := *t
|
||||
copy = &v
|
||||
case *file.ImageFile:
|
||||
case *models.ImageFile:
|
||||
v := *t
|
||||
copy = &v
|
||||
}
|
||||
@@ -266,14 +266,14 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
updatedObject file.File
|
||||
updatedObject models.File
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"full",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxInZip],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -282,7 +282,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -295,10 +295,10 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"video file",
|
||||
&file.VideoFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
&models.VideoFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
ID: fileIDs[fileIdxStartVideoFiles],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -307,7 +307,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -329,10 +329,10 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"image file",
|
||||
&file.ImageFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
&models.ImageFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
ID: fileIDs[fileIdxStartImageFiles],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -341,7 +341,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: basename,
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -358,16 +358,16 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"duplicate path",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxInZip],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ModTime: fileModTime,
|
||||
},
|
||||
Path: getFilePath(folderIdxWithFiles, getFileBaseName(fileIdxZip)),
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
Basename: getFileBaseName(fileIdxZip),
|
||||
Size: size,
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: fingerprintType,
|
||||
Fingerprint: fingerprintValue,
|
||||
@@ -380,7 +380,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"clear zip",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxInZip],
|
||||
Path: getFilePath(folderIdxWithFiles, getFileBaseName(fileIdxZip)+".renamed"),
|
||||
Basename: getFileBaseName(fileIdxZip) + ".renamed",
|
||||
@@ -390,7 +390,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"clear folder",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxZip],
|
||||
Path: basename,
|
||||
},
|
||||
@@ -398,7 +398,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid parent folder id",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxZip],
|
||||
Path: basename,
|
||||
ParentFolderID: invalidFolderID,
|
||||
@@ -407,10 +407,10 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid zip file id",
|
||||
&file.BaseFile{
|
||||
&models.BaseFile{
|
||||
ID: fileIDs[fileIdxZip],
|
||||
Path: basename,
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &invalidFileID,
|
||||
},
|
||||
ParentFolderID: folderIDs[folderIdxWithFiles],
|
||||
@@ -450,7 +450,7 @@ func Test_fileStore_Update(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeFileWithID(index int) file.File {
|
||||
func makeFileWithID(index int) models.File {
|
||||
ret := makeFile(index)
|
||||
ret.Base().Path = getFilePath(fileFolders[index], getFileBaseName(index))
|
||||
ret.Base().ID = fileIDs[index]
|
||||
@@ -461,8 +461,8 @@ func makeFileWithID(index int) file.File {
|
||||
func Test_fileStore_Find(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
id file.ID
|
||||
want file.File
|
||||
id models.FileID
|
||||
want models.File
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -473,7 +473,7 @@ func Test_fileStore_Find(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid",
|
||||
file.ID(invalidID),
|
||||
models.FileID(invalidID),
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
@@ -529,7 +529,7 @@ func Test_FileStore_FindByPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
want file.File
|
||||
want models.File
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -565,31 +565,31 @@ func Test_FileStore_FindByPath(t *testing.T) {
|
||||
func TestFileStore_FindByFingerprint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fp file.Fingerprint
|
||||
want []file.File
|
||||
fp models.Fingerprint
|
||||
want []models.File
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"by MD5",
|
||||
file.Fingerprint{
|
||||
models.Fingerprint{
|
||||
Type: "MD5",
|
||||
Fingerprint: getPrefixedStringValue("file", fileIdxZip, "md5"),
|
||||
},
|
||||
[]file.File{makeFileWithID(fileIdxZip)},
|
||||
[]models.File{makeFileWithID(fileIdxZip)},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"by OSHASH",
|
||||
file.Fingerprint{
|
||||
models.Fingerprint{
|
||||
Type: "OSHASH",
|
||||
Fingerprint: getPrefixedStringValue("file", fileIdxZip, "oshash"),
|
||||
},
|
||||
[]file.File{makeFileWithID(fileIdxZip)},
|
||||
[]models.File{makeFileWithID(fileIdxZip)},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"non-existing",
|
||||
file.Fingerprint{
|
||||
models.Fingerprint{
|
||||
Type: "OSHASH",
|
||||
Fingerprint: "foo",
|
||||
},
|
||||
@@ -617,7 +617,7 @@ func TestFileStore_FindByFingerprint(t *testing.T) {
|
||||
func TestFileStore_IsPrimary(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
)
|
||||
|
||||
@@ -23,8 +23,8 @@ func (r fingerprintQueryRow) valid() bool {
|
||||
return r.Type.Valid
|
||||
}
|
||||
|
||||
func (r *fingerprintQueryRow) resolve() file.Fingerprint {
|
||||
return file.Fingerprint{
|
||||
func (r *fingerprintQueryRow) resolve() models.Fingerprint {
|
||||
return models.Fingerprint{
|
||||
Type: r.Type.String,
|
||||
Fingerprint: r.Fingerprint,
|
||||
}
|
||||
@@ -45,7 +45,7 @@ var FingerprintReaderWriter = &fingerprintQueryBuilder{
|
||||
tableMgr: fingerprintTableMgr,
|
||||
}
|
||||
|
||||
func (qb *fingerprintQueryBuilder) insert(ctx context.Context, fileID file.ID, f file.Fingerprint) error {
|
||||
func (qb *fingerprintQueryBuilder) insert(ctx context.Context, fileID models.FileID, f models.Fingerprint) error {
|
||||
table := qb.table()
|
||||
q := dialect.Insert(table).Cols(fileIDColumn, "type", "fingerprint").Vals(
|
||||
goqu.Vals{fileID, f.Type, f.Fingerprint},
|
||||
@@ -58,7 +58,7 @@ func (qb *fingerprintQueryBuilder) insert(ctx context.Context, fileID file.ID, f
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *fingerprintQueryBuilder) insertJoins(ctx context.Context, fileID file.ID, f []file.Fingerprint) error {
|
||||
func (qb *fingerprintQueryBuilder) insertJoins(ctx context.Context, fileID models.FileID, f []models.Fingerprint) error {
|
||||
for _, ff := range f {
|
||||
if err := qb.insert(ctx, fileID, ff); err != nil {
|
||||
return err
|
||||
@@ -68,7 +68,7 @@ func (qb *fingerprintQueryBuilder) insertJoins(ctx context.Context, fileID file.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *fingerprintQueryBuilder) replaceJoins(ctx context.Context, fileID file.ID, f []file.Fingerprint) error {
|
||||
func (qb *fingerprintQueryBuilder) replaceJoins(ctx context.Context, fileID models.FileID, f []models.Fingerprint) error {
|
||||
if err := qb.destroy(ctx, []int{int(fileID)}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,23 +10,23 @@ import (
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
)
|
||||
|
||||
const folderTable = "folders"
|
||||
|
||||
type folderRow struct {
|
||||
ID file.FolderID `db:"id" goqu:"skipinsert"`
|
||||
Path string `db:"path"`
|
||||
ZipFileID null.Int `db:"zip_file_id"`
|
||||
ParentFolderID null.Int `db:"parent_folder_id"`
|
||||
ModTime Timestamp `db:"mod_time"`
|
||||
CreatedAt Timestamp `db:"created_at"`
|
||||
UpdatedAt Timestamp `db:"updated_at"`
|
||||
ID models.FolderID `db:"id" goqu:"skipinsert"`
|
||||
Path string `db:"path"`
|
||||
ZipFileID null.Int `db:"zip_file_id"`
|
||||
ParentFolderID null.Int `db:"parent_folder_id"`
|
||||
ModTime Timestamp `db:"mod_time"`
|
||||
CreatedAt Timestamp `db:"created_at"`
|
||||
UpdatedAt Timestamp `db:"updated_at"`
|
||||
}
|
||||
|
||||
func (r *folderRow) fromFolder(o file.Folder) {
|
||||
func (r *folderRow) fromFolder(o models.Folder) {
|
||||
r.ID = o.ID
|
||||
r.Path = o.Path
|
||||
r.ZipFileID = nullIntFromFileIDPtr(o.ZipFileID)
|
||||
@@ -43,10 +43,10 @@ type folderQueryRow struct {
|
||||
ZipFolderPath null.String `db:"zip_folder_path"`
|
||||
}
|
||||
|
||||
func (r *folderQueryRow) resolve() *file.Folder {
|
||||
ret := &file.Folder{
|
||||
func (r *folderQueryRow) resolve() *models.Folder {
|
||||
ret := &models.Folder{
|
||||
ID: r.ID,
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: nullIntFileIDPtr(r.ZipFileID),
|
||||
ModTime: r.ModTime.Timestamp,
|
||||
},
|
||||
@@ -57,7 +57,7 @@ func (r *folderQueryRow) resolve() *file.Folder {
|
||||
}
|
||||
|
||||
if ret.ZipFileID != nil && r.ZipFolderPath.Valid && r.ZipBasename.Valid {
|
||||
ret.ZipFile = &file.BaseFile{
|
||||
ret.ZipFile = &models.BaseFile{
|
||||
ID: *ret.ZipFileID,
|
||||
Path: filepath.Join(r.ZipFolderPath.String, r.ZipBasename.String),
|
||||
Basename: r.ZipBasename.String,
|
||||
@@ -69,8 +69,8 @@ func (r *folderQueryRow) resolve() *file.Folder {
|
||||
|
||||
type folderQueryRows []folderQueryRow
|
||||
|
||||
func (r folderQueryRows) resolve() []*file.Folder {
|
||||
var ret []*file.Folder
|
||||
func (r folderQueryRows) resolve() []*models.Folder {
|
||||
var ret []*models.Folder
|
||||
|
||||
for _, row := range r {
|
||||
f := row.resolve()
|
||||
@@ -97,7 +97,7 @@ func NewFolderStore() *FolderStore {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *FolderStore) Create(ctx context.Context, f *file.Folder) error {
|
||||
func (qb *FolderStore) Create(ctx context.Context, f *models.Folder) error {
|
||||
var r folderRow
|
||||
r.fromFolder(*f)
|
||||
|
||||
@@ -107,12 +107,12 @@ func (qb *FolderStore) Create(ctx context.Context, f *file.Folder) error {
|
||||
}
|
||||
|
||||
// only assign id once we are successful
|
||||
f.ID = file.FolderID(id)
|
||||
f.ID = models.FolderID(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) Update(ctx context.Context, updatedObject *file.Folder) error {
|
||||
func (qb *FolderStore) Update(ctx context.Context, updatedObject *models.Folder) error {
|
||||
var r folderRow
|
||||
r.fromFolder(*updatedObject)
|
||||
|
||||
@@ -123,7 +123,7 @@ func (qb *FolderStore) Update(ctx context.Context, updatedObject *file.Folder) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) Destroy(ctx context.Context, id file.FolderID) error {
|
||||
func (qb *FolderStore) Destroy(ctx context.Context, id models.FolderID) error {
|
||||
return qb.tableMgr.destroyExisting(ctx, []int{int(id)})
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (qb *FolderStore) countDataset() *goqu.SelectDataset {
|
||||
)
|
||||
}
|
||||
|
||||
func (qb *FolderStore) get(ctx context.Context, q *goqu.SelectDataset) (*file.Folder, error) {
|
||||
func (qb *FolderStore) get(ctx context.Context, q *goqu.SelectDataset) (*models.Folder, error) {
|
||||
ret, err := qb.getMany(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -192,7 +192,7 @@ func (qb *FolderStore) get(ctx context.Context, q *goqu.SelectDataset) (*file.Fo
|
||||
return ret[0], nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*file.Folder, error) {
|
||||
func (qb *FolderStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*models.Folder, error) {
|
||||
const single = false
|
||||
var rows folderQueryRows
|
||||
if err := queryFunc(ctx, q, single, func(r *sqlx.Rows) error {
|
||||
@@ -210,7 +210,7 @@ func (qb *FolderStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*f
|
||||
return rows.resolve(), nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) Find(ctx context.Context, id file.FolderID) (*file.Folder, error) {
|
||||
func (qb *FolderStore) Find(ctx context.Context, id models.FolderID) (*models.Folder, error) {
|
||||
q := qb.selectDataset().Where(qb.tableMgr.byID(id))
|
||||
|
||||
ret, err := qb.get(ctx, q)
|
||||
@@ -221,7 +221,7 @@ func (qb *FolderStore) Find(ctx context.Context, id file.FolderID) (*file.Folder
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) FindByPath(ctx context.Context, p string) (*file.Folder, error) {
|
||||
func (qb *FolderStore) FindByPath(ctx context.Context, p string) (*models.Folder, error) {
|
||||
q := qb.selectDataset().Prepared(true).Where(qb.table().Col("path").Eq(p))
|
||||
|
||||
ret, err := qb.get(ctx, q)
|
||||
@@ -232,7 +232,7 @@ func (qb *FolderStore) FindByPath(ctx context.Context, p string) (*file.Folder,
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *FolderStore) FindByParentFolderID(ctx context.Context, parentFolderID file.FolderID) ([]*file.Folder, error) {
|
||||
func (qb *FolderStore) FindByParentFolderID(ctx context.Context, parentFolderID models.FolderID) ([]*models.Folder, error) {
|
||||
q := qb.selectDataset().Where(qb.table().Col("parent_folder_id").Eq(int(parentFolderID)))
|
||||
|
||||
ret, err := qb.getMany(ctx, q)
|
||||
@@ -261,7 +261,7 @@ func (qb *FolderStore) allInPaths(q *goqu.SelectDataset, p []string) *goqu.Selec
|
||||
// FindAllInPaths returns the all folders that are or are within any of the given paths.
|
||||
// Returns all if limit is < 0.
|
||||
// Returns all folders if p is empty.
|
||||
func (qb *FolderStore) FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]*file.Folder, error) {
|
||||
func (qb *FolderStore) FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]*models.Folder, error) {
|
||||
q := qb.selectDataset().Prepared(true)
|
||||
q = qb.allInPaths(q, p)
|
||||
|
||||
@@ -300,7 +300,7 @@ func (qb *FolderStore) CountAllInPaths(ctx context.Context, p []string) (int, er
|
||||
// return qb.getMany(ctx, q)
|
||||
// }
|
||||
|
||||
func (qb *FolderStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]*file.Folder, error) {
|
||||
func (qb *FolderStore) FindByZipFileID(ctx context.Context, zipFileID models.FileID) ([]*models.Folder, error) {
|
||||
table := qb.table()
|
||||
|
||||
q := qb.selectDataset().Prepared(true).Where(
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
invalidFolderID = file.FolderID(invalidID)
|
||||
invalidFileID = file.ID(invalidID)
|
||||
invalidFolderID = models.FolderID(invalidID)
|
||||
invalidFileID = models.FileID(invalidID)
|
||||
)
|
||||
|
||||
func Test_FolderStore_Create(t *testing.T) {
|
||||
@@ -28,13 +28,13 @@ func Test_FolderStore_Create(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
newObject file.Folder
|
||||
newObject models.Folder
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"full",
|
||||
file.Folder{
|
||||
DirEntry: file.DirEntry{
|
||||
models.Folder{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -47,7 +47,7 @@ func Test_FolderStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid parent folder id",
|
||||
file.Folder{
|
||||
models.Folder{
|
||||
Path: path,
|
||||
ParentFolderID: &invalidFolderID,
|
||||
},
|
||||
@@ -55,8 +55,8 @@ func Test_FolderStore_Create(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid zip file id",
|
||||
file.Folder{
|
||||
DirEntry: file.DirEntry{
|
||||
models.Folder{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &invalidFileID,
|
||||
},
|
||||
Path: path,
|
||||
@@ -109,14 +109,14 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
updatedObject *file.Folder
|
||||
updatedObject *models.Folder
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"full",
|
||||
&file.Folder{
|
||||
&models.Folder{
|
||||
ID: folderIDs[folderIdxWithParentFolder],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &fileIDs[fileIdxZip],
|
||||
ZipFile: makeZipFileWithID(fileIdxZip),
|
||||
ModTime: fileModTime,
|
||||
@@ -129,7 +129,7 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"clear zip",
|
||||
&file.Folder{
|
||||
&models.Folder{
|
||||
ID: folderIDs[folderIdxInZip],
|
||||
Path: path,
|
||||
},
|
||||
@@ -137,7 +137,7 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"clear folder",
|
||||
&file.Folder{
|
||||
&models.Folder{
|
||||
ID: folderIDs[folderIdxWithParentFolder],
|
||||
Path: path,
|
||||
},
|
||||
@@ -145,7 +145,7 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid parent folder id",
|
||||
&file.Folder{
|
||||
&models.Folder{
|
||||
ID: folderIDs[folderIdxWithParentFolder],
|
||||
Path: path,
|
||||
ParentFolderID: &invalidFolderID,
|
||||
@@ -154,9 +154,9 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid zip file id",
|
||||
&file.Folder{
|
||||
&models.Folder{
|
||||
ID: folderIDs[folderIdxWithParentFolder],
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
ZipFileID: &invalidFileID,
|
||||
},
|
||||
Path: path,
|
||||
@@ -192,7 +192,7 @@ func Test_FolderStore_Update(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeFolderWithID(index int) *file.Folder {
|
||||
func makeFolderWithID(index int) *models.Folder {
|
||||
ret := makeFolder(index)
|
||||
ret.ID = folderIDs[index]
|
||||
|
||||
@@ -207,7 +207,7 @@ func Test_FolderStore_FindByPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
want *file.Folder
|
||||
want *models.Folder
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
@@ -163,7 +162,7 @@ func (qb *GalleryStore) selectDataset() *goqu.SelectDataset {
|
||||
)
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) Create(ctx context.Context, newObject *models.Gallery, fileIDs []file.ID) error {
|
||||
func (qb *GalleryStore) Create(ctx context.Context, newObject *models.Gallery, fileIDs []models.FileID) error {
|
||||
var r galleryRow
|
||||
r.fromGallery(*newObject)
|
||||
|
||||
@@ -230,7 +229,7 @@ func (qb *GalleryStore) Update(ctx context.Context, updatedObject *models.Galler
|
||||
}
|
||||
|
||||
if updatedObject.Files.Loaded() {
|
||||
fileIDs := make([]file.ID, len(updatedObject.Files.List()))
|
||||
fileIDs := make([]models.FileID, len(updatedObject.Files.List()))
|
||||
for i, f := range updatedObject.Files.List() {
|
||||
fileIDs[i] = f.Base().ID
|
||||
}
|
||||
@@ -287,7 +286,7 @@ func (qb *GalleryStore) Destroy(ctx context.Context, id int) error {
|
||||
return qb.tableMgr.destroyExisting(ctx, []int{id})
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) GetFiles(ctx context.Context, id int) ([]file.File, error) {
|
||||
func (qb *GalleryStore) GetFiles(ctx context.Context, id int) ([]models.File, error) {
|
||||
fileIDs, err := qb.filesRepository().get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -299,13 +298,13 @@ func (qb *GalleryStore) GetFiles(ctx context.Context, id int) ([]file.File, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([]file.File, len(files))
|
||||
ret := make([]models.File, len(files))
|
||||
copy(ret, files)
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]file.ID, error) {
|
||||
func (qb *GalleryStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]models.FileID, error) {
|
||||
const primaryOnly = false
|
||||
return qb.filesRepository().getMany(ctx, ids, primaryOnly)
|
||||
}
|
||||
@@ -412,7 +411,7 @@ func (qb *GalleryStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Gallery, error) {
|
||||
func (qb *GalleryStore) FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Gallery, error) {
|
||||
sq := dialect.From(galleriesFilesJoinTable).Select(galleriesFilesJoinTable.Col(galleryIDColumn)).Where(
|
||||
galleriesFilesJoinTable.Col(fileIDColumn).Eq(fileID),
|
||||
)
|
||||
@@ -425,14 +424,14 @@ func (qb *GalleryStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*mo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) CountByFileID(ctx context.Context, fileID file.ID) (int, error) {
|
||||
func (qb *GalleryStore) CountByFileID(ctx context.Context, fileID models.FileID) (int, error) {
|
||||
joinTable := galleriesFilesJoinTable
|
||||
|
||||
q := dialect.Select(goqu.COUNT("*")).From(joinTable).Where(joinTable.Col(fileIDColumn).Eq(fileID))
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Gallery, error) {
|
||||
func (qb *GalleryStore) FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Gallery, error) {
|
||||
fingerprintTable := fingerprintTableMgr.table
|
||||
|
||||
var ex []exp.Expression
|
||||
@@ -460,20 +459,20 @@ func (qb *GalleryStore) FindByFingerprints(ctx context.Context, fp []file.Finger
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) FindByChecksum(ctx context.Context, checksum string) ([]*models.Gallery, error) {
|
||||
return qb.FindByFingerprints(ctx, []file.Fingerprint{
|
||||
return qb.FindByFingerprints(ctx, []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: checksum,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) FindByChecksums(ctx context.Context, checksums []string) ([]*models.Gallery, error) {
|
||||
fingerprints := make([]file.Fingerprint, len(checksums))
|
||||
fingerprints := make([]models.Fingerprint, len(checksums))
|
||||
|
||||
for i, c := range checksums {
|
||||
fingerprints[i] = file.Fingerprint{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
fingerprints[i] = models.Fingerprint{
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: c,
|
||||
}
|
||||
}
|
||||
@@ -519,7 +518,7 @@ func (qb *GalleryStore) FindByPath(ctx context.Context, p string) ([]*models.Gal
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) FindByFolderID(ctx context.Context, folderID file.FolderID) ([]*models.Gallery, error) {
|
||||
func (qb *GalleryStore) FindByFolderID(ctx context.Context, folderID models.FolderID) ([]*models.Gallery, error) {
|
||||
table := qb.table()
|
||||
|
||||
sq := dialect.From(table).Select(table.Col(idColumn)).Where(
|
||||
@@ -1118,9 +1117,9 @@ func (qb *GalleryStore) filesRepository() *filesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) AddFileID(ctx context.Context, id int, fileID file.ID) error {
|
||||
func (qb *GalleryStore) AddFileID(ctx context.Context, id int, fileID models.FileID) error {
|
||||
const firstPrimary = false
|
||||
return galleriesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []file.ID{fileID})
|
||||
return galleriesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []models.FileID{fileID})
|
||||
}
|
||||
|
||||
func (qb *GalleryStore) performersRepository() *joinRepository {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -97,7 +96,7 @@ func Test_galleryQueryBuilder_Create(t *testing.T) {
|
||||
Rating: &rating,
|
||||
Organized: true,
|
||||
StudioID: &studioIDs[studioIdxWithScene],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
galleryFile,
|
||||
}),
|
||||
CreatedAt: createdAt,
|
||||
@@ -145,9 +144,9 @@ func Test_galleryQueryBuilder_Create(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := tt.newObject
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
if s.Files.Loaded() {
|
||||
fileIDs = []file.ID{s.Files.List()[0].Base().ID}
|
||||
fileIDs = []models.FileID{s.Files.List()[0].Base().ID}
|
||||
}
|
||||
|
||||
if err := qb.Create(ctx, &s, fileIDs); (err != nil) != tt.wantErr {
|
||||
@@ -195,7 +194,7 @@ func Test_galleryQueryBuilder_Create(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeGalleryFileWithID(i int) *file.BaseFile {
|
||||
func makeGalleryFileWithID(i int) *models.BaseFile {
|
||||
ret := makeGalleryFile(i)
|
||||
ret.ID = galleryFileIDs[i]
|
||||
return ret
|
||||
@@ -229,7 +228,7 @@ func Test_galleryQueryBuilder_Update(t *testing.T) {
|
||||
Rating: &rating,
|
||||
Organized: true,
|
||||
StudioID: &studioIDs[studioIdxWithScene],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
makeGalleryFileWithID(galleryIdxWithScene),
|
||||
}),
|
||||
CreatedAt: createdAt,
|
||||
@@ -449,7 +448,7 @@ func Test_galleryQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
Rating: &rating,
|
||||
Organized: true,
|
||||
StudioID: &studioIDs[studioIdxWithGallery],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
makeGalleryFile(galleryIdxWithImage),
|
||||
}),
|
||||
CreatedAt: createdAt,
|
||||
@@ -466,7 +465,7 @@ func Test_galleryQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
clearGalleryPartial(),
|
||||
models.Gallery{
|
||||
ID: galleryIDs[galleryIdxWithImage],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
makeGalleryFile(galleryIdxWithImage),
|
||||
}),
|
||||
SceneIDs: models.NewRelatedIDs([]int{}),
|
||||
@@ -844,7 +843,7 @@ func makeGalleryWithID(index int) *models.Gallery {
|
||||
ret := makeGallery(index, includeScenes)
|
||||
ret.ID = galleryIDs[index]
|
||||
|
||||
ret.Files = models.NewRelatedFiles([]file.File{makeGalleryFile(index)})
|
||||
ret.Files = models.NewRelatedFiles([]models.File{makeGalleryFile(index)})
|
||||
|
||||
return ret
|
||||
}
|
||||
@@ -1281,7 +1280,7 @@ func galleriesToIDs(i []*models.Gallery) []int {
|
||||
func Test_galleryStore_FindByFileID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
@@ -1330,7 +1329,7 @@ func Test_galleryStore_FindByFileID(t *testing.T) {
|
||||
func Test_galleryStore_FindByFolderID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
folderID file.FolderID
|
||||
folderID models.FolderID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
@@ -150,7 +149,7 @@ func (qb *ImageStore) selectDataset() *goqu.SelectDataset {
|
||||
checksum,
|
||||
goqu.On(
|
||||
checksum.Col(fileIDColumn).Eq(imagesFilesJoinTable.Col(fileIDColumn)),
|
||||
checksum.Col("type").Eq(file.FingerprintTypeMD5),
|
||||
checksum.Col("type").Eq(models.FingerprintTypeMD5),
|
||||
),
|
||||
).Select(
|
||||
qb.table().All(),
|
||||
@@ -271,7 +270,7 @@ func (qb *ImageStore) Update(ctx context.Context, updatedObject *models.Image) e
|
||||
}
|
||||
|
||||
if updatedObject.Files.Loaded() {
|
||||
fileIDs := make([]file.ID, len(updatedObject.Files.List()))
|
||||
fileIDs := make([]models.FileID, len(updatedObject.Files.List()))
|
||||
for i, f := range updatedObject.Files.List() {
|
||||
fileIDs[i] = f.Base().ID
|
||||
}
|
||||
@@ -389,7 +388,7 @@ func (qb *ImageStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*mo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]file.File, error) {
|
||||
func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]models.File, error) {
|
||||
fileIDs, err := qb.filesRepository().get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -404,12 +403,12 @@ func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]file.File, error)
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]file.ID, error) {
|
||||
func (qb *ImageStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]models.FileID, error) {
|
||||
const primaryOnly = false
|
||||
return qb.filesRepository().getMany(ctx, ids, primaryOnly)
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
|
||||
sq := dialect.From(table).
|
||||
@@ -427,14 +426,14 @@ func (qb *ImageStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*mode
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) CountByFileID(ctx context.Context, fileID file.ID) (int, error) {
|
||||
func (qb *ImageStore) CountByFileID(ctx context.Context, fileID models.FileID) (int, error) {
|
||||
joinTable := imagesFilesJoinTable
|
||||
|
||||
q := dialect.Select(goqu.COUNT("*")).From(joinTable).Where(joinTable.Col(fileIDColumn).Eq(fileID))
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fingerprintTable := fingerprintTableMgr.table
|
||||
|
||||
@@ -467,9 +466,9 @@ func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []file.Fingerpr
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByChecksum(ctx context.Context, checksum string) ([]*models.Image, error) {
|
||||
return qb.FindByFingerprints(ctx, []file.Fingerprint{
|
||||
return qb.FindByFingerprints(ctx, []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: checksum,
|
||||
},
|
||||
})
|
||||
@@ -523,7 +522,7 @@ func (qb *ImageStore) OCountByPerformerID(ctx context.Context, performerID int)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID file.FolderID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID models.FolderID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fileTable := goqu.T(fileTable)
|
||||
|
||||
@@ -548,7 +547,7 @@ func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID file.FolderID
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByZipFileID(ctx context.Context, zipFileID models.FileID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fileTable := goqu.T(fileTable)
|
||||
|
||||
@@ -1043,9 +1042,9 @@ func (qb *ImageStore) filesRepository() *filesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *ImageStore) AddFileID(ctx context.Context, id int, fileID file.ID) error {
|
||||
func (qb *ImageStore) AddFileID(ctx context.Context, id int, fileID models.FileID) error {
|
||||
const firstPrimary = false
|
||||
return imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []file.ID{fileID})
|
||||
return imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []models.FileID{fileID})
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetGalleryIDs(ctx context.Context, imageID int) ([]int, error) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -97,8 +96,8 @@ func Test_imageQueryBuilder_Create(t *testing.T) {
|
||||
Organized: true,
|
||||
OCounter: ocounter,
|
||||
StudioID: &studioIDs[studioIdxWithImage],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
imageFile.(*file.ImageFile),
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
imageFile.(*models.ImageFile),
|
||||
}),
|
||||
PrimaryFileID: &imageFile.Base().ID,
|
||||
Path: imageFile.Base().Path,
|
||||
@@ -146,7 +145,7 @@ func Test_imageQueryBuilder_Create(t *testing.T) {
|
||||
runWithRollbackTxn(t, tt.name, func(t *testing.T, ctx context.Context) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
if tt.newObject.Files.Loaded() {
|
||||
for _, f := range tt.newObject.Files.List() {
|
||||
fileIDs = append(fileIDs, f.Base().ID)
|
||||
@@ -205,7 +204,7 @@ func clearImageFileIDs(image *models.Image) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeImageFileWithID(i int) *file.ImageFile {
|
||||
func makeImageFileWithID(i int) *models.ImageFile {
|
||||
ret := makeImageFile(i)
|
||||
ret.ID = imageFileIDs[i]
|
||||
return ret
|
||||
@@ -444,7 +443,7 @@ func Test_imageQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
Organized: true,
|
||||
OCounter: ocounter,
|
||||
StudioID: &studioIDs[studioIdxWithImage],
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
makeImageFile(imageIdx1WithGallery),
|
||||
}),
|
||||
CreatedAt: createdAt,
|
||||
@@ -462,7 +461,7 @@ func Test_imageQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
models.Image{
|
||||
ID: imageIDs[imageIdx1WithGallery],
|
||||
OCounter: getOCounter(imageIdx1WithGallery),
|
||||
Files: models.NewRelatedFiles([]file.File{
|
||||
Files: models.NewRelatedFiles([]models.File{
|
||||
makeImageFile(imageIdx1WithGallery),
|
||||
}),
|
||||
GalleryIDs: models.NewRelatedIDs([]int{}),
|
||||
@@ -965,7 +964,7 @@ func makeImageWithID(index int) *models.Image {
|
||||
ret := makeImage(index)
|
||||
ret.ID = imageIDs[index]
|
||||
|
||||
ret.Files = models.NewRelatedFiles([]file.File{makeImageFile(index)})
|
||||
ret.Files = models.NewRelatedFiles([]models.File{makeImageFile(index)})
|
||||
|
||||
return ret
|
||||
}
|
||||
@@ -1153,15 +1152,15 @@ func Test_imageQueryBuilder_FindByFingerprints(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fingerprints []file.Fingerprint
|
||||
fingerprints []models.Fingerprint
|
||||
want []*models.Image
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
[]file.Fingerprint{
|
||||
[]models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getChecksum(imageIdxWithGallery),
|
||||
},
|
||||
},
|
||||
@@ -1170,9 +1169,9 @@ func Test_imageQueryBuilder_FindByFingerprints(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid",
|
||||
[]file.Fingerprint{
|
||||
[]models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: "invalid checksum",
|
||||
},
|
||||
},
|
||||
@@ -1181,9 +1180,9 @@ func Test_imageQueryBuilder_FindByFingerprints(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"with performers",
|
||||
[]file.Fingerprint{
|
||||
[]models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getChecksum(imageIdxWithTwoPerformers),
|
||||
},
|
||||
},
|
||||
@@ -1192,9 +1191,9 @@ func Test_imageQueryBuilder_FindByFingerprints(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"with tags",
|
||||
[]file.Fingerprint{
|
||||
[]models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getChecksum(imageIdxWithTwoTags),
|
||||
},
|
||||
},
|
||||
@@ -1316,7 +1315,7 @@ func imagesToIDs(i []*models.Image) []int {
|
||||
func Test_imageStore_FindByFileID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
@@ -1365,7 +1364,7 @@ func Test_imageStore_FindByFileID(t *testing.T) {
|
||||
func Test_imageStore_FindByFolderID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
folderID file.FolderID
|
||||
folderID models.FolderID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
@@ -1420,7 +1419,7 @@ func Test_imageStore_FindByFolderID(t *testing.T) {
|
||||
func Test_imageStore_FindByZipFileID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
zipFileID file.ID
|
||||
zipFileID models.FileID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
@@ -1868,11 +1867,12 @@ func verifyImagesResolution(t *testing.T, resolution models.ResolutionEnum) {
|
||||
t.Errorf("Error loading primary file: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
asFrame, ok := image.Files.Primary().(file.VisualFile)
|
||||
f := image.Files.Primary()
|
||||
vf, ok := f.(models.VisualFile)
|
||||
if !ok {
|
||||
t.Errorf("Error: Associated primary file of image is not of type VisualFile")
|
||||
t.Errorf("Error: image primary file is not a visual file (is type %T)", f)
|
||||
}
|
||||
verifyImageResolution(t, asFrame.GetHeight(), resolution)
|
||||
verifyImageResolution(t, vf.GetHeight(), resolution)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
@@ -336,7 +335,7 @@ type captionRepository struct {
|
||||
repository
|
||||
}
|
||||
|
||||
func (r *captionRepository) get(ctx context.Context, id file.ID) ([]*models.VideoCaption, error) {
|
||||
func (r *captionRepository) get(ctx context.Context, id models.FileID) ([]*models.VideoCaption, error) {
|
||||
query := fmt.Sprintf("SELECT %s, %s, %s from %s WHERE %s = ?", captionCodeColumn, captionFilenameColumn, captionTypeColumn, r.tableName, r.idColumn)
|
||||
var ret []*models.VideoCaption
|
||||
err := r.queryFunc(ctx, query, []interface{}{id}, false, func(rows *sqlx.Rows) error {
|
||||
@@ -359,12 +358,12 @@ func (r *captionRepository) get(ctx context.Context, id file.ID) ([]*models.Vide
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (r *captionRepository) insert(ctx context.Context, id file.ID, caption *models.VideoCaption) (sql.Result, error) {
|
||||
func (r *captionRepository) insert(ctx context.Context, id models.FileID, caption *models.VideoCaption) (sql.Result, error) {
|
||||
stmt := fmt.Sprintf("INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, ?)", r.tableName, r.idColumn, captionCodeColumn, captionFilenameColumn, captionTypeColumn)
|
||||
return r.tx.Exec(ctx, stmt, id, caption.LanguageCode, caption.Filename, caption.CaptionType)
|
||||
}
|
||||
|
||||
func (r *captionRepository) replace(ctx context.Context, id file.ID, captions []*models.VideoCaption) error {
|
||||
func (r *captionRepository) replace(ctx context.Context, id models.FileID, captions []*models.VideoCaption) error {
|
||||
if err := r.destroy(ctx, []int{int(id)}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -443,12 +442,12 @@ type filesRepository struct {
|
||||
}
|
||||
|
||||
type relatedFileRow struct {
|
||||
ID int `db:"id"`
|
||||
FileID file.ID `db:"file_id"`
|
||||
Primary bool `db:"primary"`
|
||||
ID int `db:"id"`
|
||||
FileID models.FileID `db:"file_id"`
|
||||
Primary bool `db:"primary"`
|
||||
}
|
||||
|
||||
func (r *filesRepository) getMany(ctx context.Context, ids []int, primaryOnly bool) ([][]file.ID, error) {
|
||||
func (r *filesRepository) getMany(ctx context.Context, ids []int, primaryOnly bool) ([][]models.FileID, error) {
|
||||
var primaryClause string
|
||||
if primaryOnly {
|
||||
primaryClause = " AND `primary` = 1"
|
||||
@@ -476,7 +475,7 @@ func (r *filesRepository) getMany(ctx context.Context, ids []int, primaryOnly bo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([][]file.ID, len(ids))
|
||||
ret := make([][]models.FileID, len(ids))
|
||||
idToIndex := make(map[int]int)
|
||||
for i, id := range ids {
|
||||
idToIndex[id] = i
|
||||
@@ -488,7 +487,7 @@ func (r *filesRepository) getMany(ctx context.Context, ids []int, primaryOnly bo
|
||||
|
||||
if row.Primary {
|
||||
// prepend to list
|
||||
ret[idToIndex[id]] = append([]file.ID{fileID}, ret[idToIndex[id]]...)
|
||||
ret[idToIndex[id]] = append([]models.FileID{fileID}, ret[idToIndex[id]]...)
|
||||
} else {
|
||||
ret[idToIndex[id]] = append(ret[idToIndex[id]], row.FileID)
|
||||
}
|
||||
@@ -497,15 +496,15 @@ func (r *filesRepository) getMany(ctx context.Context, ids []int, primaryOnly bo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *filesRepository) get(ctx context.Context, id int) ([]file.ID, error) {
|
||||
func (r *filesRepository) get(ctx context.Context, id int) ([]models.FileID, error) {
|
||||
query := fmt.Sprintf("SELECT file_id, `primary` from %s WHERE %s = ?", r.tableName, r.idColumn)
|
||||
|
||||
type relatedFile struct {
|
||||
FileID file.ID `db:"file_id"`
|
||||
Primary bool `db:"primary"`
|
||||
FileID models.FileID `db:"file_id"`
|
||||
Primary bool `db:"primary"`
|
||||
}
|
||||
|
||||
var ret []file.ID
|
||||
var ret []models.FileID
|
||||
if err := r.queryFunc(ctx, query, []interface{}{id}, false, func(rows *sqlx.Rows) error {
|
||||
var f relatedFile
|
||||
|
||||
@@ -515,7 +514,7 @@ func (r *filesRepository) get(ctx context.Context, id int) ([]file.ID, error) {
|
||||
|
||||
if f.Primary {
|
||||
// prepend to list
|
||||
ret = append([]file.ID{f.FileID}, ret...)
|
||||
ret = append([]models.FileID{f.FileID}, ret...)
|
||||
} else {
|
||||
ret = append(ret, f.FileID)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"gopkg.in/guregu/null.v4"
|
||||
"gopkg.in/guregu/null.v4/zero"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
@@ -232,13 +231,13 @@ func (qb *SceneStore) selectDataset() *goqu.SelectDataset {
|
||||
checksum,
|
||||
goqu.On(
|
||||
checksum.Col(fileIDColumn).Eq(scenesFilesJoinTable.Col(fileIDColumn)),
|
||||
checksum.Col("type").Eq(file.FingerprintTypeMD5),
|
||||
checksum.Col("type").Eq(models.FingerprintTypeMD5),
|
||||
),
|
||||
).LeftJoin(
|
||||
oshash,
|
||||
goqu.On(
|
||||
oshash.Col(fileIDColumn).Eq(scenesFilesJoinTable.Col(fileIDColumn)),
|
||||
oshash.Col("type").Eq(file.FingerprintTypeOshash),
|
||||
oshash.Col("type").Eq(models.FingerprintTypeOshash),
|
||||
),
|
||||
).Select(
|
||||
qb.table().All(),
|
||||
@@ -250,7 +249,7 @@ func (qb *SceneStore) selectDataset() *goqu.SelectDataset {
|
||||
)
|
||||
}
|
||||
|
||||
func (qb *SceneStore) Create(ctx context.Context, newObject *models.Scene, fileIDs []file.ID) error {
|
||||
func (qb *SceneStore) Create(ctx context.Context, newObject *models.Scene, fileIDs []models.FileID) error {
|
||||
var r sceneRow
|
||||
r.fromScene(*newObject)
|
||||
|
||||
@@ -411,7 +410,7 @@ func (qb *SceneStore) Update(ctx context.Context, updatedObject *models.Scene) e
|
||||
}
|
||||
|
||||
if updatedObject.Files.Loaded() {
|
||||
fileIDs := make([]file.ID, len(updatedObject.Files.List()))
|
||||
fileIDs := make([]models.FileID, len(updatedObject.Files.List()))
|
||||
for i, f := range updatedObject.Files.List() {
|
||||
fileIDs[i] = f.ID
|
||||
}
|
||||
@@ -538,7 +537,7 @@ func (qb *SceneStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*mo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *SceneStore) GetFiles(ctx context.Context, id int) ([]*file.VideoFile, error) {
|
||||
func (qb *SceneStore) GetFiles(ctx context.Context, id int) ([]*models.VideoFile, error) {
|
||||
fileIDs, err := qb.filesRepository().get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -550,10 +549,10 @@ func (qb *SceneStore) GetFiles(ctx context.Context, id int) ([]*file.VideoFile,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([]*file.VideoFile, len(files))
|
||||
ret := make([]*models.VideoFile, len(files))
|
||||
for i, f := range files {
|
||||
var ok bool
|
||||
ret[i], ok = f.(*file.VideoFile)
|
||||
ret[i], ok = f.(*models.VideoFile)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected file to be *file.VideoFile not %T", f)
|
||||
}
|
||||
@@ -562,12 +561,12 @@ func (qb *SceneStore) GetFiles(ctx context.Context, id int) ([]*file.VideoFile,
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *SceneStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]file.ID, error) {
|
||||
func (qb *SceneStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]models.FileID, error) {
|
||||
const primaryOnly = false
|
||||
return qb.filesRepository().getMany(ctx, ids, primaryOnly)
|
||||
}
|
||||
|
||||
func (qb *SceneStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Scene, error) {
|
||||
func (qb *SceneStore) FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Scene, error) {
|
||||
sq := dialect.From(scenesFilesJoinTable).Select(scenesFilesJoinTable.Col(sceneIDColumn)).Where(
|
||||
scenesFilesJoinTable.Col(fileIDColumn).Eq(fileID),
|
||||
)
|
||||
@@ -580,7 +579,7 @@ func (qb *SceneStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*mode
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *SceneStore) FindByPrimaryFileID(ctx context.Context, fileID file.ID) ([]*models.Scene, error) {
|
||||
func (qb *SceneStore) FindByPrimaryFileID(ctx context.Context, fileID models.FileID) ([]*models.Scene, error) {
|
||||
sq := dialect.From(scenesFilesJoinTable).Select(scenesFilesJoinTable.Col(sceneIDColumn)).Where(
|
||||
scenesFilesJoinTable.Col(fileIDColumn).Eq(fileID),
|
||||
scenesFilesJoinTable.Col("primary").Eq(1),
|
||||
@@ -594,14 +593,14 @@ func (qb *SceneStore) FindByPrimaryFileID(ctx context.Context, fileID file.ID) (
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *SceneStore) CountByFileID(ctx context.Context, fileID file.ID) (int, error) {
|
||||
func (qb *SceneStore) CountByFileID(ctx context.Context, fileID models.FileID) (int, error) {
|
||||
joinTable := scenesFilesJoinTable
|
||||
|
||||
q := dialect.Select(goqu.COUNT("*")).From(joinTable).Where(joinTable.Col(fileIDColumn).Eq(fileID))
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *SceneStore) FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Scene, error) {
|
||||
func (qb *SceneStore) FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Scene, error) {
|
||||
fingerprintTable := fingerprintTableMgr.table
|
||||
|
||||
var ex []exp.Expression
|
||||
@@ -629,18 +628,18 @@ func (qb *SceneStore) FindByFingerprints(ctx context.Context, fp []file.Fingerpr
|
||||
}
|
||||
|
||||
func (qb *SceneStore) FindByChecksum(ctx context.Context, checksum string) ([]*models.Scene, error) {
|
||||
return qb.FindByFingerprints(ctx, []file.Fingerprint{
|
||||
return qb.FindByFingerprints(ctx, []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: checksum,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (qb *SceneStore) FindByOSHash(ctx context.Context, oshash string) ([]*models.Scene, error) {
|
||||
return qb.FindByFingerprints(ctx, []file.Fingerprint{
|
||||
return qb.FindByFingerprints(ctx, []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeOshash,
|
||||
Type: models.FingerprintTypeOshash,
|
||||
Fingerprint: oshash,
|
||||
},
|
||||
})
|
||||
@@ -1684,7 +1683,7 @@ func (qb *SceneStore) destroyCover(ctx context.Context, sceneID int) error {
|
||||
return qb.DestroyImage(ctx, sceneID, sceneCoverBlobColumn)
|
||||
}
|
||||
|
||||
func (qb *SceneStore) AssignFiles(ctx context.Context, sceneID int, fileIDs []file.ID) error {
|
||||
func (qb *SceneStore) AssignFiles(ctx context.Context, sceneID int, fileIDs []models.FileID) error {
|
||||
// assuming a file can only be assigned to a single scene
|
||||
if err := scenesFilesTableMgr.destroyJoins(ctx, fileIDs); err != nil {
|
||||
return err
|
||||
@@ -1736,9 +1735,9 @@ func (qb *SceneStore) filesRepository() *filesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *SceneStore) AddFileID(ctx context.Context, id int, fileID file.ID) error {
|
||||
func (qb *SceneStore) AddFileID(ctx context.Context, id int, fileID models.FileID) error {
|
||||
const firstPrimary = false
|
||||
return scenesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []file.ID{fileID})
|
||||
return scenesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []models.FileID{fileID})
|
||||
}
|
||||
|
||||
func (qb *SceneStore) performersRepository() *joinRepository {
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -165,8 +164,8 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
|
||||
Organized: true,
|
||||
OCounter: ocounter,
|
||||
StudioID: &studioIDs[studioIdxWithScene],
|
||||
Files: models.NewRelatedVideoFiles([]*file.VideoFile{
|
||||
videoFile.(*file.VideoFile),
|
||||
Files: models.NewRelatedVideoFiles([]*models.VideoFile{
|
||||
videoFile.(*models.VideoFile),
|
||||
}),
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
@@ -248,7 +247,7 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
|
||||
runWithRollbackTxn(t, tt.name, func(t *testing.T, ctx context.Context) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
if tt.newObject.Files.Loaded() {
|
||||
for _, f := range tt.newObject.Files.List() {
|
||||
fileIDs = append(fileIDs, f.ID)
|
||||
@@ -308,7 +307,7 @@ func clearSceneFileIDs(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeSceneFileWithID(i int) *file.VideoFile {
|
||||
func makeSceneFileWithID(i int) *models.VideoFile {
|
||||
ret := makeSceneFile(i)
|
||||
ret.ID = sceneFileIDs[i]
|
||||
return ret
|
||||
@@ -626,7 +625,7 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
},
|
||||
models.Scene{
|
||||
ID: sceneIDs[sceneIdxWithSpacedName],
|
||||
Files: models.NewRelatedVideoFiles([]*file.VideoFile{
|
||||
Files: models.NewRelatedVideoFiles([]*models.VideoFile{
|
||||
makeSceneFile(sceneIdxWithSpacedName),
|
||||
}),
|
||||
Title: title,
|
||||
@@ -678,7 +677,7 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
|
||||
models.Scene{
|
||||
ID: sceneIDs[sceneIdxWithSpacedName],
|
||||
OCounter: getOCounter(sceneIdxWithSpacedName),
|
||||
Files: models.NewRelatedVideoFiles([]*file.VideoFile{
|
||||
Files: models.NewRelatedVideoFiles([]*models.VideoFile{
|
||||
makeSceneFile(sceneIdxWithSpacedName),
|
||||
}),
|
||||
GalleryIDs: models.NewRelatedIDs([]int{}),
|
||||
@@ -1460,7 +1459,7 @@ func makeSceneWithID(index int) *models.Scene {
|
||||
ret := makeScene(index)
|
||||
ret.ID = sceneIDs[index]
|
||||
|
||||
ret.Files = models.NewRelatedVideoFiles([]*file.VideoFile{makeSceneFile(index)})
|
||||
ret.Files = models.NewRelatedVideoFiles([]*models.VideoFile{makeSceneFile(index)})
|
||||
|
||||
return ret
|
||||
}
|
||||
@@ -1891,7 +1890,7 @@ func scenesToIDs(i []*models.Scene) []int {
|
||||
func Test_sceneStore_FindByFileID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
include []int
|
||||
exclude []int
|
||||
}{
|
||||
@@ -1940,7 +1939,7 @@ func Test_sceneStore_FindByFileID(t *testing.T) {
|
||||
func Test_sceneStore_CountByFileID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
want int
|
||||
}{
|
||||
{
|
||||
@@ -3053,8 +3052,8 @@ func queryScenes(ctx context.Context, t *testing.T, queryBuilder models.SceneRea
|
||||
func createScene(ctx context.Context, width int, height int) (*models.Scene, error) {
|
||||
name := fmt.Sprintf("TestSceneQueryResolutionModifiers %d %d", width, height)
|
||||
|
||||
sceneFile := &file.VideoFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
sceneFile := &models.VideoFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
Basename: name,
|
||||
ParentFolderID: folderIDs[folderIdxWithSceneFiles],
|
||||
},
|
||||
@@ -3068,7 +3067,7 @@ func createScene(ctx context.Context, width int, height int) (*models.Scene, err
|
||||
|
||||
scene := &models.Scene{}
|
||||
|
||||
if err := db.Scene.Create(ctx, scene, []file.ID{sceneFile.ID}); err != nil {
|
||||
if err := db.Scene.Create(ctx, scene, []models.FileID{sceneFile.ID}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4559,7 +4558,7 @@ func TestSceneStore_AssignFiles(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
sceneID int
|
||||
fileID file.ID
|
||||
fileID models.FileID
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -4587,7 +4586,7 @@ func TestSceneStore_AssignFiles(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
withRollbackTxn(func(ctx context.Context) error {
|
||||
if err := qb.AssignFiles(ctx, tt.sceneID, []file.ID{tt.fileID}); (err != nil) != tt.wantErr {
|
||||
if err := qb.AssignFiles(ctx, tt.sceneID, []models.FileID{tt.fileID}); (err != nil) != tt.wantErr {
|
||||
t.Errorf("SceneStore.AssignFiles() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"github.com/stashapp/stash/pkg/sqlite"
|
||||
@@ -283,11 +282,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
folderIDs []file.FolderID
|
||||
fileIDs []file.ID
|
||||
sceneFileIDs []file.ID
|
||||
imageFileIDs []file.ID
|
||||
galleryFileIDs []file.ID
|
||||
folderIDs []models.FolderID
|
||||
fileIDs []models.FileID
|
||||
sceneFileIDs []models.FileID
|
||||
imageFileIDs []models.FileID
|
||||
galleryFileIDs []models.FileID
|
||||
chapterIDs []int
|
||||
|
||||
sceneIDs []int
|
||||
@@ -700,8 +699,8 @@ func getFolderModTime(index int) time.Time {
|
||||
return time.Date(2000, 1, (index%10)+1, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
func makeFolder(i int) file.Folder {
|
||||
var folderID *file.FolderID
|
||||
func makeFolder(i int) models.Folder {
|
||||
var folderID *models.FolderID
|
||||
var folderIdx *int
|
||||
if pidx, ok := folderParentFolders[i]; ok {
|
||||
folderIdx = &pidx
|
||||
@@ -709,9 +708,9 @@ func makeFolder(i int) file.Folder {
|
||||
folderID = &v
|
||||
}
|
||||
|
||||
return file.Folder{
|
||||
return models.Folder{
|
||||
ParentFolderID: folderID,
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
// zip files have to be added after creating files
|
||||
ModTime: getFolderModTime(i),
|
||||
},
|
||||
@@ -748,8 +747,8 @@ func getFileModTime(index int) time.Time {
|
||||
return getFolderModTime(index)
|
||||
}
|
||||
|
||||
func getFileFingerprints(index int) []file.Fingerprint {
|
||||
return []file.Fingerprint{
|
||||
func getFileFingerprints(index int) []models.Fingerprint {
|
||||
return []models.Fingerprint{
|
||||
{
|
||||
Type: "MD5",
|
||||
Fingerprint: getPrefixedStringValue("file", index, "md5"),
|
||||
@@ -772,22 +771,22 @@ func getFileDuration(index int) float64 {
|
||||
return float64(duration) + 0.432
|
||||
}
|
||||
|
||||
func makeFile(i int) file.File {
|
||||
func makeFile(i int) models.File {
|
||||
folderID := folderIDs[fileFolders[i]]
|
||||
if folderID == 0 {
|
||||
folderID = folderIDs[folderIdxWithFiles]
|
||||
}
|
||||
|
||||
var zipFileID *file.ID
|
||||
var zipFileID *models.FileID
|
||||
if zipFileIndex, found := fileZipFiles[i]; found {
|
||||
zipFileID = &fileIDs[zipFileIndex]
|
||||
}
|
||||
|
||||
var ret file.File
|
||||
baseFile := &file.BaseFile{
|
||||
var ret models.File
|
||||
baseFile := &models.BaseFile{
|
||||
Basename: getFileBaseName(i),
|
||||
ParentFolderID: folderID,
|
||||
DirEntry: file.DirEntry{
|
||||
DirEntry: models.DirEntry{
|
||||
// zip files have to be added after creating files
|
||||
ModTime: getFileModTime(i),
|
||||
ZipFileID: zipFileID,
|
||||
@@ -799,7 +798,7 @@ func makeFile(i int) file.File {
|
||||
ret = baseFile
|
||||
|
||||
if i >= fileIdxStartVideoFiles && i < fileIdxStartImageFiles {
|
||||
ret = &file.VideoFile{
|
||||
ret = &models.VideoFile{
|
||||
BaseFile: baseFile,
|
||||
Format: getFileStringValue(i, "format"),
|
||||
Width: getWidth(i),
|
||||
@@ -811,7 +810,7 @@ func makeFile(i int) file.File {
|
||||
BitRate: int64(getFileDuration(i)) * 3,
|
||||
}
|
||||
} else if i >= fileIdxStartImageFiles && i < fileIdxStartGalleryFiles {
|
||||
ret = &file.ImageFile{
|
||||
ret = &models.ImageFile{
|
||||
BaseFile: baseFile,
|
||||
Format: getFileStringValue(i, "format"),
|
||||
Width: getWidth(i),
|
||||
@@ -977,27 +976,27 @@ func getSceneBasename(index int) string {
|
||||
return getSceneStringValue(index, pathField)
|
||||
}
|
||||
|
||||
func makeSceneFile(i int) *file.VideoFile {
|
||||
fp := []file.Fingerprint{
|
||||
func makeSceneFile(i int) *models.VideoFile {
|
||||
fp := []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getSceneStringValue(i, checksumField),
|
||||
},
|
||||
{
|
||||
Type: file.FingerprintTypeOshash,
|
||||
Type: models.FingerprintTypeOshash,
|
||||
Fingerprint: getSceneStringValue(i, "oshash"),
|
||||
},
|
||||
}
|
||||
|
||||
if i != sceneIdxMissingPhash {
|
||||
fp = append(fp, file.Fingerprint{
|
||||
Type: file.FingerprintTypePhash,
|
||||
fp = append(fp, models.Fingerprint{
|
||||
Type: models.FingerprintTypePhash,
|
||||
Fingerprint: getScenePhash(i, "phash"),
|
||||
})
|
||||
}
|
||||
|
||||
return &file.VideoFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
return &models.VideoFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
Path: getFilePath(folderIdxWithSceneFiles, getSceneBasename(i)),
|
||||
Basename: getSceneBasename(i),
|
||||
ParentFolderID: folderIDs[folderIdxWithSceneFiles],
|
||||
@@ -1100,7 +1099,7 @@ func createScenes(ctx context.Context, n int) error {
|
||||
|
||||
scene := makeScene(i)
|
||||
|
||||
if err := sqb.Create(ctx, scene, []file.ID{f.ID}); err != nil {
|
||||
if err := sqb.Create(ctx, scene, []models.FileID{f.ID}); err != nil {
|
||||
return fmt.Errorf("Error creating scene %v+: %s", scene, err.Error())
|
||||
}
|
||||
|
||||
@@ -1118,15 +1117,15 @@ func getImageBasename(index int) string {
|
||||
return getImageStringValue(index, pathField)
|
||||
}
|
||||
|
||||
func makeImageFile(i int) *file.ImageFile {
|
||||
return &file.ImageFile{
|
||||
BaseFile: &file.BaseFile{
|
||||
func makeImageFile(i int) *models.ImageFile {
|
||||
return &models.ImageFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
Path: getFilePath(folderIdxWithImageFiles, getImageBasename(i)),
|
||||
Basename: getImageBasename(i),
|
||||
ParentFolderID: folderIDs[folderIdxWithImageFiles],
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getImageStringValue(i, checksumField),
|
||||
},
|
||||
},
|
||||
@@ -1180,7 +1179,7 @@ func createImages(ctx context.Context, n int) error {
|
||||
|
||||
err := qb.Create(ctx, &models.ImageCreateInput{
|
||||
Image: image,
|
||||
FileIDs: []file.ID{f.ID},
|
||||
FileIDs: []models.FileID{f.ID},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -1209,14 +1208,14 @@ func getGalleryBasename(index int) string {
|
||||
return getGalleryStringValue(index, pathField)
|
||||
}
|
||||
|
||||
func makeGalleryFile(i int) *file.BaseFile {
|
||||
return &file.BaseFile{
|
||||
func makeGalleryFile(i int) *models.BaseFile {
|
||||
return &models.BaseFile{
|
||||
Path: getFilePath(folderIdxWithGalleryFiles, getGalleryBasename(i)),
|
||||
Basename: getGalleryBasename(i),
|
||||
ParentFolderID: folderIDs[folderIdxWithGalleryFiles],
|
||||
Fingerprints: []file.Fingerprint{
|
||||
Fingerprints: []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: getGalleryStringValue(i, checksumField),
|
||||
},
|
||||
},
|
||||
@@ -1255,14 +1254,14 @@ func createGalleries(ctx context.Context, n int) error {
|
||||
fqb := db.File
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
if i != galleryIdxWithoutFile {
|
||||
f := makeGalleryFile(i)
|
||||
if err := fqb.Create(ctx, f); err != nil {
|
||||
return fmt.Errorf("creating gallery file: %w", err)
|
||||
}
|
||||
galleryFileIDs = append(galleryFileIDs, f.ID)
|
||||
fileIDs = []file.ID{f.ID}
|
||||
fileIDs = []models.FileID{f.ID}
|
||||
} else {
|
||||
galleryFileIDs = append(galleryFileIDs, 0)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil"
|
||||
@@ -707,12 +706,12 @@ type relatedFilesTable struct {
|
||||
}
|
||||
|
||||
// type scenesFilesRow struct {
|
||||
// SceneID int `db:"scene_id"`
|
||||
// Primary bool `db:"primary"`
|
||||
// FileID file.ID `db:"file_id"`
|
||||
// SceneID int `db:"scene_id"`
|
||||
// Primary bool `db:"primary"`
|
||||
// FileID models.FileID `db:"file_id"`
|
||||
// }
|
||||
|
||||
func (t *relatedFilesTable) insertJoin(ctx context.Context, id int, primary bool, fileID file.ID) error {
|
||||
func (t *relatedFilesTable) insertJoin(ctx context.Context, id int, primary bool, fileID models.FileID) error {
|
||||
q := dialect.Insert(t.table.table).Cols(t.idColumn.GetCol(), "primary", "file_id").Vals(
|
||||
goqu.Vals{id, primary, fileID},
|
||||
)
|
||||
@@ -724,7 +723,7 @@ func (t *relatedFilesTable) insertJoin(ctx context.Context, id int, primary bool
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *relatedFilesTable) insertJoins(ctx context.Context, id int, firstPrimary bool, fileIDs []file.ID) error {
|
||||
func (t *relatedFilesTable) insertJoins(ctx context.Context, id int, firstPrimary bool, fileIDs []models.FileID) error {
|
||||
for i, fk := range fileIDs {
|
||||
if err := t.insertJoin(ctx, id, firstPrimary && i == 0, fk); err != nil {
|
||||
return err
|
||||
@@ -734,7 +733,7 @@ func (t *relatedFilesTable) insertJoins(ctx context.Context, id int, firstPrimar
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *relatedFilesTable) replaceJoins(ctx context.Context, id int, fileIDs []file.ID) error {
|
||||
func (t *relatedFilesTable) replaceJoins(ctx context.Context, id int, fileIDs []models.FileID) error {
|
||||
if err := t.destroy(ctx, []int{id}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -744,7 +743,7 @@ func (t *relatedFilesTable) replaceJoins(ctx context.Context, id int, fileIDs []
|
||||
}
|
||||
|
||||
// destroyJoins destroys all entries in the table with the provided fileIDs
|
||||
func (t *relatedFilesTable) destroyJoins(ctx context.Context, fileIDs []file.ID) error {
|
||||
func (t *relatedFilesTable) destroyJoins(ctx context.Context, fileIDs []models.FileID) error {
|
||||
q := dialect.Delete(t.table.table).Where(t.table.table.Col("file_id").In(fileIDs))
|
||||
|
||||
if _, err := exec(ctx, q); err != nil {
|
||||
@@ -754,7 +753,7 @@ func (t *relatedFilesTable) destroyJoins(ctx context.Context, fileIDs []file.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *relatedFilesTable) setPrimary(ctx context.Context, id int, fileID file.ID) error {
|
||||
func (t *relatedFilesTable) setPrimary(ctx context.Context, id int, fileID models.FileID) error {
|
||||
table := t.table.table
|
||||
|
||||
q := dialect.Update(table).Prepared(true).Set(goqu.Record{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
|
||||
"gopkg.in/guregu/null.v4"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
// null package does not provide methods to convert null.Int to int pointer
|
||||
@@ -33,27 +33,27 @@ func nullFloatPtr(i null.Float) *float64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func nullIntFolderIDPtr(i null.Int) *file.FolderID {
|
||||
func nullIntFolderIDPtr(i null.Int) *models.FolderID {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := file.FolderID(i.Int64)
|
||||
v := models.FolderID(i.Int64)
|
||||
|
||||
return &v
|
||||
}
|
||||
|
||||
func nullIntFileIDPtr(i null.Int) *file.ID {
|
||||
func nullIntFileIDPtr(i null.Int) *models.FileID {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := file.ID(i.Int64)
|
||||
v := models.FileID(i.Int64)
|
||||
|
||||
return &v
|
||||
}
|
||||
|
||||
func nullIntFromFileIDPtr(i *file.ID) null.Int {
|
||||
func nullIntFromFileIDPtr(i *models.FileID) null.Int {
|
||||
if i == nil {
|
||||
return null.NewInt(0, false)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func nullIntFromFileIDPtr(i *file.ID) null.Int {
|
||||
return null.IntFrom(int64(*i))
|
||||
}
|
||||
|
||||
func nullIntFromFolderIDPtr(i *file.FolderID) null.Int {
|
||||
func nullIntFromFolderIDPtr(i *models.FolderID) null.Int {
|
||||
if i == nil {
|
||||
return null.NewInt(0, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user