stash/pkg/models/paths/paths_generated.go
WithoutPants f69bd8a94f
Restructure go project (#2356)
* Move main to cmd
* Move api to internal
* Move logger and manager to internal
* Move shell hiding code to separate package
* Decouple job from desktop and utils
* Decouple session from config
* Move static into internal
* Decouple config from dlna
* Move desktop to internal
* Move dlna to internal
* Decouple remaining packages from config
* Move config into internal
* Move jsonschema and paths to models
* Make ffmpeg functions private
* Move file utility methods into fsutil package
* Move symwalk into fsutil
* Move single-use util functions into client package
* Move slice functions to separate packages
* Add env var to suppress windowsgui arg
* Move hash functions into separate package
* Move identify to internal
* Move autotag to internal
* Touch UI when generating backend
2022-03-17 11:33:59 +11:00

74 lines
2 KiB
Go

package paths
import (
"fmt"
"os"
"path/filepath"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
)
const thumbDirDepth int = 2
const thumbDirLength int = 2 // thumbDirDepth * thumbDirLength must be smaller than the length of checksum
type generatedPaths struct {
Screenshots string
Thumbnails string
Vtt string
Markers string
Transcodes string
Downloads string
Tmp string
InteractiveHeatmap string
}
func newGeneratedPaths(path string) *generatedPaths {
gp := generatedPaths{}
gp.Screenshots = filepath.Join(path, "screenshots")
gp.Thumbnails = filepath.Join(path, "thumbnails")
gp.Vtt = filepath.Join(path, "vtt")
gp.Markers = filepath.Join(path, "markers")
gp.Transcodes = filepath.Join(path, "transcodes")
gp.Downloads = filepath.Join(path, "download_stage")
gp.Tmp = filepath.Join(path, "tmp")
gp.InteractiveHeatmap = filepath.Join(path, "interactive_heatmaps")
return &gp
}
func (gp *generatedPaths) GetTmpPath(fileName string) string {
return filepath.Join(gp.Tmp, fileName)
}
func (gp *generatedPaths) EnsureTmpDir() error {
return fsutil.EnsureDir(gp.Tmp)
}
func (gp *generatedPaths) EmptyTmpDir() error {
return fsutil.EmptyDir(gp.Tmp)
}
func (gp *generatedPaths) RemoveTmpDir() error {
return fsutil.RemoveDir(gp.Tmp)
}
func (gp *generatedPaths) TempDir(pattern string) (string, error) {
if err := gp.EnsureTmpDir(); err != nil {
logger.Warnf("Could not ensure existence of a temporary directory: %v", err)
}
ret, err := os.MkdirTemp(gp.Tmp, pattern)
if err != nil {
return "", err
}
if err = fsutil.EmptyDir(ret); err != nil {
logger.Warnf("could not recursively empty dir: %v", err)
}
return ret, nil
}
func (gp *generatedPaths) GetThumbnailPath(checksum string, width int) string {
fname := fmt.Sprintf("%s_%d.jpg", checksum, width)
return filepath.Join(gp.Thumbnails, fsutil.GetIntraDir(checksum, thumbDirDepth, thumbDirLength), fname)
}