wmio import: in case of silo domains, use url instead of src
This commit is contained in:
parent
989495a18e
commit
6503037098
|
@ -3,6 +3,7 @@ package external
|
||||||
import (
|
import (
|
||||||
"brainbaking.com/go-jamming/app/mf"
|
"brainbaking.com/go-jamming/app/mf"
|
||||||
"brainbaking.com/go-jamming/common"
|
"brainbaking.com/go-jamming/common"
|
||||||
|
"brainbaking.com/go-jamming/rest"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,12 +100,23 @@ func convert(wmio WebmentionIOMention) *mf.IndiewebData {
|
||||||
Content: contentOf(wmio, iType),
|
Content: contentOf(wmio, iType),
|
||||||
Published: publishedDate(wmio),
|
Published: publishedDate(wmio),
|
||||||
Url: wmio.Data.Url,
|
Url: wmio.Data.Url,
|
||||||
Source: wmio.Source,
|
Source: sourceOf(wmio),
|
||||||
Target: wmio.Target,
|
Target: wmio.Target,
|
||||||
IndiewebType: iType,
|
IndiewebType: iType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sourceOf returns wmio.Source unless it detects a silo link such as bridgy.
|
||||||
|
// In that case, it returns the data URL. This isn't entirely correct, as it technically never was the sender.
|
||||||
|
func sourceOf(wmio WebmentionIOMention) string {
|
||||||
|
srcDomain := rest.Domain(wmio.Source)
|
||||||
|
if common.Includes(rest.SiloDomains, srcDomain) {
|
||||||
|
return wmio.Data.Url
|
||||||
|
}
|
||||||
|
|
||||||
|
return wmio.Source
|
||||||
|
}
|
||||||
|
|
||||||
func nameOf(wmio WebmentionIOMention, iType mf.MfType) string {
|
func nameOf(wmio WebmentionIOMention, iType mf.MfType) string {
|
||||||
if (iType == mf.TypeReply || iType == mf.TypeLike) && wmio.Data.Name == "" {
|
if (iType == mf.TypeReply || iType == mf.TypeLike) && wmio.Data.Name == "" {
|
||||||
return wmio.Data.Content
|
return wmio.Data.Content
|
||||||
|
|
|
@ -7,6 +7,40 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestTryImportBridgyUrl(t *testing.T) {
|
||||||
|
wmio := &WebmentionIOImporter{}
|
||||||
|
cases := []struct {
|
||||||
|
label string
|
||||||
|
mention string
|
||||||
|
expectedSource string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"conventional source URL does nothing special",
|
||||||
|
`{ "links": [ { "source": "https://brainbaking.com/lolz" } ] }`,
|
||||||
|
"https://brainbaking.com/lolz",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Source URL from brid.gy takes data URL as source instead",
|
||||||
|
`{ "links": [ { "source": "https://brid.gy/like/twitter/iamchrisburnell/1298550501307486208/252048752", "data": { "url": "https://twitter.com/iamchrisburnell/status/1298550501307486208#favorited-by-252048752" } } ] }`,
|
||||||
|
"https://twitter.com/iamchrisburnell/status/1298550501307486208#favorited-by-252048752",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Source URL from brid-gy.appspot.com takes URL as data source instead",
|
||||||
|
`{ "links": [ { "source": "https://brid-gy.appspot.com/post/twitter/iamchrisburnell/1103728693648809984", "data": { "url": "https://twitter.com/adactioLinks/status/1103728693648809984" } } ] }`,
|
||||||
|
"https://twitter.com/adactioLinks/status/1103728693648809984",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.label, func(t *testing.T) {
|
||||||
|
res, err := wmio.TryImport([]byte(tc.mention))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, tc.expectedSource, res[0].Source)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTryImportPublishedDates(t *testing.T) {
|
func TestTryImportPublishedDates(t *testing.T) {
|
||||||
wmio := &WebmentionIOImporter{}
|
wmio := &WebmentionIOImporter{}
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
|
|
|
@ -61,6 +61,7 @@ var (
|
||||||
// These are privacy issues and will be anonymized as such.
|
// These are privacy issues and will be anonymized as such.
|
||||||
SiloDomains = []string{
|
SiloDomains = []string{
|
||||||
"brid.gy",
|
"brid.gy",
|
||||||
|
"brid-gy.appspot.com",
|
||||||
"twitter.com",
|
"twitter.com",
|
||||||
"facebook.com",
|
"facebook.com",
|
||||||
"indieweb.social",
|
"indieweb.social",
|
||||||
|
|
Loading…
Reference in New Issue