From 4b07c5b60bcedb319353e5ed3126f8b951d2f9c7 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:59:16 +1000 Subject: [PATCH] Include old URL in script input (#3940) * Include old URL in script input * Include URL in update input --- pkg/scraper/cache.go | 3 +++ pkg/scraper/scraper.go | 8 ++++++++ pkg/scraper/stash.go | 12 ++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/scraper/cache.go b/pkg/scraper/cache.go index 81607cd44..d526ecb0a 100644 --- a/pkg/scraper/cache.go +++ b/pkg/scraper/cache.go @@ -262,6 +262,9 @@ func (c Cache) ScrapeName(ctx context.Context, id, query string, ty ScrapeConten // ScrapeFragment uses the given fragment input to scrape func (c Cache) ScrapeFragment(ctx context.Context, id string, input Input) (ScrapedContent, error) { + // set the deprecated URL field if it's not set + input.populateURL() + s := c.findScraper(id) if s == nil { return nil, fmt.Errorf("%w: id %s", ErrNotFound, id) diff --git a/pkg/scraper/scraper.go b/pkg/scraper/scraper.go index 67569c18b..23ad411bd 100644 --- a/pkg/scraper/scraper.go +++ b/pkg/scraper/scraper.go @@ -157,6 +157,14 @@ type Input struct { Gallery *ScrapedGalleryInput } +// populateURL populates the URL field of the input based on the +// URLs field of the input. Does nothing if the URL field is already set. +func (i *Input) populateURL() { + if i.Scene != nil && i.Scene.URL == nil && len(i.Scene.URLs) > 0 { + i.Scene.URL = &i.Scene.URLs[0] + } +} + // simple type definitions that can help customize // actions per query type QueryType int diff --git a/pkg/scraper/stash.go b/pkg/scraper/stash.go index f616789c4..da204f347 100644 --- a/pkg/scraper/stash.go +++ b/pkg/scraper/stash.go @@ -324,12 +324,20 @@ func sceneToUpdateInput(scene *models.Scene) models.SceneUpdateInput { // fallback to file basename if title is empty title := scene.GetTitle() + var url *string + urls := scene.URLs.List() + if len(urls) > 0 { + url = &urls[0] + } + return models.SceneUpdateInput{ ID: strconv.Itoa(scene.ID), Title: &title, Details: &scene.Details, - Urls: scene.URLs.List(), - Date: dateToStringPtr(scene.Date), + // include deprecated URL for now + URL: url, + Urls: urls, + Date: dateToStringPtr(scene.Date), } }