Include old URL in script input (#3940)

* Include old URL in script input
* Include URL in update input
This commit is contained in:
WithoutPants
2023-07-26 12:59:16 +10:00
committed by GitHub
parent df70b182a4
commit 4b07c5b60b
3 changed files with 21 additions and 2 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -324,11 +324,19 @@ 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(),
// include deprecated URL for now
URL: url,
Urls: urls,
Date: dateToStringPtr(scene.Date),
}
}