Performer urls (#4958)

* Populate URLs from legacy fields
* Return nil properly in xpath/json scrapers
* Improve migration logging
This commit is contained in:
WithoutPants
2024-06-18 13:41:05 +10:00
committed by GitHub
parent fda4776d30
commit f26766033e
47 changed files with 992 additions and 379 deletions

15
pkg/utils/url.go Normal file
View File

@@ -0,0 +1,15 @@
package utils
import "regexp"
// URLFromHandle adds the site URL to the input if the input is not already a URL
// siteURL must not end with a slash
func URLFromHandle(input string, siteURL string) string {
// if the input is already a URL, return it
re := regexp.MustCompile(`^https?://`)
if re.MatchString(input) {
return input
}
return siteURL + "/" + input
}

47
pkg/utils/url_test.go Normal file
View File

@@ -0,0 +1,47 @@
package utils
import "testing"
func TestURLFromHandle(t *testing.T) {
type args struct {
input string
siteURL string
}
tests := []struct {
name string
args args
want string
}{
{
name: "input is already a URL https",
args: args{
input: "https://foo.com",
siteURL: "https://bar.com",
},
want: "https://foo.com",
},
{
name: "input is already a URL http",
args: args{
input: "http://foo.com",
siteURL: "https://bar.com",
},
want: "http://foo.com",
},
{
name: "input is not a URL",
args: args{
input: "foo",
siteURL: "https://foo.com",
},
want: "https://foo.com/foo",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := URLFromHandle(tt.args.input, tt.args.siteURL); got != tt.want {
t.Errorf("URLFromHandle() = %v, want %v", got, tt.want)
}
})
}
}