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
This commit is contained in:
WithoutPants 2022-03-17 11:33:59 +11:00 committed by GitHub
parent dcee874f59
commit f69bd8a94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
334 changed files with 1845 additions and 1525 deletions

View File

@ -73,13 +73,8 @@ jobs:
# Static validation happens in the linter workflow in parallel to this workflow
# Run Dynamic validation here, to make sure we pass all the projects integration tests
#
# create UI file so that the embed doesn't fail
- name: Test Backend
run: |
mkdir -p ui/v2.5/build
touch ui/v2.5/build/index.html
docker exec -t build /bin/bash -c "make it"
run: docker exec -t build /bin/bash -c "make it"
- name: Build UI
# skip UI build for pull requests if UI is unchanged (UI was cached)

2
.gitignore vendored
View File

@ -55,6 +55,6 @@ node_modules
*.db
stash
/stash
dist
.DS_Store

View File

@ -50,14 +50,17 @@ ifndef OFFICIAL_BUILD
$(eval OFFICIAL_BUILD := false)
endif
build: pre-build
ifdef IS_WIN_OS
ifndef SUPPRESS_WINDOWSGUI
PLATFORM_SPECIFIC_LDFLAGS := -H windowsgui
endif
endif
build: pre-build
build:
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)')
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/pkg/manager/config.officialBuild=$(OFFICIAL_BUILD)')
go build $(OUTPUT) -mod=vendor -v -tags "sqlite_omit_load_extension osusergo netgo" $(GO_BUILD_FLAGS) -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS) $(PLATFORM_SPECIFIC_LDFLAGS)"
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/internal/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/internal/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash/internal/api.githash=$(GITHASH)')
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/internal/manager/config.officialBuild=$(OFFICIAL_BUILD)')
go build $(OUTPUT) -mod=vendor -v -tags "sqlite_omit_load_extension osusergo netgo" $(GO_BUILD_FLAGS) -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS) $(PLATFORM_SPECIFIC_LDFLAGS)" ./cmd/stash
# strips debug symbols from the release build
build-release: EXTRA_LDFLAGS := -s -w
@ -140,6 +143,12 @@ cross-compile-all:
make cross-compile-linux-arm32v7
make cross-compile-linux-arm32v6
# ensures a file is present in ui/v2.5/build since this is required
# for the embedded ui library
touch-ui:
@mkdir -p ui/v2.5/build
@touch ui/v2.5/build/index.html
# Regenerates GraphQL files
generate: generate-backend generate-frontend
@ -148,8 +157,8 @@ generate-frontend:
cd ui/v2.5 && yarn run gqlgen
.PHONY: generate-backend
generate-backend:
go generate -mod=vendor
generate-backend: touch-ui
go generate -mod=vendor ./cmd/stash
# Regenerates stash-box client files
.PHONY: generate-stash-box-client

View File

