mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Query url parameters (#878)
This commit is contained in:
51
pkg/scraper/query_url.go
Normal file
51
pkg/scraper/query_url.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package scraper
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type queryURLReplacements map[string]mappedRegexConfigs
|
||||
|
||||
type queryURLParameters map[string]string
|
||||
|
||||
func queryURLParametersFromScene(scene *models.Scene) queryURLParameters {
|
||||
ret := make(queryURLParameters)
|
||||
ret["checksum"] = scene.Checksum.String
|
||||
ret["oshash"] = scene.OSHash.String
|
||||
ret["filename"] = filepath.Base(scene.Path)
|
||||
ret["title"] = scene.Title.String
|
||||
return ret
|
||||
}
|
||||
|
||||
func queryURLParametersFromGallery(gallery *models.Gallery) queryURLParameters {
|
||||
ret := make(queryURLParameters)
|
||||
ret["checksum"] = gallery.Checksum
|
||||
|
||||
if gallery.Path.Valid {
|
||||
ret["filename"] = filepath.Base(gallery.Path.String)
|
||||
}
|
||||
ret["title"] = gallery.Title.String
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p queryURLParameters) applyReplacements(r queryURLReplacements) {
|
||||
for k, v := range p {
|
||||
rpl, found := r[k]
|
||||
if found {
|
||||
p[k] = rpl.apply(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p queryURLParameters) constructURL(url string) string {
|
||||
ret := url
|
||||
for k, v := range p {
|
||||
ret = strings.Replace(ret, "{"+k+"}", v, -1)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user