mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +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:
@@ -32,7 +32,6 @@ import (
|
||||
|
||||
type SceneReader interface {
|
||||
Find(ctx context.Context, id int) (*models.Scene, error)
|
||||
GetStashIDs(ctx context.Context, sceneID int) ([]*models.StashID, error)
|
||||
}
|
||||
|
||||
type PerformerReader interface {
|
||||
@@ -142,22 +141,25 @@ func (c Client) FindStashBoxScenesByFingerprints(ctx context.Context, ids []int)
|
||||
|
||||
var sceneFPs []*graphql.FingerprintQueryInput
|
||||
|
||||
if scene.Checksum.Valid {
|
||||
checksum := scene.Checksum()
|
||||
if checksum != "" {
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
Hash: scene.Checksum.String,
|
||||
Hash: checksum,
|
||||
Algorithm: graphql.FingerprintAlgorithmMd5,
|
||||
})
|
||||
}
|
||||
|
||||
if scene.OSHash.Valid {
|
||||
oshash := scene.OSHash()
|
||||
if oshash != "" {
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
Hash: scene.OSHash.String,
|
||||
Hash: oshash,
|
||||
Algorithm: graphql.FingerprintAlgorithmOshash,
|
||||
})
|
||||
}
|
||||
|
||||
if scene.Phash.Valid {
|
||||
phashStr := utils.PhashToString(scene.Phash.Int64)
|
||||
phash := scene.Phash()
|
||||
if phash != 0 {
|
||||
phashStr := utils.PhashToString(phash)
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
Hash: phashStr,
|
||||
Algorithm: graphql.FingerprintAlgorithmPhash,
|
||||
@@ -225,11 +227,7 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
continue
|
||||
}
|
||||
|
||||
stashIDs, err := qb.GetStashIDs(ctx, sceneID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stashIDs := scene.StashIDs
|
||||
sceneStashID := ""
|
||||
for _, stashID := range stashIDs {
|
||||
if stashID.Endpoint == endpoint {
|
||||
@@ -238,11 +236,12 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
}
|
||||
|
||||
if sceneStashID != "" {
|
||||
if scene.Checksum.Valid && scene.Duration.Valid {
|
||||
duration := scene.Duration()
|
||||
if checksum := scene.Checksum(); checksum != "" && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: scene.Checksum.String,
|
||||
Hash: checksum,
|
||||
Algorithm: graphql.FingerprintAlgorithmMd5,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, graphql.FingerprintSubmission{
|
||||
SceneID: sceneStashID,
|
||||
@@ -250,11 +249,11 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
})
|
||||
}
|
||||
|
||||
if scene.OSHash.Valid && scene.Duration.Valid {
|
||||
if oshash := scene.OSHash(); oshash != "" && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: scene.OSHash.String,
|
||||
Hash: oshash,
|
||||
Algorithm: graphql.FingerprintAlgorithmOshash,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, graphql.FingerprintSubmission{
|
||||
SceneID: sceneStashID,
|
||||
@@ -262,11 +261,11 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
})
|
||||
}
|
||||
|
||||
if scene.Phash.Valid && scene.Duration.Valid {
|
||||
if phash := scene.Phash(); phash != 0 && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: utils.PhashToString(scene.Phash.Int64),
|
||||
Hash: utils.PhashToString(phash),
|
||||
Algorithm: graphql.FingerprintAlgorithmPhash,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, graphql.FingerprintSubmission{
|
||||
SceneID: sceneStashID,
|
||||
@@ -751,22 +750,23 @@ func (c Client) SubmitSceneDraft(ctx context.Context, sceneID int, endpoint stri
|
||||
return err
|
||||
}
|
||||
|
||||
if scene.Title.Valid {
|
||||
draft.Title = &scene.Title.String
|
||||
if scene.Title != "" {
|
||||
draft.Title = &scene.Title
|
||||
}
|
||||
if scene.Details.Valid {
|
||||
draft.Details = &scene.Details.String
|
||||
if scene.Details != "" {
|
||||
draft.Details = &scene.Details
|
||||
}
|
||||
if len(strings.TrimSpace(scene.URL.String)) > 0 {
|
||||
url := strings.TrimSpace(scene.URL.String)
|
||||
if scene.URL != "" && len(strings.TrimSpace(scene.URL)) > 0 {
|
||||
url := strings.TrimSpace(scene.URL)
|
||||
draft.URL = &url
|
||||
}
|
||||
if scene.Date.Valid {
|
||||
draft.Date = &scene.Date.String
|
||||
if scene.Date != nil {
|
||||
v := scene.Date.String()
|
||||
draft.Date = &v
|
||||
}
|
||||
|
||||
if scene.StudioID.Valid {
|
||||
studio, err := sqb.Find(ctx, int(scene.StudioID.Int64))
|
||||
if scene.StudioID != nil {
|
||||
studio, err := sqb.Find(ctx, int(*scene.StudioID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -788,29 +788,30 @@ func (c Client) SubmitSceneDraft(ctx context.Context, sceneID int, endpoint stri
|
||||
}
|
||||
|
||||
fingerprints := []*graphql.FingerprintInput{}
|
||||
if scene.OSHash.Valid && scene.Duration.Valid {
|
||||
duration := scene.Duration()
|
||||
if oshash := scene.OSHash(); oshash != "" && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: scene.OSHash.String,
|
||||
Hash: oshash,
|
||||
Algorithm: graphql.FingerprintAlgorithmOshash,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, &fingerprint)
|
||||
}
|
||||
|
||||
if scene.Checksum.Valid && scene.Duration.Valid {
|
||||
if checksum := scene.Checksum(); checksum != "" && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: scene.Checksum.String,
|
||||
Hash: checksum,
|
||||
Algorithm: graphql.FingerprintAlgorithmMd5,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, &fingerprint)
|
||||
}
|
||||
|
||||
if scene.Phash.Valid && scene.Duration.Valid {
|
||||
if phash := scene.Phash(); phash != 0 && duration != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: utils.PhashToString(scene.Phash.Int64),
|
||||
Hash: utils.PhashToString(phash),
|
||||
Algorithm: graphql.FingerprintAlgorithmPhash,
|
||||
Duration: int(scene.Duration.Float64),
|
||||
Duration: int(duration),
|
||||
}
|
||||
fingerprints = append(fingerprints, &fingerprint)
|
||||
}
|
||||
@@ -861,14 +862,12 @@ func (c Client) SubmitSceneDraft(ctx context.Context, sceneID int, endpoint stri
|
||||
}
|
||||
}
|
||||
|
||||
stashIDs, err := qb.GetStashIDs(ctx, sceneID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stashIDs := scene.StashIDs
|
||||
var stashID *string
|
||||
for _, v := range stashIDs {
|
||||
if v.Endpoint == endpoint {
|
||||
stashID = &v.StashID
|
||||
vv := v.StashID
|
||||
stashID = &vv
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user