This commit is contained in:
NativeRavenclaw 2026-05-05 08:03:26 -05:00 committed by GitHub
commit 7483da6aef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 24 deletions

View file

@ -205,6 +205,52 @@ func galleryInputFromGallery(gallery *models.Gallery) galleryInput {
return ret
}
type imageInput struct {
ID string `json:"id"`
Title string `json:"title"`
Urls []string `json:"urls"`
Date *string `json:"date"`
Details string `json:"details"`
Code string `json:"code,omitempty"`
Photographer string `json:"photographer,omitempty"`
Files []fileInput `json:"files,omitempty"`
}
func imageInputFromImage(image *models.Image) imageInput {
dateToStringPtr := func(s *models.Date) *string {
if s != nil {
v := s.String()
return &v
}
return nil
}
// fallback to file basename if title is empty
title := image.GetTitle()
urls := image.URLs.List()
ret := imageInput{
ID: strconv.Itoa(image.ID),
Title: title,
Urls: urls,
Details: image.Details,
Date: dateToStringPtr(image.Date),
Code: image.Code,
Photographer: image.Photographer,
}
for _, f := range image.Files.List() {
fi := fileInputFromFile(*f.Base())
ret.Files = append(ret.Files, fi)
}
return ret
}
var ErrScraperScript = errors.New("scraper script error")
type scriptScraper struct {
@ -392,6 +438,9 @@ func (s *scriptFragmentScraper) scrapeByFragment(ctx context.Context, input Inpu
case input.Scene != nil:
inString, err = json.Marshal(*input.Scene)
ty = ScrapeContentTypeScene
case input.Image != nil:
inString, err = json.Marshal(*input.Image)
ty = ScrapeContentTypeImage
}
if err != nil {
@ -430,7 +479,7 @@ func (s *scriptFragmentScraper) scrapeGalleryByGallery(ctx context.Context, gall
}
func (s *scriptFragmentScraper) scrapeImageByImage(ctx context.Context, image *models.Image) (*models.ScrapedImage, error) {
inString, err := json.Marshal(imageToUpdateInput(image))
inString, err := json.Marshal(imageInputFromImage(image))
if err != nil {
return nil, err

View file

@ -438,26 +438,3 @@ func (s *stashScraper) scrapeImageByImage(ctx context.Context, image *models.Ima
func (s *stashScraper) scrapeByURL(_ context.Context, _ string, _ ScrapeContentType) (ScrapedContent, error) {
return nil, ErrNotSupported
}
func imageToUpdateInput(gallery *models.Image) models.ImageUpdateInput {
dateToStringPtr := func(s *models.Date) *string {
if s != nil {
v := s.String()
return &v
}
return nil
}
// fallback to file basename if title is empty
title := gallery.GetTitle()
urls := gallery.URLs.List()
return models.ImageUpdateInput{
ID: strconv.Itoa(gallery.ID),
Title: &title,
Details: &gallery.Details,
Urls: urls,
Date: dateToStringPtr(gallery.Date),
}
}