forked from wgroeneveld/go-jamming
if no picture found in microformat data, revert to anonymous pic
This commit is contained in:
parent
c5dcb45de9
commit
1f38a42c77
|
@ -36,7 +36,7 @@ type IndiewebAuthor struct {
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ia *IndiewebAuthor) Anonymize() {
|
func (ia *IndiewebAuthor) AnonymizePicture() {
|
||||||
ia.Picture = fmt.Sprintf("/pictures/%s", Anonymous)
|
ia.Picture = fmt.Sprintf("/pictures/%s", Anonymous)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,17 +57,7 @@ func (recv *Receiver) processSourceBody(body string, wm mf.Mention) {
|
||||||
|
|
||||||
data := microformats.Parse(strings.NewReader(body), wm.SourceUrl())
|
data := microformats.Parse(strings.NewReader(body), wm.SourceUrl())
|
||||||
indieweb := recv.convertBodyToIndiewebData(body, wm, data)
|
indieweb := recv.convertBodyToIndiewebData(body, wm, data)
|
||||||
if indieweb.Author.Picture != "" {
|
recv.processAuthorPicture(indieweb)
|
||||||
err := recv.saveAuthorPictureLocally(indieweb)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Str("url", indieweb.Author.Picture).Msg("Failed to save picture. Reverting to anonymous")
|
|
||||||
indieweb.Author.Anonymize()
|
|
||||||
|
|
||||||
if err == errWontDownloadBecauseOfPrivacy {
|
|
||||||
indieweb.Author.AnonymizeName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := recv.Repo.Save(wm, indieweb)
|
key, err := recv.Repo.Save(wm, indieweb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -76,6 +66,22 @@ func (recv *Receiver) processSourceBody(body string, wm mf.Mention) {
|
||||||
log.Info().Str("key", key).Msg("OK: Webmention processed.")
|
log.Info().Str("key", key).Msg("OK: Webmention processed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (recv *Receiver) processAuthorPicture(indieweb *mf.IndiewebData) {
|
||||||
|
if indieweb.Author.Picture != "" {
|
||||||
|
err := recv.saveAuthorPictureLocally(indieweb)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Str("url", indieweb.Author.Picture).Msg("Failed to save picture. Reverting to anonymous")
|
||||||
|
indieweb.Author.AnonymizePicture()
|
||||||
|
|
||||||
|
if err == errWontDownloadBecauseOfPrivacy {
|
||||||
|
indieweb.Author.AnonymizeName()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
indieweb.Author.AnonymizePicture()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (recv *Receiver) convertBodyToIndiewebData(body string, wm mf.Mention, mfRoot *microformats.Data) *mf.IndiewebData {
|
func (recv *Receiver) convertBodyToIndiewebData(body string, wm mf.Mention, mfRoot *microformats.Data) *mf.IndiewebData {
|
||||||
hEntry := mf.HEntry(mfRoot)
|
hEntry := mf.HEntry(mfRoot)
|
||||||
hCard := mf.HCard(mfRoot)
|
hCard := mf.HCard(mfRoot)
|
||||||
|
|
|
@ -174,7 +174,7 @@ func TestReceive(t *testing.T) {
|
||||||
Source: "https://brainbaking.com/valid-nonindieweb-source.html",
|
Source: "https://brainbaking.com/valid-nonindieweb-source.html",
|
||||||
Target: "https://brainbaking.com/valid-indieweb-target.html",
|
Target: "https://brainbaking.com/valid-indieweb-target.html",
|
||||||
},
|
},
|
||||||
json: `{"author":{"name":"https://brainbaking.com/valid-nonindieweb-source.html", "picture":""}, "content":"Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", "name":"Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", "published":"2020-01-01T12:30:00+00:00", "source":"https://brainbaking.com/valid-nonindieweb-source.html", "target":"https://brainbaking.com/valid-indieweb-target.html", "type":"mention", "url":"https://brainbaking.com/valid-nonindieweb-source.html"}`,
|
json: `{"author":{"name":"https://brainbaking.com/valid-nonindieweb-source.html", "picture":"/pictures/anonymous"}, "content":"Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", "name":"Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", "published":"2020-01-01T12:30:00+00:00", "source":"https://brainbaking.com/valid-nonindieweb-source.html", "target":"https://brainbaking.com/valid-indieweb-target.html", "type":"mention", "url":"https://brainbaking.com/valid-nonindieweb-source.html"}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ func TestProcessSourceBodyAnonymizesBothAuthorPictureAndNameIfComingFromSilo(t *
|
||||||
Target: "https://brainbaking.com/",
|
Target: "https://brainbaking.com/",
|
||||||
}
|
}
|
||||||
repo := db.NewMentionRepo(conf)
|
repo := db.NewMentionRepo(conf)
|
||||||
receiver := &Receiver{
|
recv := &Receiver{
|
||||||
Conf: conf,
|
Conf: conf,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ func TestProcessSourceBodyAnonymizesBothAuthorPictureAndNameIfComingFromSilo(t *
|
||||||
src, err := ioutil.ReadFile("../../../mocks/valid-bridgy-source.html")
|
src, err := ioutil.ReadFile("../../../mocks/valid-bridgy-source.html")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
receiver.processSourceBody(string(src), wm)
|
recv.processSourceBody(string(src), wm)
|
||||||
savedMention := repo.Get(wm)
|
savedMention := repo.Get(wm)
|
||||||
|
|
||||||
assert.Equal(t, "Anonymous", savedMention.Author.Name)
|
assert.Equal(t, "Anonymous", savedMention.Author.Name)
|
||||||
|
@ -275,11 +275,23 @@ func TestProcessSourceBodyAbortsIfNoMentionOfTargetFoundInSourceHtml(t *testing.
|
||||||
Target: "https://jefklakscodex.com/articles",
|
Target: "https://jefklakscodex.com/articles",
|
||||||
}
|
}
|
||||||
repo := db.NewMentionRepo(conf)
|
repo := db.NewMentionRepo(conf)
|
||||||
receiver := &Receiver{
|
recv := &Receiver{
|
||||||
Conf: conf,
|
Conf: conf,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
receiver.processSourceBody("<html>my nice body</html>", wm)
|
recv.processSourceBody("<html>my nice body</html>", wm)
|
||||||
assert.Empty(t, repo.Get(wm))
|
assert.Empty(t, repo.Get(wm))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessAuthorPictureAnonymizesIfEmpty(t *testing.T) {
|
||||||
|
recv := &Receiver{}
|
||||||
|
indieweb := &mf.IndiewebData{
|
||||||
|
Author: mf.IndiewebAuthor{
|
||||||
|
Picture: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
recv.processAuthorPicture(indieweb)
|
||||||
|
|
||||||
|
assert.Equal(t, "/pictures/anonymous", indieweb.Author.Picture)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue