Feature: Support Multiple URLs in Studios (#6223)

* Backend support for studio URLs
* FrontEnd addition
* Support URLs in BulkStudioUpdate
* Update tagger modal for URLs
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
Gykes
2025-11-09 19:34:21 -08:00
committed by GitHub
parent 12a9a0b5f6
commit f434c1f529
33 changed files with 451 additions and 69 deletions

View File

@@ -12,7 +12,7 @@ import (
type Studio struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
URLs []string `json:"urls,omitempty"`
ParentStudio string `json:"parent_studio,omitempty"`
Image string `json:"image,omitempty"`
CreatedAt json.JSONTime `json:"created_at,omitempty"`
@@ -24,6 +24,9 @@ type Studio struct {
StashIDs []models.StashID `json:"stash_ids,omitempty"`
Tags []string `json:"tags,omitempty"`
IgnoreAutoTag bool `json:"ignore_auto_tag,omitempty"`
// deprecated - for import only
URL string `json:"url,omitempty"`
}
func (s Studio) Filename() string {

View File

@@ -360,6 +360,29 @@ func (_m *StudioReaderWriter) GetTagIDs(ctx context.Context, relatedID int) ([]i
return r0, r1
}
// GetURLs provides a mock function with given fields: ctx, relatedID
func (_m *StudioReaderWriter) GetURLs(ctx context.Context, relatedID int) ([]string, error) {
ret := _m.Called(ctx, relatedID)
var r0 []string
if rf, ok := ret.Get(0).(func(context.Context, int) []string); ok {
r0 = rf(ctx, relatedID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]string)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int) error); ok {
r1 = rf(ctx, relatedID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// HasImage provides a mock function with given fields: ctx, studioID
func (_m *StudioReaderWriter) HasImage(ctx context.Context, studioID int) (bool, error) {
ret := _m.Called(ctx, studioID)

View File

@@ -14,7 +14,8 @@ type ScrapedStudio struct {
// Set if studio matched
StoredID *string `json:"stored_id"`
Name string `json:"name"`
URL *string `json:"url"`
URL *string `json:"url"` // deprecated
URLs []string `json:"urls"`
Parent *ScrapedStudio `json:"parent"`
Image *string `json:"image"`
Images []string `json:"images"`
@@ -38,8 +39,20 @@ func (s *ScrapedStudio) ToStudio(endpoint string, excluded map[string]bool) *Stu
})
}
if s.URL != nil && !excluded["url"] {
ret.URL = *s.URL
// if URLs are provided, only use those
if len(s.URLs) > 0 {
if !excluded["urls"] {
ret.URLs = NewRelatedStrings(s.URLs)
}
} else {
urls := []string{}
if s.URL != nil && !excluded["url"] {
urls = append(urls, *s.URL)
}
if len(urls) > 0 {
ret.URLs = NewRelatedStrings(urls)
}
}
if s.Parent != nil && s.Parent.StoredID != nil && !excluded["parent"] && !excluded["parent_studio"] {
@@ -74,8 +87,25 @@ func (s *ScrapedStudio) ToPartial(id string, endpoint string, excluded map[strin
ret.Name = NewOptionalString(s.Name)
}
if s.URL != nil && !excluded["url"] {
ret.URL = NewOptionalString(*s.URL)
if len(s.URLs) > 0 {
if !excluded["urls"] {
ret.URLs = &UpdateStrings{
Values: s.URLs,
Mode: RelationshipUpdateModeSet,
}
}
} else {
urls := []string{}
if s.URL != nil && !excluded["url"] {
urls = append(urls, *s.URL)
}
if len(urls) > 0 {
ret.URLs = &UpdateStrings{
Values: urls,
Mode: RelationshipUpdateModeSet,
}
}
}
if s.Parent != nil && !excluded["parent"] {

View File

@@ -11,6 +11,7 @@ import (
func Test_scrapedToStudioInput(t *testing.T) {
const name = "name"
url := "url"
url2 := "url2"
emptyEndpoint := ""
endpoint := "endpoint"
remoteSiteID := "remoteSiteID"
@@ -25,13 +26,33 @@ func Test_scrapedToStudioInput(t *testing.T) {
"set all",
&ScrapedStudio{
Name: name,
URLs: []string{url, url2},
URL: &url,
RemoteSiteID: &remoteSiteID,
},
endpoint,
&Studio{
Name: name,
URL: url,
URLs: NewRelatedStrings([]string{url, url2}),
StashIDs: NewRelatedStashIDs([]StashID{
{
Endpoint: endpoint,
StashID: remoteSiteID,
},
}),
},
},
{
"set url instead of urls",
&ScrapedStudio{
Name: name,
URL: &url,
RemoteSiteID: &remoteSiteID,
},
endpoint,
&Studio{
Name: name,
URLs: NewRelatedStrings([]string{url}),
StashIDs: NewRelatedStashIDs([]StashID{
{
Endpoint: endpoint,
@@ -321,9 +342,12 @@ func TestScrapedStudio_ToPartial(t *testing.T) {
fullStudio,
stdArgs,
StudioPartial{
ID: id,
Name: NewOptionalString(name),
URL: NewOptionalString(url),
ID: id,
Name: NewOptionalString(name),
URLs: &UpdateStrings{
Values: []string{url},
Mode: RelationshipUpdateModeSet,
},
ParentID: NewOptionalInt(parentStoredID),
StashIDs: &UpdateStashIDs{
StashIDs: append(existingStashIDs, StashID{

View File

@@ -8,7 +8,6 @@ import (
type Studio struct {
ID int `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
ParentID *int `json:"parent_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@@ -19,6 +18,7 @@ type Studio struct {
IgnoreAutoTag bool `json:"ignore_auto_tag"`
Aliases RelatedStrings `json:"aliases"`
URLs RelatedStrings `json:"urls"`
TagIDs RelatedIDs `json:"tag_ids"`
StashIDs RelatedStashIDs `json:"stash_ids"`
}
@@ -35,7 +35,6 @@ func NewStudio() Studio {
type StudioPartial struct {
ID int
Name OptionalString
URL OptionalString
ParentID OptionalInt
// Rating expressed in 1-100 scale
Rating OptionalInt
@@ -46,6 +45,7 @@ type StudioPartial struct {
IgnoreAutoTag OptionalBool
Aliases *UpdateStrings
URLs *UpdateStrings
TagIDs *UpdateIDs
StashIDs *UpdateStashIDs
}
@@ -63,6 +63,12 @@ func (s *Studio) LoadAliases(ctx context.Context, l AliasLoader) error {
})
}
func (s *Studio) LoadURLs(ctx context.Context, l URLLoader) error {
return s.URLs.load(func() ([]string, error) {
return l.GetURLs(ctx, s.ID)
})
}
func (s *Studio) LoadTagIDs(ctx context.Context, l TagIDLoader) error {
return s.TagIDs.load(func() ([]int, error) {
return l.GetTagIDs(ctx, s.ID)

View File

@@ -77,6 +77,7 @@ type StudioReader interface {
AliasLoader
StashIDLoader
TagIDLoader
URLLoader
All(ctx context.Context) ([]*Studio, error)
GetImage(ctx context.Context, studioID int) ([]byte, error)

View File

@@ -47,9 +47,10 @@ type StudioFilterType struct {
}
type StudioCreateInput struct {
Name string `json:"name"`
URL *string `json:"url"`
ParentID *string `json:"parent_id"`
Name string `json:"name"`
URL *string `json:"url"` // deprecated
Urls []string `json:"urls"`
ParentID *string `json:"parent_id"`
// This should be a URL or a base64 encoded data URL
Image *string `json:"image"`
StashIds []StashIDInput `json:"stash_ids"`
@@ -62,10 +63,11 @@ type StudioCreateInput struct {
}
type StudioUpdateInput struct {
ID string `json:"id"`
Name *string `json:"name"`
URL *string `json:"url"`
ParentID *string `json:"parent_id"`
ID string `json:"id"`
Name *string `json:"name"`
URL *string `json:"url"` // deprecated
Urls []string `json:"urls"`
ParentID *string `json:"parent_id"`
// This should be a URL or a base64 encoded data URL
Image *string `json:"image"`
StashIds []StashIDInput `json:"stash_ids"`

View File

@@ -233,7 +233,7 @@ func performerJSONToPerformer(performerJSON jsonschema.Performer) models.Perform
}
if len(urls) > 0 {
newPerformer.URLs = models.NewRelatedStrings([]string{performerJSON.URL})
newPerformer.URLs = models.NewRelatedStrings(urls)
}
}

View File

@@ -619,7 +619,6 @@ func (db *Anonymiser) anonymiseStudios(ctx context.Context) error {
query := dialect.From(table).Select(
table.Col(idColumn),
table.Col("name"),
table.Col("url"),
table.Col("details"),
).Where(table.Col(idColumn).Gt(lastID)).Limit(1000)
@@ -630,14 +629,12 @@ func (db *Anonymiser) anonymiseStudios(ctx context.Context) error {
var (
id int
name sql.NullString
url sql.NullString
details sql.NullString
)
if err := rows.Scan(
&id,
&name,
&url,
&details,
); err != nil {
return err
@@ -645,7 +642,6 @@ func (db *Anonymiser) anonymiseStudios(ctx context.Context) error {
set := goqu.Record{}
db.obfuscateNullString(set, "name", name)
db.obfuscateNullString(set, "url", url)
db.obfuscateNullString(set, "details", details)
if len(set) > 0 {
@@ -677,6 +673,10 @@ func (db *Anonymiser) anonymiseStudios(ctx context.Context) error {
return err
}
if err := db.anonymiseURLs(ctx, goqu.T(studioURLsTable), "studio_id"); err != nil {
return err
}
return nil
}

View File

@@ -34,7 +34,7 @@ const (
cacheSizeEnv = "STASH_SQLITE_CACHE_SIZE"
)
var appSchemaVersion uint = 72
var appSchemaVersion uint = 73
//go:embed migrations/*.sql
var migrationsBox embed.FS

View File

@@ -0,0 +1,24 @@
CREATE TABLE `studio_urls` (
`studio_id` integer NOT NULL,
`position` integer NOT NULL,
`url` varchar(255) NOT NULL,
foreign key(`studio_id`) references `studios`(`id`) on delete CASCADE,
PRIMARY KEY(`studio_id`, `position`, `url`)
);
CREATE INDEX `studio_urls_url` on `studio_urls` (`url`);
INSERT INTO `studio_urls`
(
`studio_id`,
`position`,
`url`
)
SELECT
`id`,
'0',
`url`
FROM `studios`
WHERE `studios`.`url` IS NOT NULL AND `studios`.`url` != '';
ALTER TABLE `studios` DROP COLUMN `url`;

View File

@@ -0,0 +1,7 @@
# Creating a migration
1. Create new migration file in the migrations directory with the format `NN_description.up.sql`, where `NN` is the next sequential number.
2. Update `pkg/sqlite/database.go` to update the `appSchemaVersion` value to the new migration number.
For migrations requiring complex logic or config file changes, see existing custom migrations for examples.

View File

@@ -2659,6 +2659,21 @@ func verifyString(t *testing.T, value string, criterion models.StringCriterionIn
}
}
func verifyStringList(t *testing.T, values []string, criterion models.StringCriterionInput) {
t.Helper()
assert := assert.New(t)
switch criterion.Modifier {
case models.CriterionModifierIsNull:
assert.Empty(values)
case models.CriterionModifierNotNull:
assert.NotEmpty(values)
default:
for _, v := range values {
verifyString(t, v, criterion)
}
}
}
func TestSceneQueryRating100(t *testing.T) {
const rating = 60
ratingCriterion := models.IntCriterionInput{

View File

@@ -1770,6 +1770,24 @@ func getStudioBoolValue(index int) bool {
return index == 1
}
func getStudioEmptyString(index int, field string) string {
v := getPrefixedNullStringValue("studio", index, field)
if !v.Valid {
return ""
}
return v.String
}
func getStudioStringList(index int, field string) []string {
v := getStudioEmptyString(index, field)
if v == "" {
return []string{}
}
return []string{v}
}
// createStudios creates n studios with plain Name and o studios with camel cased NaMe included
func createStudios(ctx context.Context, n int, o int) error {
sqb := db.Studio
@@ -1790,7 +1808,7 @@ func createStudios(ctx context.Context, n int, o int) error {
tids := indexesToIDs(tagIDs, studioTags[i])
studio := models.Studio{
Name: name,
URL: getStudioStringValue(index, urlField),
URLs: models.NewRelatedStrings(getStudioStringList(i, urlField)),
Favorite: getStudioBoolValue(index),
IgnoreAutoTag: getIgnoreAutoTag(i),
TagIDs: models.NewRelatedIDs(tids),

View File

@@ -18,8 +18,12 @@ import (
)
const (
studioTable = "studios"
studioIDColumn = "studio_id"
studioTable = "studios"
studioIDColumn = "studio_id"
studioURLsTable = "studio_urls"
studioURLColumn = "url"
studioAliasesTable = "studio_aliases"
studioAliasColumn = "alias"
studioParentIDColumn = "parent_id"
@@ -31,7 +35,6 @@ const (
type studioRow struct {
ID int `db:"id" goqu:"skipinsert"`
Name zero.String `db:"name"`
URL zero.String `db:"url"`
ParentID null.Int `db:"parent_id,omitempty"`
CreatedAt Timestamp `db:"created_at"`
UpdatedAt Timestamp `db:"updated_at"`
@@ -48,7 +51,6 @@ type studioRow struct {
func (r *studioRow) fromStudio(o models.Studio) {
r.ID = o.ID
r.Name = zero.StringFrom(o.Name)
r.URL = zero.StringFrom(o.URL)
r.ParentID = intFromPtr(o.ParentID)
r.CreatedAt = Timestamp{Timestamp: o.CreatedAt}
r.UpdatedAt = Timestamp{Timestamp: o.UpdatedAt}
@@ -62,7 +64,6 @@ func (r *studioRow) resolve() *models.Studio {
ret := &models.Studio{
ID: r.ID,
Name: r.Name.String,
URL: r.URL.String,
ParentID: nullIntPtr(r.ParentID),
CreatedAt: r.CreatedAt.Timestamp,
UpdatedAt: r.UpdatedAt.Timestamp,
@@ -81,7 +82,6 @@ type studioRowRecord struct {
func (r *studioRowRecord) fromPartial(o models.StudioPartial) {
r.setNullString("name", o.Name)
r.setNullString("url", o.URL)
r.setNullInt("parent_id", o.ParentID)
r.setTimestamp("created_at", o.CreatedAt)
r.setTimestamp("updated_at", o.UpdatedAt)
@@ -190,6 +190,13 @@ func (qb *StudioStore) Create(ctx context.Context, newObject *models.Studio) err
}
}
if newObject.URLs.Loaded() {
const startPos = 0
if err := studiosURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
if err := qb.tagRelationshipStore.createRelationships(ctx, id, newObject.TagIDs); err != nil {
return err
}
@@ -234,6 +241,12 @@ func (qb *StudioStore) UpdatePartial(ctx context.Context, input models.StudioPar
}
}
if input.URLs != nil {
if err := studiosURLsTableMgr.modifyJoins(ctx, input.ID, input.URLs.Values, input.URLs.Mode); err != nil {
return nil, err
}
}
if err := qb.tagRelationshipStore.modifyRelationships(ctx, input.ID, input.TagIDs); err != nil {
return nil, err
}
@@ -262,6 +275,12 @@ func (qb *StudioStore) Update(ctx context.Context, updatedObject *models.Studio)
}
}
if updatedObject.URLs.Loaded() {
if err := studiosURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}
if err := qb.tagRelationshipStore.replaceRelationships(ctx, updatedObject.ID, updatedObject.TagIDs); err != nil {
return err
}
@@ -507,7 +526,7 @@ func (qb *StudioStore) QueryForAutoTag(ctx context.Context, words []string) ([]*
ret, err := qb.findBySubquery(ctx, sq)
if err != nil {
return nil, fmt.Errorf("getting performers for autotag: %w", err)
return nil, fmt.Errorf("getting studios for autotag: %w", err)
}
return ret, nil
@@ -663,3 +682,7 @@ func (qb *StudioStore) GetStashIDs(ctx context.Context, studioID int) ([]models.
func (qb *StudioStore) GetAliases(ctx context.Context, studioID int) ([]string, error) {
return studiosAliasesTableMgr.get(ctx, studioID)
}
func (qb *StudioStore) GetURLs(ctx context.Context, studioID int) ([]string, error) {
return studiosURLsTableMgr.get(ctx, studioID)
}

View File

@@ -55,7 +55,7 @@ func (qb *studioFilterHandler) criterionHandler() criterionHandler {
return compoundHandler{
stringCriterionHandler(studioFilter.Name, studioTable+".name"),
stringCriterionHandler(studioFilter.Details, studioTable+".details"),
stringCriterionHandler(studioFilter.URL, studioTable+".url"),
qb.urlsCriterionHandler(studioFilter.URL),
intCriterionHandler(studioFilter.Rating100, studioTable+".rating", nil),
boolCriterionHandler(studioFilter.Favorite, studioTable+".favorite", nil),
boolCriterionHandler(studioFilter.IgnoreAutoTag, studioTable+".ignore_auto_tag", nil),
@@ -118,6 +118,9 @@ func (qb *studioFilterHandler) isMissingCriterionHandler(isMissing *string) crit
return func(ctx context.Context, f *filterBuilder) {
if isMissing != nil && *isMissing != "" {
switch *isMissing {
case "url":
studiosURLsTableMgr.join(f, "", "studios.id")
f.addWhere("studio_urls.url IS NULL")
case "image":
f.addWhere("studios.image_blob IS NULL")
case "stash_id":
@@ -202,6 +205,20 @@ func (qb *studioFilterHandler) aliasCriterionHandler(alias *models.StringCriteri
return h.handler(alias)
}
func (qb *studioFilterHandler) urlsCriterionHandler(url *models.StringCriterionInput) criterionHandlerFunc {
h := stringListCriterionHandlerBuilder{
primaryTable: studioTable,
primaryFK: studioIDColumn,
joinTable: studioURLsTable,
stringColumn: studioURLColumn,
addJoinTable: func(f *filterBuilder) {
studiosURLsTableMgr.join(f, "", "studios.id")
},
}
return h.handler(url)
}
func (qb *studioFilterHandler) childCountCriterionHandler(childCount *models.IntCriterionInput) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if childCount != nil {

View File

@@ -82,6 +82,14 @@ func TestStudioQueryNameOr(t *testing.T) {
})
}
func loadStudioRelationships(ctx context.Context, t *testing.T, s *models.Studio) error {
if err := s.LoadURLs(ctx, db.Studio); err != nil {
return err
}
return nil
}
func TestStudioQueryNameAndUrl(t *testing.T) {
const studioIdx = 1
studioName := getStudioStringValue(studioIdx, "Name")
@@ -107,9 +115,16 @@ func TestStudioQueryNameAndUrl(t *testing.T) {
studios := queryStudio(ctx, t, sqb, &studioFilter, nil)
assert.Len(t, studios, 1)
if !assert.Len(t, studios, 1) {
return nil
}
if err := studios[0].LoadURLs(ctx, db.Studio); err != nil {
t.Errorf("Error loading studio relationships: %v", err)
}
assert.Equal(t, studioName, studios[0].Name)
assert.Equal(t, studioUrl, studios[0].URL)
assert.Equal(t, []string{studioUrl}, studios[0].URLs.List())
return nil
})
@@ -145,9 +160,13 @@ func TestStudioQueryNameNotUrl(t *testing.T) {
studios := queryStudio(ctx, t, sqb, &studioFilter, nil)
for _, studio := range studios {
if err := studio.LoadURLs(ctx, db.Studio); err != nil {
t.Errorf("Error loading studio relationships: %v", err)
}
verifyString(t, studio.Name, nameCriterion)
urlCriterion.Modifier = models.CriterionModifierNotEquals
verifyString(t, studio.URL, urlCriterion)
verifyStringList(t, studio.URLs.List(), urlCriterion)
}
return nil
@@ -659,7 +678,11 @@ func TestStudioQueryURL(t *testing.T) {
verifyFn := func(ctx context.Context, g *models.Studio) {
t.Helper()
verifyString(t, g.URL, urlCriterion)
if err := g.LoadURLs(ctx, db.Studio); err != nil {
t.Errorf("Error loading studio relationships: %v", err)
return
}
verifyStringList(t, g.URLs.List(), urlCriterion)
}
verifyStudioQuery(t, filter, verifyFn)

View File

@@ -37,6 +37,7 @@ var (
performersCustomFieldsTable = goqu.T("performer_custom_fields")
studiosAliasesJoinTable = goqu.T(studioAliasesTable)
studiosURLsJoinTable = goqu.T(studioURLsTable)
studiosTagsJoinTable = goqu.T(studiosTagsTable)
studiosStashIDsJoinTable = goqu.T("studio_stash_ids")
@@ -319,6 +320,14 @@ var (
stringColumn: studiosAliasesJoinTable.Col(studioAliasColumn),
}
studiosURLsTableMgr = &orderedValueTable[string]{
table: table{
table: studiosURLsJoinTable,
idColumn: studiosURLsJoinTable.Col(studioIDColumn),
},
valueColumn: studiosURLsJoinTable.Col(studioURLColumn),
}
studiosTagsTableMgr = &joinTable{
table: table{
table: studiosTagsJoinTable,

View File

@@ -65,11 +65,14 @@ func studioFragmentToScrapedStudio(s graphql.StudioFragment) *models.ScrapedStud
st := &models.ScrapedStudio{
Name: s.Name,
URL: findURL(s.Urls, "HOME"),
Images: images,
RemoteSiteID: &s.ID,
}
for _, u := range s.Urls {
st.URLs = append(st.URLs, u.URL)
}
if len(st.Images) > 0 {
st.Image = &st.Images[0]
}

View File

@@ -14,6 +14,7 @@ import (
type FinderImageStashIDGetter interface {
models.StudioGetter
models.AliasLoader
models.URLLoader
models.StashIDLoader
GetImage(ctx context.Context, studioID int) ([]byte, error)
}
@@ -22,7 +23,6 @@ type FinderImageStashIDGetter interface {
func ToJSON(ctx context.Context, reader FinderImageStashIDGetter, studio *models.Studio) (*jsonschema.Studio, error) {
newStudioJSON := jsonschema.Studio{
Name: studio.Name,
URL: studio.URL,
Details: studio.Details,
Favorite: studio.Favorite,
IgnoreAutoTag: studio.IgnoreAutoTag,
@@ -50,6 +50,11 @@ func ToJSON(ctx context.Context, reader FinderImageStashIDGetter, studio *models
}
newStudioJSON.Aliases = studio.Aliases.List()
if err := studio.LoadURLs(ctx, reader); err != nil {
return nil, fmt.Errorf("loading studio URLs: %w", err)
}
newStudioJSON.URLs = studio.URLs.List()
if err := studio.LoadStashIDs(ctx, reader); err != nil {
return nil, fmt.Errorf("loading studio stash ids: %w", err)
}

View File

@@ -60,7 +60,7 @@ func createFullStudio(id int, parentID int) models.Studio {
ret := models.Studio{
ID: id,
Name: studioName,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Details: details,
Favorite: true,
CreatedAt: createTime,
@@ -84,6 +84,7 @@ func createEmptyStudio(id int) models.Studio {
ID: id,
CreatedAt: createTime,
UpdatedAt: updateTime,
URLs: models.NewRelatedStrings([]string{}),
Aliases: models.NewRelatedStrings([]string{}),
TagIDs: models.NewRelatedIDs([]int{}),
StashIDs: models.NewRelatedStashIDs([]models.StashID{}),
@@ -93,7 +94,7 @@ func createEmptyStudio(id int) models.Studio {
func createFullJSONStudio(parentStudio, image string, aliases []string) *jsonschema.Studio {
return &jsonschema.Studio{
Name: studioName,
URL: url,
URLs: []string{url},
Details: details,
Favorite: true,
CreatedAt: json.JSONTime{
@@ -120,6 +121,7 @@ func createEmptyJSONStudio() *jsonschema.Studio {
Time: updateTime,
},
Aliases: []string{},
URLs: []string{},
StashIDs: []models.StashID{},
}
}

View File

@@ -217,7 +217,6 @@ func (i *Importer) Update(ctx context.Context, id int) error {
func studioJSONtoStudio(studioJSON jsonschema.Studio) models.Studio {
newStudio := models.Studio{
Name: studioJSON.Name,
URL: studioJSON.URL,
Aliases: models.NewRelatedStrings(studioJSON.Aliases),
Details: studioJSON.Details,
Favorite: studioJSON.Favorite,
@@ -229,6 +228,19 @@ func studioJSONtoStudio(studioJSON jsonschema.Studio) models.Studio {
StashIDs: models.NewRelatedStashIDs(studioJSON.StashIDs),
}
if len(studioJSON.URLs) > 0 {
newStudio.URLs = models.NewRelatedStrings(studioJSON.URLs)
} else {
urls := []string{}
if studioJSON.URL != "" {
urls = append(urls, studioJSON.URL)
}
if len(urls) > 0 {
newStudio.URLs = models.NewRelatedStrings(urls)
}
}
if studioJSON.Rating != 0 {
newStudio.Rating = &studioJSON.Rating
}