@ -2,7 +2,6 @@
package main
import (
"embed"
"fmt"
"os"
"os/signal"
@ -10,19 +9,13 @@ import (
"syscall"
"github.com/apenwarr/fixconsole"
"github.com/stashapp/stash/pkg/api"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/api"
"github.com/stashapp/stash/internal/manager"
_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
)
//go:embed ui/v2.5/build
var uiBox embed.FS
//go:embed ui/login
var loginUIBox embed.FS
func init() {
// On Windows, attach to parent shell
err := fixconsole.FixConsoleIfNeeded()
@ -33,7 +26,7 @@ func init() {
func main() {
manager.Initialize()
api.Start(uiBox, loginUIBox)
api.Start()
blockForever()

View File

@ -8,7 +8,7 @@ exec:
model:
filename: pkg/models/generated_models.go
resolver:
filename: pkg/api/resolver.go
filename: internal/api/resolver.go
type: Resolver
struct_tag: gqlgen

View File

@ -7,9 +7,9 @@ import (
"net/url"
"strings"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/session"
)

View File

@ -1,22 +1,22 @@
package utils
package api
import (
"strconv"
"strings"
)
type ByteRange struct {
type byteRange struct {
Start int64
End *int64
RawString string
}
func CreateByteRange(s string) ByteRange {
func createByteRange(s string) byteRange {
// strip bytes=
r := strings.TrimPrefix(s, "bytes=")
e := strings.Split(r, "-")
ret := ByteRange{
ret := byteRange{
RawString: s,
}
if len(e) > 0 {
@ -30,7 +30,7 @@ func CreateByteRange(s string) ByteRange {
return ret
}
func (r ByteRange) ToHeaderValue(fileLength int64) string {
func (r byteRange) toHeaderValue(fileLength int64) string {
if r.End == nil {
return ""
}
@ -38,7 +38,7 @@ func (r ByteRange) ToHeaderValue(fileLength int64) string {
return "bytes " + strconv.FormatInt(r.Start, 10) + "-" + strconv.FormatInt(end, 10) + "/" + strconv.FormatInt(fileLength, 10)
}
func (r ByteRange) Apply(bytes []byte) []byte {
func (r byteRange) apply(bytes []byte) []byte {
if r.End == nil {
return bytes[r.Start:]
}

48
internal/api/dir_list.go Normal file
View File

@ -0,0 +1,48 @@
package api
import (
"io/fs"
"os"
"path/filepath"
"golang.org/x/text/collate"
)
type dirLister []fs.DirEntry
func (s dirLister) Len() int {
return len(s)
}
func (s dirLister) Swap(i, j int) {
s[j], s[i] = s[i], s[j]
}
func (s dirLister) Bytes(i int) []byte {
return []byte(s[i].Name())
}
// listDir will return the contents of a given directory path as a string slice
func listDir(col *collate.Collator, path string) ([]string, error) {
var dirPaths []string
files, err := os.ReadDir(path)
if err != nil {
path = filepath.Dir(path)
files, err = os.ReadDir(path)
if err != nil {
return dirPaths, err
}
}
if col != nil {
col.Sort(dirLister(files))
}
for _, file := range files {
if !file.IsDir() {
continue
}
dirPaths = append(dirPaths, filepath.Join(path, file.Name()))
}
return dirPaths, nil
}

View File

@ -6,10 +6,10 @@ import (
"os"
"strings"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/internal/static"
"github.com/stashapp/stash/pkg/hash"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/static"
"github.com/stashapp/stash/pkg/utils"
)
type imageBox struct {
@ -102,7 +102,7 @@ func getRandomPerformerImageUsingName(name, gender, customPath string) ([]byte,
}
imageFiles := box.files
index := utils.IntFromString(name) % uint64(len(imageFiles))
index := hash.IntFromString(name) % uint64(len(imageFiles))
img, err := box.box.Open(imageFiles[index])
if err != nil {
return nil, err

View File

@ -6,8 +6,8 @@ import (
"sort"
"strconv"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/scraper"

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/gallery"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models"

View File

@ -4,8 +4,8 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/gallery"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models"

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/gallery"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models"

View File

@ -6,11 +6,11 @@ import (
"fmt"
"path/filepath"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
var ErrOverriddenConfig = errors.New("cannot set overridden value")
@ -40,7 +40,7 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
}
}
if isNew {
exists, err := utils.DirExists(s.Path)
exists, err := fsutil.DirExists(s.Path)
if !exists {
return makeConfigGeneralResult(), err
}
@ -63,7 +63,7 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
}
if !optional || value != "" {
if err := utils.EnsureDir(value); err != nil {
if err := fsutil.EnsureDir(value); err != nil {
return err
}
}
@ -211,6 +211,7 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
if input.LogLevel != nil && *input.LogLevel != c.GetLogLevel() {
c.Set(config.LogLevel, input.LogLevel)
logger := manager.GetInstance().Logger
logger.SetLogLevel(*input.LogLevel)
}

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -9,11 +9,14 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/intslice"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils"
)
@ -35,7 +38,7 @@ func (r *mutationResolver) GalleryCreate(ctx context.Context, input models.Galle
}
// for manually created galleries, generate checksum from title
checksum := utils.MD5FromString(input.Title)
checksum := md5.FromString(input.Title)
// Populate a new performer from the input
currentTime := time.Now()
@ -110,7 +113,7 @@ func (r *mutationResolver) GalleryCreate(ctx context.Context, input models.Galle
}
func (r *mutationResolver) updateGalleryPerformers(qb models.GalleryReaderWriter, galleryID int, performerIDs []string) error {
ids, err := utils.StringSliceToIntSlice(performerIDs)
ids, err := stringslice.StringSliceToIntSlice(performerIDs)
if err != nil {
return err
}
@ -118,7 +121,7 @@ func (r *mutationResolver) updateGalleryPerformers(qb models.GalleryReaderWriter
}
func (r *mutationResolver) updateGalleryTags(qb models.GalleryReaderWriter, galleryID int, tagIDs []string) error {
ids, err := utils.StringSliceToIntSlice(tagIDs)
ids, err := stringslice.StringSliceToIntSlice(tagIDs)
if err != nil {
return err
}
@ -126,7 +129,7 @@ func (r *mutationResolver) updateGalleryTags(qb models.GalleryReaderWriter, gall
}
func (r *mutationResolver) updateGalleryScenes(qb models.GalleryReaderWriter, galleryID int, sceneIDs []string) error {
ids, err := utils.StringSliceToIntSlice(sceneIDs)
ids, err := stringslice.StringSliceToIntSlice(sceneIDs)
if err != nil {
return err
}
@ -225,7 +228,7 @@ func (r *mutationResolver) galleryUpdate(input models.GalleryUpdateInput, transl
// if gallery is not zip-based, then generate the checksum from the title
if !originalGallery.Path.Valid {
checksum := utils.MD5FromString(*input.Title)
checksum := md5.FromString(*input.Title)
updatedGallery.Checksum = &checksum
}
@ -392,7 +395,7 @@ func adjustGallerySceneIDs(qb models.GalleryReader, galleryID int, ids models.Bu
}
func (r *mutationResolver) GalleryDestroy(ctx context.Context, input models.GalleryDestroyInput) (bool, error) {
galleryIDs, err := utils.StringSliceToIntSlice(input.Ids)
galleryIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return false, err
}
@ -529,7 +532,7 @@ func (r *mutationResolver) AddGalleryImages(ctx context.Context, input models.Ga
return false, err
}
imageIDs, err := utils.StringSliceToIntSlice(input.ImageIds)
imageIDs, err := stringslice.StringSliceToIntSlice(input.ImageIds)
if err != nil {
return false, err
}
@ -554,7 +557,7 @@ func (r *mutationResolver) AddGalleryImages(ctx context.Context, input models.Ga
return err
}
newIDs = utils.IntAppendUniques(newIDs, imageIDs)
newIDs = intslice.IntAppendUniques(newIDs, imageIDs)
return qb.UpdateImages(galleryID, newIDs)
}); err != nil {
return false, err
@ -569,7 +572,7 @@ func (r *mutationResolver) RemoveGalleryImages(ctx context.Context, input models
return false, err
}
imageIDs, err := utils.StringSliceToIntSlice(input.ImageIds)
imageIDs, err := stringslice.StringSliceToIntSlice(input.ImageIds)
if err != nil {
return false, err
}
@ -594,7 +597,7 @@ func (r *mutationResolver) RemoveGalleryImages(ctx context.Context, input models
return err
}
newIDs = utils.IntExclude(newIDs, imageIDs)
newIDs = intslice.IntExclude(newIDs, imageIDs)
return qb.UpdateImages(galleryID, newIDs)
}); err != nil {
return false, err

View File

@ -6,11 +6,12 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils"
)
@ -133,7 +134,7 @@ func (r *mutationResolver) imageUpdate(input models.ImageUpdateInput, translator
}
func (r *mutationResolver) updateImageGalleries(qb models.ImageReaderWriter, imageID int, galleryIDs []string) error {
ids, err := utils.StringSliceToIntSlice(galleryIDs)
ids, err := stringslice.StringSliceToIntSlice(galleryIDs)
if err != nil {
return err
}
@ -141,7 +142,7 @@ func (r *mutationResolver) updateImageGalleries(qb models.ImageReaderWriter, ima
}
func (r *mutationResolver) updateImagePerformers(qb models.ImageReaderWriter, imageID int, performerIDs []string) error {
ids, err := utils.StringSliceToIntSlice(performerIDs)
ids, err := stringslice.StringSliceToIntSlice(performerIDs)
if err != nil {
return err
}
@ -149,7 +150,7 @@ func (r *mutationResolver) updateImagePerformers(qb models.ImageReaderWriter, im
}
func (r *mutationResolver) updateImageTags(qb models.ImageReaderWriter, imageID int, tagsIDs []string) error {
ids, err := utils.StringSliceToIntSlice(tagsIDs)
ids, err := stringslice.StringSliceToIntSlice(tagsIDs)
if err != nil {
return err
}
@ -157,7 +158,7 @@ func (r *mutationResolver) updateImageTags(qb models.ImageReaderWriter, imageID
}
func (r *mutationResolver) BulkImageUpdate(ctx context.Context, input models.BulkImageUpdateInput) (ret []*models.Image, err error) {
imageIDs, err := utils.StringSliceToIntSlice(input.Ids)
imageIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return nil, err
}
@ -320,7 +321,7 @@ func (r *mutationResolver) ImageDestroy(ctx context.Context, input models.ImageD
}
func (r *mutationResolver) ImagesDestroy(ctx context.Context, input models.ImagesDestroyInput) (ret bool, err error) {
imageIDs, err := utils.StringSliceToIntSlice(input.Ids)
imageIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return false, err
}

View File

@ -4,7 +4,7 @@ import (
"context"
"strconv"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
)
func (r *mutationResolver) StopJob(ctx context.Context, jobID string) (bool, error) {

View File

@ -9,12 +9,12 @@ import (
"sync"
"time"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
func (r *mutationResolver) MetadataScan(ctx context.Context, input models.ScanMetadataInput) (string, error) {
@ -113,7 +113,7 @@ func (r *mutationResolver) BackupDatabase(ctx context.Context, input models.Back
mgr := manager.GetInstance()
var backupPath string
if download {
if err := utils.EnsureDir(mgr.Paths.Generated.Downloads); err != nil {
if err := fsutil.EnsureDir(mgr.Paths.Generated.Downloads); err != nil {
return nil, fmt.Errorf("could not create backup directory %v: %w", mgr.Paths.Generated.Downloads, err)
}
f, err := os.CreateTemp(mgr.Paths.Generated.Downloads, "backup*.sqlite")
@ -133,7 +133,10 @@ func (r *mutationResolver) BackupDatabase(ctx context.Context, input models.Back
}
if download {
downloadHash := mgr.DownloadStore.RegisterFile(backupPath, "", false)
downloadHash, err := mgr.DownloadStore.RegisterFile(backupPath, "", false)
if err != nil {
return nil, fmt.Errorf("error registering file for download: %w", err)
}
logger.Debugf("Generated backup file %s with hash %s", backupPath, downloadHash)
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)

View File

@ -7,8 +7,10 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils"
)
@ -25,7 +27,7 @@ func (r *mutationResolver) getMovie(ctx context.Context, id int) (ret *models.Mo
func (r *mutationResolver) MovieCreate(ctx context.Context, input models.MovieCreateInput) (*models.Movie, error) {
// generate checksum from movie name rather than image
checksum := utils.MD5FromString(input.Name)
checksum := md5.FromString(input.Name)
var frontimageData []byte
var backimageData []byte
@ -156,7 +158,7 @@ func (r *mutationResolver) MovieUpdate(ctx context.Context, input models.MovieUp
if input.Name != nil {
// generate checksum from movie name rather than image
checksum := utils.MD5FromString(*input.Name)
checksum := md5.FromString(*input.Name)
updatedMovie.Name = &sql.NullString{String: *input.Name, Valid: true}
updatedMovie.Checksum = &checksum
}
@ -222,7 +224,7 @@ func (r *mutationResolver) MovieUpdate(ctx context.Context, input models.MovieUp
}
func (r *mutationResolver) BulkMovieUpdate(ctx context.Context, input models.BulkMovieUpdateInput) ([]*models.Movie, error) {
movieIDs, err := utils.StringSliceToIntSlice(input.Ids)
movieIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return nil, err
}
@ -304,7 +306,7 @@ func (r *mutationResolver) MovieDestroy(ctx context.Context, input models.MovieD
}
func (r *mutationResolver) MoviesDestroy(ctx context.Context, movieIDs []string) (bool, error) {
ids, err := utils.StringSliceToIntSlice(movieIDs)
ids, err := stringslice.StringSliceToIntSlice(movieIDs)
if err != nil {
return false, err
}

View File

@ -7,9 +7,11 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/performer"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils"
)
@ -26,7 +28,7 @@ func (r *mutationResolver) getPerformer(ctx context.Context, id int) (ret *model
func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.PerformerCreateInput) (*models.Performer, error) {
// generate checksum from performer name rather than image
checksum := utils.MD5FromString(input.Name)
checksum := md5.FromString(input.Name)
var imageData []byte
var err error
@ -186,7 +188,7 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input models.Per
if input.Name != nil {
// generate checksum from performer name rather than image
checksum := utils.MD5FromString(*input.Name)
checksum := md5.FromString(*input.Name)
updatedPerformer.Name = &sql.NullString{String: *input.Name, Valid: true}
updatedPerformer.Checksum = &checksum
@ -285,7 +287,7 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input models.Per
}
func (r *mutationResolver) updatePerformerTags(qb models.PerformerReaderWriter, performerID int, tagsIDs []string) error {
ids, err := utils.StringSliceToIntSlice(tagsIDs)
ids, err := stringslice.StringSliceToIntSlice(tagsIDs)
if err != nil {
return err
}
@ -293,7 +295,7 @@ func (r *mutationResolver) updatePerformerTags(qb models.PerformerReaderWriter,
}
func (r *mutationResolver) BulkPerformerUpdate(ctx context.Context, input models.BulkPerformerUpdateInput) ([]*models.Performer, error) {
performerIDs, err := utils.StringSliceToIntSlice(input.Ids)
performerIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return nil, err
}
@ -420,7 +422,7 @@ func (r *mutationResolver) PerformerDestroy(ctx context.Context, input models.Pe
}
func (r *mutationResolver) PerformersDestroy(ctx context.Context, performerIDs []string) (bool, error) {
ids, err := utils.StringSliceToIntSlice(performerIDs)
ids, err := stringslice.StringSliceToIntSlice(performerIDs)
if err != nil {
return false, err
}

View File

@ -3,8 +3,8 @@ package api
import (
"context"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -7,12 +7,14 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils"
)
@ -181,7 +183,7 @@ func (r *mutationResolver) sceneUpdate(ctx context.Context, input models.SceneUp
}
func (r *mutationResolver) updateScenePerformers(qb models.SceneReaderWriter, sceneID int, performerIDs []string) error {
ids, err := utils.StringSliceToIntSlice(performerIDs)
ids, err := stringslice.StringSliceToIntSlice(performerIDs)
if err != nil {
return err
}
@ -215,7 +217,7 @@ func (r *mutationResolver) updateSceneMovies(qb models.SceneReaderWriter, sceneI
}
func (r *mutationResolver) updateSceneTags(qb models.SceneReaderWriter, sceneID int, tagsIDs []string) error {
ids, err := utils.StringSliceToIntSlice(tagsIDs)
ids, err := stringslice.StringSliceToIntSlice(tagsIDs)
if err != nil {
return err
}
@ -223,7 +225,7 @@ func (r *mutationResolver) updateSceneTags(qb models.SceneReaderWriter, sceneID
}
func (r *mutationResolver) updateSceneGalleries(qb models.SceneReaderWriter, sceneID int, galleryIDs []string) error {
ids, err := utils.StringSliceToIntSlice(galleryIDs)
ids, err := stringslice.StringSliceToIntSlice(galleryIDs)
if err != nil {
return err
}
@ -231,7 +233,7 @@ func (r *mutationResolver) updateSceneGalleries(qb models.SceneReaderWriter, sce
}
func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input models.BulkSceneUpdateInput) ([]*models.Scene, error) {
sceneIDs, err := utils.StringSliceToIntSlice(input.Ids)
sceneIDs, err := stringslice.StringSliceToIntSlice(input.Ids)
if err != nil {
return nil, err
}
@ -593,7 +595,7 @@ func (r *mutationResolver) SceneMarkerCreate(ctx context.Context, input models.S
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
}
tagIDs, err := utils.StringSliceToIntSlice(input.TagIds)
tagIDs, err := stringslice.StringSliceToIntSlice(input.TagIds)
if err != nil {
return nil, err
}
@ -633,7 +635,7 @@ func (r *mutationResolver) SceneMarkerUpdate(ctx context.Context, input models.S
UpdatedAt: models.SQLiteTimestamp{Timestamp: time.Now()},
}
tagIDs, err := utils.StringSliceToIntSlice(input.TagIds)
tagIDs, err := stringslice.StringSliceToIntSlice(input.TagIds)
if err != nil {
return nil, err
}
@ -746,7 +748,7 @@ func (r *mutationResolver) changeMarker(ctx context.Context, changeType int, cha
// Save the marker tags
// If this tag is the primary tag, then let's not add it.
tagIDs = utils.IntExclude(tagIDs, []int{changedMarker.PrimaryTagID})
tagIDs = intslice.IntExclude(tagIDs, []int{changedMarker.PrimaryTagID})
return qb.UpdateTags(sceneMarker.ID, tagIDs)
}); err != nil {
fileDeleter.Rollback()

View File

@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
)
func (r *mutationResolver) ReloadScrapers(ctx context.Context) (bool, error) {

View File

@ -5,8 +5,8 @@ import (
"fmt"
"strconv"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper/stashbox"
)

View File

@ -6,9 +6,11 @@ import (
"strconv"
"time"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/studio"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/utils"
@ -27,7 +29,7 @@ func (r *mutationResolver) getStudio(ctx context.Context, id int) (ret *models.S
func (r *mutationResolver) StudioCreate(ctx context.Context, input models.StudioCreateInput) (*models.Studio, error) {
// generate checksum from studio name rather than image
checksum := utils.MD5FromString(input.Name)
checksum := md5.FromString(input.Name)
var imageData []byte
var err error
@ -137,7 +139,7 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
}
if input.Name != nil {
// generate checksum from studio name rather than image
checksum := utils.MD5FromString(*input.Name)
checksum := md5.FromString(*input.Name)
updatedStudio.Name = &sql.NullString{String: *input.Name, Valid: true}
updatedStudio.Checksum = &checksum
}
@ -219,7 +221,7 @@ func (r *mutationResolver) StudioDestroy(ctx context.Context, input models.Studi
}
func (r *mutationResolver) StudiosDestroy(ctx context.Context, studioIDs []string) (bool, error) {
ids, err := utils.StringSliceToIntSlice(studioIDs)
ids, err := stringslice.StringSliceToIntSlice(studioIDs)
if err != nil {
return false, err
}

View File

@ -9,6 +9,7 @@ import (
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/tag"
"github.com/stashapp/stash/pkg/utils"
)
@ -48,14 +49,14 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input models.TagCreate
var childIDs []int
if len(input.ParentIds) > 0 {
parentIDs, err = utils.StringSliceToIntSlice(input.ParentIds)
parentIDs, err = stringslice.StringSliceToIntSlice(input.ParentIds)
if err != nil {
return nil, err
}
}
if len(input.ChildIds) > 0 {
childIDs, err = utils.StringSliceToIntSlice(input.ChildIds)
childIDs, err = stringslice.StringSliceToIntSlice(input.ChildIds)
if err != nil {
return nil, err
}
@ -148,14 +149,14 @@ func (r *mutationResolver) TagUpdate(ctx context.Context, input models.TagUpdate
var childIDs []int
if translator.hasField("parent_ids") {
parentIDs, err = utils.StringSliceToIntSlice(input.ParentIds)
parentIDs, err = stringslice.StringSliceToIntSlice(input.ParentIds)
if err != nil {
return nil, err
}
}
if translator.hasField("child_ids") {
childIDs, err = utils.StringSliceToIntSlice(input.ChildIds)
childIDs, err = stringslice.StringSliceToIntSlice(input.ChildIds)
if err != nil {
return nil, err
}
@ -264,7 +265,7 @@ func (r *mutationResolver) TagDestroy(ctx context.Context, input models.TagDestr
}
func (r *mutationResolver) TagsDestroy(ctx context.Context, tagIDs []string) (bool, error) {
ids, err := utils.StringSliceToIntSlice(tagIDs)
ids, err := stringslice.StringSliceToIntSlice(tagIDs)
if err != nil {
return false, err
}
@ -290,7 +291,7 @@ func (r *mutationResolver) TagsDestroy(ctx context.Context, tagIDs []string) (bo
}
func (r *mutationResolver) TagsMerge(ctx context.Context, input models.TagsMergeInput) (*models.Tag, error) {
source, err := utils.StringSliceToIntSlice(input.Source)
source, err := stringslice.StringSliceToIntSlice(input.Source)
if err != nil {
return nil, err
}

View File

@ -3,12 +3,13 @@ package api
import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper/stashbox"
"github.com/stashapp/stash/pkg/utils"
"golang.org/x/text/collate"
)
@ -27,19 +28,37 @@ func (r *queryResolver) Directory(ctx context.Context, path, locale *string) (*m
if path != nil {
dirPath = *path
}
currentDir := utils.GetDir(dirPath)
directories, err := utils.ListDir(col, currentDir)
currentDir := getDir(dirPath)
directories, err := listDir(col, currentDir)
if err != nil {
return directory, err
}
directory.Path = currentDir
directory.Parent = utils.GetParent(currentDir)
directory.Parent = getParent(currentDir)
directory.Directories = directories
return directory, err
}
func getDir(path string) string {
if path == "" {
path = fsutil.GetHomeDirectory()
}
return path
}
func getParent(path string) *string {
isRoot := path[len(path)-1:] == "/"
if isRoot {
return nil
} else {
parentPath := filepath.Clean(path + "/..")
return &parentPath
}
}
func makeConfigResult() *models.ConfigResult {
return &models.ConfigResult{
General: makeConfigGeneralResult(),

View File

@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -6,7 +6,7 @@ import (
"github.com/99designs/gqlgen/graphql"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
)
func (r *queryResolver) FindImage(ctx context.Context, id *string, checksum *string) (*models.Image, error) {
@ -47,11 +47,11 @@ func (r *queryResolver) FindImages(ctx context.Context, imageFilter *models.Imag
result, err := qb.Query(models.ImageQueryOptions{
QueryOptions: models.QueryOptions{
FindFilter: filter,
Count: utils.StrInclude(fields, "count"),
Count: stringslice.StrInclude(fields, "count"),
},
ImageFilter: imageFilter,
Megapixels: utils.StrInclude(fields, "megapixels"),
TotalSize: utils.StrInclude(fields, "filesize"),
Megapixels: stringslice.StrInclude(fields, "megapixels"),
TotalSize: stringslice.StrInclude(fields, "filesize"),
})
if err != nil {
return err

View File

@ -5,9 +5,9 @@ import (
"strconv"
"github.com/99designs/gqlgen/graphql"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
)
func (r *queryResolver) FindScene(ctx context.Context, id *string, checksum *string) (*models.Scene, error) {
@ -86,11 +86,11 @@ func (r *queryResolver) FindScenes(ctx context.Context, sceneFilter *models.Scen
result, err = repo.Scene().Query(models.SceneQueryOptions{
QueryOptions: models.QueryOptions{
FindFilter: filter,
Count: utils.StrInclude(fields, "count"),
Count: stringslice.StrInclude(fields, "count"),
},
SceneFilter: sceneFilter,
TotalDuration: utils.StrInclude(fields, "duration"),
TotalSize: utils.StrInclude(fields, "filesize"),
TotalDuration: stringslice.StrInclude(fields, "duration"),
TotalSize: stringslice.StrInclude(fields, "filesize"),
})
if err == nil {
scenes, err = result.Resolve()
@ -141,11 +141,11 @@ func (r *queryResolver) FindScenesByPathRegex(ctx context.Context, filter *model
result, err := repo.Scene().Query(models.SceneQueryOptions{
QueryOptions: models.QueryOptions{
FindFilter: queryFilter,
Count: utils.StrInclude(fields, "count"),
Count: stringslice.StrInclude(fields, "count"),
},
SceneFilter: sceneFilter,
TotalDuration: utils.StrInclude(fields, "duration"),
TotalSize: utils.StrInclude(fields, "filesize"),
TotalDuration: stringslice.StrInclude(fields, "duration"),
TotalSize: stringslice.StrInclude(fields, "filesize"),
})
if err != nil {
return err

View File

@ -4,8 +4,8 @@ import (
"context"
"strconv"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -3,11 +3,12 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)
func (r *queryResolver) Logs(ctx context.Context) ([]*models.LogEntry, error) {
logger := manager.GetInstance().Logger
logCache := logger.GetLogCache()
ret := make([]*models.LogEntry, len(logCache))

View File

@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -5,9 +5,9 @@ import (
"errors"
"strconv"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -6,7 +6,7 @@ import (
"fmt"
"strconv"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper"
"github.com/stashapp/stash/pkg/scraper/stashbox"

View File

@ -3,8 +3,8 @@ package api
import (
"context"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
)

View File

@ -3,7 +3,8 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/internal/log"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/models"
)
@ -26,7 +27,7 @@ func getLogLevel(logType string) models.LogLevel {
}
}
func logEntriesFromLogItems(logItems []logger.LogItem) []*models.LogEntry {
func logEntriesFromLogItems(logItems []log.LogItem) []*models.LogEntry {
ret := make([]*models.LogEntry, len(logItems))
for i, entry := range logItems {
@ -43,6 +44,7 @@ func logEntriesFromLogItems(logItems []logger.LogItem) []*models.LogEntry {
func (r *subscriptionResolver) LoggingSubscribe(ctx context.Context) (<-chan []*models.LogEntry, error) {
ret := make(chan []*models.LogEntry, 100)
stop := make(chan int, 1)
logger := manager.GetInstance().Logger
logSub := logger.SubscribeToLog(stop)
go func() {

View File

@ -5,7 +5,7 @@ import (
"net/http"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/internal/manager"
)
type downloadsRoutes struct{}

View File

@ -6,11 +6,11 @@ import (
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
type imageRoutes struct {
@ -39,7 +39,7 @@ func (rs imageRoutes) Thumbnail(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Cache-Control", "max-age=604800000")
// if the thumbnail doesn't exist, encode on the fly
exists, _ := utils.FileExists(filepath)
exists, _ := fsutil.FileExists(filepath)
if exists {
http.ServeFile(w, r, filepath)
} else {
@ -55,7 +55,7 @@ func (rs imageRoutes) Thumbnail(w http.ResponseWriter, r *http.Request) {
// write the generated thumbnail to disk if enabled
if manager.GetInstance().Config.IsWriteImageThumbnails() {
if err := utils.WriteFile(filepath, data); err != nil {
if err := fsutil.WriteFile(filepath, data); err != nil {
logger.Errorf("error writing thumbnail for image %s: %s", img.Path, err)
}
}

View File

@ -6,8 +6,8 @@ import (
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
@ -43,7 +43,7 @@ func (rs movieRoutes) FrontImage(w http.ResponseWriter, r *http.Request) {
}
if len(image) == 0 {
_, image, _ = utils.ProcessBase64Image(models.DefaultMovieImage)
image, _ = utils.ProcessBase64Image(models.DefaultMovieImage)
}
if err := utils.ServeImage(image, w, r); err != nil {
@ -66,7 +66,7 @@ func (rs movieRoutes) BackImage(w http.ResponseWriter, r *http.Request) {
}
if len(image) == 0 {
_, image, _ = utils.ProcessBase64Image(models.DefaultMovieImage)
image, _ = utils.ProcessBase64Image(models.DefaultMovieImage)
}
if err := utils.ServeImage(image, w, r); err != nil {

View File

@ -6,9 +6,9 @@ import (
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)

View File

@ -7,11 +7,13 @@ import (
"strings"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/utils"
)
@ -122,13 +124,13 @@ func (rs sceneRoutes) StreamHLS(w http.ResponseWriter, r *http.Request) {
ffmpeg.WriteHLSPlaylist(*videoFile, r.URL.String(), &str)
requestByteRange := utils.CreateByteRange(r.Header.Get("Range"))
requestByteRange := createByteRange(r.Header.Get("Range"))
if requestByteRange.RawString != "" {
logger.Debugf("Requested range: %s", requestByteRange.RawString)
}
ret := requestByteRange.Apply([]byte(str.String()))
rangeStr := requestByteRange.ToHeaderValue(int64(str.Len()))
ret := requestByteRange.apply([]byte(str.String()))
rangeStr := requestByteRange.toHeaderValue(int64(str.Len()))
w.Header().Set("Content-Range", rangeStr)
if n, err := w.Write(ret); err != nil {
@ -201,7 +203,15 @@ func (rs sceneRoutes) Screenshot(w http.ResponseWriter, r *http.Request) {
func (rs sceneRoutes) Preview(w http.ResponseWriter, r *http.Request) {
scene := r.Context().Value(sceneKey).(*models.Scene)
filepath := manager.GetInstance().Paths.Scene.GetStreamPreviewPath(scene.GetHash(config.GetInstance().GetVideoFileNamingAlgorithm()))
utils.ServeFileNoCache(w, r, filepath)
serveFileNoCache(w, r, filepath)
}
// serveFileNoCache serves the provided file, ensuring that the response
// contains headers to prevent caching.
func serveFileNoCache(w http.ResponseWriter, r *http.Request, filepath string) {
w.Header().Add("Cache-Control", "no-cache")
http.ServeFile(w, r, filepath)
}
func (rs sceneRoutes) Webp(w http.ResponseWriter, r *http.Request) {
@ -269,9 +279,9 @@ func (rs sceneRoutes) ChapterVtt(w http.ResponseWriter, r *http.Request) {
}
func (rs sceneRoutes) Funscript(w http.ResponseWriter, r *http.Request) {
scene := r.Context().Value(sceneKey).(*models.Scene)
funscript := utils.GetFunscriptPath(scene.Path)
utils.ServeFileNoCache(w, r, funscript)
s := r.Context().Value(sceneKey).(*models.Scene)
funscript := scene.GetFunscriptPath(s.Path)
serveFileNoCache(w, r, funscript)
}
func (rs sceneRoutes) InteractiveHeatmap(w http.ResponseWriter, r *http.Request) {
@ -340,7 +350,7 @@ func (rs sceneRoutes) SceneMarkerPreview(w http.ResponseWriter, r *http.Request)
filepath := manager.GetInstance().Paths.SceneMarkers.GetStreamPreviewImagePath(scene.GetHash(config.GetInstance().GetVideoFileNamingAlgorithm()), int(sceneMarker.Seconds))
// If the image doesn't exist, send the placeholder
exists, _ := utils.FileExists(filepath)
exists, _ := fsutil.FileExists(filepath)
if !exists {
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Cache-Control", "no-store")
@ -373,7 +383,7 @@ func (rs sceneRoutes) SceneMarkerScreenshot(w http.ResponseWriter, r *http.Reque
filepath := manager.GetInstance().Paths.SceneMarkers.GetStreamScreenshotPath(scene.GetHash(config.GetInstance().GetVideoFileNamingAlgorithm()), int(sceneMarker.Seconds))
// If the image doesn't exist, send the placeholder
exists, _ := utils.FileExists(filepath)
exists, _ := fsutil.FileExists(filepath)
if !exists {
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Cache-Control", "no-store")

View File

@ -8,8 +8,8 @@ import (
"syscall"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
@ -45,7 +45,7 @@ func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
}
if len(image) == 0 {
_, image, _ = utils.ProcessBase64Image(models.DefaultStudioImage)
image, _ = utils.ProcessBase64Image(models.DefaultStudioImage)
}
if err := utils.ServeImage(image, w, r); err != nil {

View File

@ -6,8 +6,8 @@ import (
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)

View File

@ -3,7 +3,6 @@ package api
import (
"context"
"crypto/tls"
"embed"
"errors"
"fmt"
"io/fs"
@ -23,23 +22,26 @@ import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/gorilla/websocket"
"github.com/vearutop/statigz"
"github.com/go-chi/httplog"
"github.com/rs/cors"
"github.com/stashapp/stash/pkg/desktop"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"github.com/vearutop/statigz"
"github.com/stashapp/stash/ui"
)
var version string
var buildstamp string
var githash string
func Start(uiBox embed.FS, loginUIBox embed.FS) {
var uiBox = ui.UIBox
var loginUIBox = ui.LoginUIBox
func Start() {
initialiseImages()
r := chi.NewRouter()
@ -144,7 +146,7 @@ func Start(uiBox embed.FS, loginUIBox embed.FS) {
// search for custom.css in current directory, then $HOME/.stash
fn := c.GetCSSPath()
exists, _ := utils.FileExists(fn)
exists, _ := fsutil.FileExists(fn)
if !exists {
return
}
@ -192,7 +194,7 @@ func Start(uiBox embed.FS, loginUIBox embed.FS) {
// Serve the web app
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
const uiRootDir = "ui/v2.5/build"
const uiRootDir = "v2.5/build"
ext := path.Ext(r.URL.Path)
@ -271,7 +273,6 @@ func Start(uiBox embed.FS, loginUIBox embed.FS) {
}
manager.GetInstance().Shutdown(0)
}()
desktop.Start(manager.GetInstance(), &FaviconProvider{uiBox: uiBox})
}
func printVersion() {

View File

@ -7,12 +7,12 @@ import (
"html/template"
"net/http"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/session"
)
const loginRootDir = "ui/login"
const loginRootDir = "login"
const returnURLParam = "returnURL"
func getLoginPage(loginUIBox embed.FS) []byte {

View File

@ -11,9 +11,9 @@ import (
"testing"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/utils"
_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
@ -149,7 +149,7 @@ func createScenes(sqb models.SceneReaderWriter) error {
func makeScene(name string, expectedResult bool) *models.Scene {
scene := &models.Scene{
Checksum: sql.NullString{String: utils.MD5FromString(name), Valid: true},
Checksum: sql.NullString{String: md5.FromString(name), Valid: true},
Path: name,
}
@ -211,7 +211,7 @@ func createImages(sqb models.ImageReaderWriter) error {
func makeImage(name string, expectedResult bool) *models.Image {
image := &models.Image{
Checksum: utils.MD5FromString(name),
Checksum: md5.FromString(name),
Path: name,
}
@ -273,7 +273,7 @@ func createGalleries(sqb models.GalleryReaderWriter) error {
func makeGallery(name string, expectedResult bool) *models.Gallery {
gallery := &models.Gallery{
Checksum: utils.MD5FromString(name),
Checksum: md5.FromString(name),
Path: models.NullString(name),
}

View File

@ -3,7 +3,6 @@ package desktop
import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
@ -11,9 +10,9 @@ import (
"strings"
"github.com/pkg/browser"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/utils"
"golang.org/x/term"
)
@ -26,6 +25,7 @@ type FaviconProvider interface {
GetFaviconPng() []byte
}
// Start starts the desktop icon process. It blocks until the process exits.
func Start(shutdownHandler ShutdownHandler, faviconProvider FaviconProvider) {
if IsDesktop() {
c := config.GetInstance()
@ -81,11 +81,6 @@ func IsServerDockerized() bool {
return isServerDockerized()
}
// Set a command to execute in the background, instead of spawning a shell window
func HideExecShell(cmd *exec.Cmd) {
hideExecShell(cmd)
}
// writeStashIcon writes the current stash logo to config/icon.png
func writeStashIcon(faviconProvider FaviconProvider) {
c := config.GetInstance()
@ -119,7 +114,7 @@ func IsAllowedAutoUpdate() bool {
logger.Errorf("Cannot get executable path: %s", err)
return false
}
if utils.IsPathInDir("/usr", executablePath) || utils.IsPathInDir("/opt", executablePath) {
if fsutil.IsPathInDir("/usr", executablePath) || fsutil.IsPathInDir("/opt", executablePath) {
return false
}
@ -136,7 +131,7 @@ func getIconPath() string {
}
func RevealInFileManager(path string) {
exists, err := utils.FileExists(path)
exists, err := fsutil.FileExists(path)
if err != nil {
logger.Errorf("Error checking file: %s", err)
return

View File

@ -19,10 +19,6 @@ func isServerDockerized() bool {
return false
}
func hideExecShell(cmd *exec.Cmd) {
}
func sendNotification(notificationTitle string, notificationText string) {
notification := gosxnotifier.NewNotification(notificationText)
notification.Title = notificationTitle

View File

@ -27,10 +27,6 @@ func isServerDockerized() bool {
return false
}
func hideExecShell(cmd *exec.Cmd) {
}
func sendNotification(notificationTitle string, notificationText string) {
err := exec.Command("notify-send", "-i", getIconPath(), notificationTitle, notificationText, "-a", "Stash").Run()
if err != nil {

View File

@ -5,9 +5,6 @@ package desktop
import (
"os/exec"
"syscall"
"golang.org/x/sys/windows"
"github.com/go-toast/toast"
"github.com/stashapp/stash/pkg/logger"
@ -27,12 +24,6 @@ func isServerDockerized() bool {
return false
}
// On Windows, calling exec.Cmd.Start() will create a cmd window, even if we live in the taskbar.
// We don't want every ffmpeg / plugin to pop up a window.
func hideExecShell(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: windows.DETACHED_PROCESS}
}
func sendNotification(notificationTitle string, notificationText string) {
notification := toast.Notification{
AppID: "Stash",

View File

@ -7,8 +7,8 @@ import (
"strings"
"github.com/kermieisinthehouse/systray"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
)
// MUST be run on the main goroutine or will have no effect on macOS

View File

@ -40,7 +40,7 @@ import (
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/utils"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
)
var pageSize = 100
@ -491,7 +491,7 @@ func (me *contentDirectoryService) getPageVideos(sceneFilter *models.SceneFilter
}
func getPageFromID(paths []string) *int {
i := utils.StrIndex(paths, "page")
i := stringslice.StrIndex(paths, "page")
if i == -1 || i+1 >= len(paths) {
return nil
}

Some files were not shown because too many files have changed in this diff Show More