mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
File storage rewrite (#2676)
* Restructure data layer part 2 (#2599) * Refactor and separate image model * Refactor image query builder * Handle relationships in image query builder * Remove relationship management methods * Refactor gallery model/query builder * Add scenes to gallery model * Convert scene model * Refactor scene models * Remove unused methods * Add unit tests for gallery * Add image tests * Add scene tests * Convert unnecessary scene value pointers to values * Convert unnecessary pointer values to values * Refactor scene partial * Add scene partial tests * Refactor ImagePartial * Add image partial tests * Refactor gallery partial update * Add partial gallery update tests * Use zero/null package for null values * Add files and scan system * Add sqlite implementation for files/folders * Add unit tests for files/folders * Image refactors * Update image data layer * Refactor gallery model and creation * Refactor scene model * Refactor scenes * Don't set title from filename * Allow galleries to freely add/remove images * Add multiple scene file support to graphql and UI * Add multiple file support for images in graphql/UI * Add multiple file for galleries in graphql/UI * Remove use of some deprecated fields * Remove scene path usage * Remove gallery path usage * Remove path from image * Move funscript to video file * Refactor caption detection * Migrate existing data * Add post commit/rollback hook system * Lint. Comment out import/export tests * Add WithDatabase read only wrapper * Prepend tasks to list * Add 32 pre-migration * Add warnings in release and migration notes
This commit is contained in:
@@ -1,21 +1,62 @@
|
||||
package models
|
||||
|
||||
import "database/sql"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type MoviesScenes struct {
|
||||
MovieID int `db:"movie_id" json:"movie_id"`
|
||||
SceneID int `db:"scene_id" json:"scene_id"`
|
||||
SceneIndex sql.NullInt64 `db:"scene_index" json:"scene_index"`
|
||||
MovieID int `json:"movie_id"`
|
||||
// SceneID int `json:"scene_id"`
|
||||
SceneIndex *int `json:"scene_index"`
|
||||
}
|
||||
|
||||
type StashID struct {
|
||||
StashID string `db:"stash_id" json:"stash_id"`
|
||||
Endpoint string `db:"endpoint" json:"endpoint"`
|
||||
}
|
||||
|
||||
func (s StashID) StashIDInput() StashIDInput {
|
||||
return StashIDInput{
|
||||
Endpoint: s.Endpoint,
|
||||
StashID: s.StashID,
|
||||
func (s MoviesScenes) SceneMovieInput() *SceneMovieInput {
|
||||
return &SceneMovieInput{
|
||||
MovieID: strconv.Itoa(s.MovieID),
|
||||
SceneIndex: s.SceneIndex,
|
||||
}
|
||||
}
|
||||
|
||||
func (s MoviesScenes) Equal(o MoviesScenes) bool {
|
||||
return o.MovieID == s.MovieID && ((o.SceneIndex == nil && s.SceneIndex == nil) ||
|
||||
(o.SceneIndex != nil && s.SceneIndex != nil && *o.SceneIndex == *s.SceneIndex))
|
||||
}
|
||||
|
||||
type UpdateMovieIDs struct {
|
||||
Movies []MoviesScenes `json:"movies"`
|
||||
Mode RelationshipUpdateMode `json:"mode"`
|
||||
}
|
||||
|
||||
func (u *UpdateMovieIDs) SceneMovieInputs() []*SceneMovieInput {
|
||||
if u == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ret := make([]*SceneMovieInput, len(u.Movies))
|
||||
for _, id := range u.Movies {
|
||||
ret = append(ret, id.SceneMovieInput())
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func UpdateMovieIDsFromInput(i []*SceneMovieInput) (*UpdateMovieIDs, error) {
|
||||
ret := &UpdateMovieIDs{
|
||||
Mode: RelationshipUpdateModeSet,
|
||||
}
|
||||
|
||||
for _, v := range i {
|
||||
mID, err := strconv.Atoi(v.MovieID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid movie ID: %s", v.MovieID)
|
||||
}
|
||||
|
||||
ret.Movies = append(ret.Movies, MoviesScenes{
|
||||
MovieID: mID,
|
||||
SceneIndex: v.SceneIndex,
|
||||
})
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user