mirror of
https://github.com/stashapp/stash.git
synced 2026-05-09 05:05:29 +02:00
* Bump go version in go.mod * Update compiler image. Changed github download url since existing one didn't have version 12 of the SDK. * Update macOS requirements in README for v0.32.0 * Update lint action * Bump golangci-lint version * Migrate golangci-lint config * Fix QF1012 errors (Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...))) * Fix QF1003 errors (could use tagged switch) * Fix ST1005 errors (error string capitalisation) * Fix ST1011 errors (seconds suffix) * Fix QF1006 errors (lift into loop condition) * Fix QF1002 errors (switch condition) * Fix gocritic error (deprecated paragraph) * Fix incorrect nolint directive * Ignore specific checks noctx should be addressed in a later PR --------- Co-authored-by: DogmaDragon <103123951+DogmaDragon@users.noreply.github.com> Co-authored-by: feederbox826 <me@feederbox.cc>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
)
|
|
|
|
type SceneMissingHashCounter interface {
|
|
CountMissingChecksum(ctx context.Context) (int, error)
|
|
CountMissingOSHash(ctx context.Context) (int, error)
|
|
}
|
|
|
|
// ValidateVideoFileNamingAlgorithm validates changing the
|
|
// VideoFileNamingAlgorithm configuration flag.
|
|
//
|
|
// If setting VideoFileNamingAlgorithm to MD5, then this function will ensure
|
|
// that all checksum values are set on all scenes.
|
|
//
|
|
// Likewise, if VideoFileNamingAlgorithm is set to oshash, then this function
|
|
// will ensure that all oshash values are set on all scenes.
|
|
func ValidateVideoFileNamingAlgorithm(ctx context.Context, qb SceneMissingHashCounter, newValue models.HashAlgorithm) error {
|
|
// if algorithm is being set to MD5, then all checksums must be present
|
|
switch newValue {
|
|
case models.HashAlgorithmMd5:
|
|
missingMD5, err := qb.CountMissingChecksum(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if missingMD5 > 0 {
|
|
return errors.New("some checksums are missing on scenes. Run Scan with calculateMD5 set to true")
|
|
}
|
|
case models.HashAlgorithmOshash:
|
|
missingOSHash, err := qb.CountMissingOSHash(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if missingOSHash > 0 {
|
|
return errors.New("some oshash values are missing on scenes. Run Scan to populate")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|