mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Images section (#813)
* Add new configuration options * Refactor scan/clean * Schema changes * Add details to galleries * Remove redundant code * Refine thumbnail generation * Gallery overhaul * Don't allow modifying zip gallery images * Show gallery card overlays * Hide zoom slider when not in grid mode
This commit is contained in:
101
pkg/manager/image.go
Normal file
101
pkg/manager/image.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
// DestroyImage deletes an image and its associated relationships from the
|
||||
// database.
|
||||
func DestroyImage(imageID int, tx *sqlx.Tx) error {
|
||||
qb := models.NewImageQueryBuilder()
|
||||
jqb := models.NewJoinsQueryBuilder()
|
||||
|
||||
_, err := qb.Find(imageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := jqb.DestroyImagesTags(imageID, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := jqb.DestroyPerformersImages(imageID, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := jqb.DestroyImageGalleries(imageID, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := qb.Destroy(imageID, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteGeneratedImageFiles deletes generated files for the provided image.
|
||||
func DeleteGeneratedImageFiles(image *models.Image) {
|
||||
thumbPath := GetInstance().Paths.Generated.GetThumbnailPath(image.Checksum, models.DefaultGthumbWidth)
|
||||
exists, _ := utils.FileExists(thumbPath)
|
||||
if exists {
|
||||
err := os.Remove(thumbPath)
|
||||
if err != nil {
|
||||
logger.Warnf("Could not delete file %s: %s", thumbPath, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteImageFile deletes the image file from the filesystem.
|
||||
func DeleteImageFile(image *models.Image) {
|
||||
err := os.Remove(image.Path)
|
||||
if err != nil {
|
||||
logger.Warnf("Could not delete file %s: %s", image.Path, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func walkGalleryZip(path string, walkFunc func(file *zip.File) error) error {
|
||||
readCloser, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range readCloser.File {
|
||||
if file.FileInfo().IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(file.Name, "__MACOSX") {
|
||||
continue
|
||||
}
|
||||
|
||||
if !isImage(file.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
err := walkFunc(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func countImagesInZip(path string) int {
|
||||
ret := 0
|
||||
walkGalleryZip(path, func(file *zip.File) error {
|
||||
ret++
|
||||
return nil
|
||||
})
|
||||
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user