Add a cache for gallery thumbnails (#496)

This commit is contained in:
bnkai
2020-05-11 10:20:08 +03:00
committed by GitHub
parent 8ba76783b0
commit bd45daacf3
36 changed files with 319 additions and 1200 deletions

View File

@@ -1,12 +1,18 @@
package paths
import (
"fmt"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/utils"
"path/filepath"
)
type galleryPaths struct{}
const thumbDir = "gthumbs"
const thumbDirDepth int = 2
const thumbDirLength int = 2 // thumbDirDepth * thumbDirLength must be smaller than the length of checksum
func newGalleryPaths() *galleryPaths {
return &galleryPaths{}
}
@@ -15,6 +21,19 @@ func (gp *galleryPaths) GetExtractedPath(checksum string) string {
return filepath.Join(config.GetCachePath(), checksum)
}
func GetGthumbCache() string {
return filepath.Join(config.GetCachePath(), thumbDir)
}
func GetGthumbDir(checksum string) string {
return filepath.Join(config.GetCachePath(), thumbDir, utils.GetIntraDir(checksum, thumbDirDepth, thumbDirLength), checksum)
}
func GetGthumbPath(checksum string, index int, width int) string {
fname := fmt.Sprintf("%s_%d_%d.jpg", checksum, index, width)
return filepath.Join(config.GetCachePath(), thumbDir, utils.GetIntraDir(checksum, thumbDirDepth, thumbDirLength), checksum, fname)
}
func (gp *galleryPaths) GetExtractedFilePath(checksum string, fileName string) string {
return filepath.Join(config.GetCachePath(), checksum, fileName)
}