Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stashapp/stash into here…
Browse files Browse the repository at this point in the history
…sphere-api
  • Loading branch information
NodudeWasTaken committed Sep 12, 2023
2 parents c4fe002 + f51ac81 commit 0dbe5f2
Show file tree
Hide file tree
Showing 2,757 changed files with 1,377 additions and 1,260,541 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: docker exec -t build /bin/bash -c "make generate-backend"

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
Expand All @@ -42,19 +42,26 @@ jobs:
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --modules-download-mode=vendor --timeout=5m
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
args: --timeout=5m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true
# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
skip-build-cache: true
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"

- name: Cleanup build container
run: docker rm -f -v build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Go
####

# Vendored dependencies
vendor

# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# options for analysis running
run:
timeout: 5m
modules-download-mode: vendor

linters:
disable-all: true
Expand Down
2 changes: 1 addition & 1 deletion cmd/stash/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run -mod=vendor github.com/99designs/gqlgen
//go:generate go run github.com/99designs/gqlgen
package main

import (
Expand Down
1 change: 0 additions & 1 deletion docker/build/x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ RUN apk add --no-cache make alpine-sdk
WORKDIR /stash
COPY ./go* ./*.go Makefile gqlgen.yml .gqlgenc.yml /stash/
COPY ./scripts /stash/scripts/
COPY ./vendor /stash/vendor/
COPY ./pkg /stash/pkg/
COPY ./cmd /stash/cmd
COPY ./internal /stash/internal
Expand Down
1 change: 0 additions & 1 deletion docker/build/x86_64/Dockerfile-CUDA
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ RUN apt update && apt install -y build-essential golang
WORKDIR /stash
COPY ./go* ./*.go Makefile gqlgen.yml .gqlgenc.yml /stash/
COPY ./scripts /stash/scripts/
COPY ./vendor /stash/vendor/
COPY ./pkg /stash/pkg/
COPY ./cmd /stash/cmd
COPY ./internal /stash/internal
Expand Down
2 changes: 1 addition & 1 deletion graphql/documents/data/image-slim.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fragment SlimImageData on Image {
id
title
date
url
urls
rating100
organized
o_counter
Expand Down
2 changes: 1 addition & 1 deletion graphql/documents/data/image.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fragment ImageData on Image {
title
rating100
date
url
urls
organized
o_counter
created_at
Expand Down
9 changes: 6 additions & 3 deletions graphql/schema/types/image.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type Image {
rating: Int @deprecated(reason: "Use 1-100 range with rating100")
# rating expressed as 1-100
rating100: Int
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]!
date: String
o_counter: Int
organized: Boolean!
Expand Down Expand Up @@ -48,7 +49,8 @@ input ImageUpdateInput {
# rating expressed as 1-100
rating100: Int
organized: Boolean
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
date: String

studio_id: ID
Expand All @@ -68,7 +70,8 @@ input BulkImageUpdateInput {
# rating expressed as 1-100
rating100: Int
organized: Boolean
url: String
url: String @deprecated(reason: "Use urls")
urls: BulkUpdateStrings
date: String

studio_id: ID
Expand Down
2 changes: 1 addition & 1 deletion graphql/schema/types/scene.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Scene {
details: String
director: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
urls: [String!]!
date: String
# rating expressed as 1-5
rating: Int @deprecated(reason: "Use 1-100 range with rating100")
Expand Down
40 changes: 40 additions & 0 deletions internal/api/changeset_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,46 @@ func (t changesetTranslator) updateIdsBulk(value *BulkUpdateIds, field string) (
}, nil
}

func (t changesetTranslator) optionalURLs(value []string, legacyValue *string) *models.UpdateStrings {
const (
legacyField = "url"
field = "urls"
)

// prefer urls over url
if t.hasField(field) {
return t.updateStrings(value, field)
} else if t.hasField(legacyField) {
var valueSlice []string
if legacyValue != nil {
valueSlice = []string{*legacyValue}
}
return t.updateStrings(valueSlice, legacyField)
}

return nil
}

func (t changesetTranslator) optionalURLsBulk(value *BulkUpdateStrings, legacyValue *string) *models.UpdateStrings {
const (
legacyField = "url"
field = "urls"
)

// prefer urls over url
if t.hasField("urls") {
return t.updateStringsBulk(value, field)
} else if t.hasField(legacyField) {
var valueSlice []string
if legacyValue != nil {
valueSlice = []string{*legacyValue}
}
return t.updateStrings(valueSlice, legacyField)
}

return nil
}

func (t changesetTranslator) updateStrings(value []string, field string) *models.UpdateStrings {
if !t.hasField(field) {
return nil
Expand Down
29 changes: 29 additions & 0 deletions internal/api/resolver_model_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,32 @@ func (r *imageResolver) Performers(ctx context.Context, obj *models.Image) (ret
ret, errs = loaders.From(ctx).PerformerByID.LoadAll(obj.PerformerIDs.List())
return ret, firstError(errs)
}

func (r *imageResolver) URL(ctx context.Context, obj *models.Image) (*string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Image)
}); err != nil {
return nil, err
}
}

urls := obj.URLs.List()
if len(urls) == 0 {
return nil, nil
}

return &urls[0], nil
}

func (r *imageResolver) Urls(ctx context.Context, obj *models.Image) ([]string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Image)
}); err != nil {
return nil, err
}
}

return obj.URLs.List(), nil
}
6 changes: 4 additions & 2 deletions internal/api/resolver_mutation_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (r *mutationResolver) imageUpdate(ctx context.Context, input ImageUpdateInp

updatedImage.Title = translator.optionalString(input.Title, "title")
updatedImage.Rating = translator.optionalRatingConversion(input.Rating, input.Rating100)
updatedImage.URL = translator.optionalString(input.URL, "url")
updatedImage.Organized = translator.optionalBool(input.Organized, "organized")

updatedImage.Date, err = translator.optionalDate(input.Date, "date")
Expand All @@ -120,6 +119,8 @@ func (r *mutationResolver) imageUpdate(ctx context.Context, input ImageUpdateInp
return nil, fmt.Errorf("converting studio id: %w", err)
}

updatedImage.URLs = translator.optionalURLs(input.Urls, input.URL)

updatedImage.PrimaryFileID, err = translator.fileIDPtrFromString(input.PrimaryFileID)
if err != nil {
return nil, fmt.Errorf("converting primary file id: %w", err)
Expand Down Expand Up @@ -203,7 +204,6 @@ func (r *mutationResolver) BulkImageUpdate(ctx context.Context, input BulkImageU

updatedImage.Title = translator.optionalString(input.Title, "title")
updatedImage.Rating = translator.optionalRatingConversion(input.Rating, input.Rating100)
updatedImage.URL = translator.optionalString(input.URL, "url")
updatedImage.Organized = translator.optionalBool(input.Organized, "organized")

updatedImage.Date, err = translator.optionalDate(input.Date, "date")
Expand All @@ -215,6 +215,8 @@ func (r *mutationResolver) BulkImageUpdate(ctx context.Context, input BulkImageU
return nil, fmt.Errorf("converting studio id: %w", err)
}

updatedImage.URLs = translator.optionalURLsBulk(input.Urls, input.URL)

updatedImage.GalleryIDs, err = translator.updateIdsBulk(input.GalleryIds, "gallery_ids")
if err != nil {
return nil, fmt.Errorf("converting gallery ids: %w", err)
Expand Down
22 changes: 2 additions & 20 deletions internal/api/resolver_mutation_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,7 @@ func scenePartialFromInput(input models.SceneUpdateInput, translator changesetTr
return nil, fmt.Errorf("converting studio id: %w", err)
}

// prefer urls over url
if translator.hasField("urls") {
updatedScene.URLs = translator.updateStrings(input.Urls, "urls")
} else if translator.hasField("url") {
var urls []string
if input.URL != nil {
urls = []string{*input.URL}
}
updatedScene.URLs = translator.updateStrings(urls, "url")
}
updatedScene.URLs = translator.optionalURLs(input.Urls, input.URL)

updatedScene.PrimaryFileID, err = translator.fileIDPtrFromString(input.PrimaryFileID)
if err != nil {
Expand Down Expand Up @@ -342,16 +333,7 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input BulkSceneU
return nil, fmt.Errorf("converting studio id: %w", err)
}

// prefer urls over url
if translator.hasField("urls") {
updatedScene.URLs = translator.updateStringsBulk(input.Urls, "urls")
} else if translator.hasField("url") {
var urls []string
if input.URL != nil {
urls = []string{*input.URL}
}
updatedScene.URLs = translator.updateStrings(urls, "url")
}
updatedScene.URLs = translator.optionalURLsBulk(input.Urls, input.URL)

updatedScene.PerformerIDs, err = translator.updateIdsBulk(input.PerformerIds, "performer_ids")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/manager/task_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ func exportImage(ctx context.Context, wg *sync.WaitGroup, jobChan <-chan *models
continue
}

if err := s.LoadURLs(ctx, repo.Image); err != nil {
logger.Errorf("[images] <%s> error getting image urls: %s", imageHash, err.Error())
continue
}

newImageJSON := image.ToBasicJSON(s)

// export files
Expand Down
15 changes: 1 addition & 14 deletions pkg/image/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func ToBasicJSON(image *models.Image) *jsonschema.Image {
newImageJSON := jsonschema.Image{
Title: image.Title,
URL: image.URL,
URLs: image.URLs.List(),
CreatedAt: json.JSONTime{Time: image.CreatedAt},
UpdatedAt: json.JSONTime{Time: image.UpdatedAt},
}
Expand All @@ -37,19 +37,6 @@ func ToBasicJSON(image *models.Image) *jsonschema.Image {
return &newImageJSON
}

// func getImageFileJSON(image *models.Image) *jsonschema.ImageFile {
// ret := &jsonschema.ImageFile{}

// f := image.PrimaryFile()

// ret.ModTime = json.JSONTime{Time: f.ModTime}
// ret.Size = f.Size
// ret.Width = f.Width
// ret.Height = f.Height

// return ret
// }

// GetStudioName returns the name of the provided image's studio. It returns an
// empty string if there is no studio assigned to the image.
func GetStudioName(ctx context.Context, reader models.StudioGetter, image *models.Image) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/image/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func createFullImage(id int) models.Image {
OCounter: ocounter,
Rating: &rating,
Date: &dateObj,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Organized: organized,
CreatedAt: createTime,
UpdatedAt: updateTime,
Expand All @@ -66,7 +66,7 @@ func createFullJSONImage() *jsonschema.Image {
OCounter: ocounter,
Rating: rating,
Date: date,
URL: url,
URLs: []string{url},
Organized: organized,
Files: []string{path},
CreatedAt: json.JSONTime{
Expand Down
9 changes: 5 additions & 4 deletions pkg/image/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func (i *Importer) PreImport(ctx context.Context) error {

func (i *Importer) imageJSONToImage(imageJSON jsonschema.Image) models.Image {
newImage := models.Image{
// Checksum: imageJSON.Checksum,
// Path: i.Path,
PerformerIDs: models.NewRelatedIDs([]int{}),
TagIDs: models.NewRelatedIDs([]int{}),
GalleryIDs: models.NewRelatedIDs([]int{}),
Expand All @@ -81,9 +79,12 @@ func (i *Importer) imageJSONToImage(imageJSON jsonschema.Image) models.Image {
if imageJSON.Rating != 0 {
newImage.Rating = &imageJSON.Rating
}
if imageJSON.URL != "" {
newImage.URL = imageJSON.URL
if len(imageJSON.URLs) > 0 {
newImage.URLs = models.NewRelatedStrings(imageJSON.URLs)
} else if imageJSON.URL != "" {
newImage.URLs = models.NewRelatedStrings([]string{imageJSON.URL})
}

if imageJSON.Date != "" {
d, err := models.ParseDate(imageJSON.Date)
if err == nil {
Expand Down
12 changes: 8 additions & 4 deletions pkg/models/jsonschema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
)

type Image struct {
Title string `json:"title,omitempty"`
Studio string `json:"studio,omitempty"`
Rating int `json:"rating,omitempty"`
URL string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
Studio string `json:"studio,omitempty"`
Rating int `json:"rating,omitempty"`

// deprecated - for import only
URL string `json:"url,omitempty"`

URLs []string `json:"urls,omitempty"`
Date string `json:"date,omitempty"`
Organized bool `json:"organized,omitempty"`
OCounter int `json:"o_counter,omitempty"`
Expand Down
Loading

0 comments on commit 0dbe5f2

Please sign in to comment.