mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 01:35:56 +01:00
Little hack to prevent webmentions overwriting
This commit is contained in:
parent
716e206938
commit
baa43bdb40
2 changed files with 25 additions and 3 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -13,7 +13,8 @@
|
||||||
"shortener",
|
"shortener",
|
||||||
"shorteners",
|
"shorteners",
|
||||||
"shortlink",
|
"shortlink",
|
||||||
"shortlinks"
|
"shortlinks",
|
||||||
|
"Webmention"
|
||||||
],
|
],
|
||||||
"cSpell.language": "en-GB"
|
"cSpell.language": "en-GB"
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -20,6 +21,10 @@ import (
|
||||||
const webmentions = "https://webmention.io/api/mentions.jf2?domain=%s&token=%s"
|
const webmentions = "https://webmention.io/api/mentions.jf2?domain=%s&token=%s"
|
||||||
const siteTarget = "https://www.byjp.me/"
|
const siteTarget = "https://www.byjp.me/"
|
||||||
|
|
||||||
|
var myURLs = []string{
|
||||||
|
"https://bsky.app/profile/byjp.me",
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Domain string
|
Domain string
|
||||||
Token string
|
Token string
|
||||||
|
@ -39,7 +44,7 @@ func main() {
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
// Proceed
|
// Proceed
|
||||||
case ErrNoEntry, ErrIsPrivate, ErrIncorrectTarget:
|
case ErrNoEntry, ErrIsPrivate, ErrIncorrectTarget, ErrIsMine:
|
||||||
// Skip
|
// Skip
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
|
@ -89,6 +94,14 @@ func addInteraction(jsonPath string, newIn synd.Interaction) error {
|
||||||
added := false
|
added := false
|
||||||
for idx, in := range inf.Interactions {
|
for idx, in := range inf.Interactions {
|
||||||
if in.GUID == newIn.GUID {
|
if in.GUID == newIn.GUID {
|
||||||
|
// A hack because webmentions.io can't process emoji properly currently
|
||||||
|
if strings.Contains(newIn.Author.Name, "????") {
|
||||||
|
newIn.Author.Name = in.Author.Name
|
||||||
|
}
|
||||||
|
if strings.Contains(newIn.Comment, "????") {
|
||||||
|
newIn.Comment = in.Comment
|
||||||
|
}
|
||||||
|
|
||||||
inf.Interactions[idx] = newIn
|
inf.Interactions[idx] = newIn
|
||||||
added = true
|
added = true
|
||||||
}
|
}
|
||||||
|
@ -115,6 +128,7 @@ func addInteraction(jsonPath string, newIn synd.Interaction) error {
|
||||||
var ErrNoEntry = errors.New("JF2 item isn't an entry")
|
var ErrNoEntry = errors.New("JF2 item isn't an entry")
|
||||||
var ErrIsPrivate = errors.New("JF2 item is set to private")
|
var ErrIsPrivate = errors.New("JF2 item is set to private")
|
||||||
var ErrIncorrectTarget = errors.New("JF2 item describes a different target site")
|
var ErrIncorrectTarget = errors.New("JF2 item describes a different target site")
|
||||||
|
var ErrIsMine = errors.New("JF2 item was created by the author")
|
||||||
|
|
||||||
func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interaction, error) {
|
func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interaction, error) {
|
||||||
if m.Type != "entry" {
|
if m.Type != "entry" {
|
||||||
|
@ -135,6 +149,14 @@ func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interactio
|
||||||
return "", synd.Interaction{}, ErrIncorrectTarget
|
return "", synd.Interaction{}, ErrIncorrectTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(sitePath) == 0 {
|
||||||
|
return "", synd.Interaction{}, ErrIncorrectTarget
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.Contains(myURLs, m.Author.URL) {
|
||||||
|
return "", synd.Interaction{}, ErrIsMine
|
||||||
|
}
|
||||||
|
|
||||||
i := synd.Interaction{
|
i := synd.Interaction{
|
||||||
GUID: fmt.Sprintf("webmentions.io#%d", m.WebmentionID),
|
GUID: fmt.Sprintf("webmentions.io#%d", m.WebmentionID),
|
||||||
URL: m.URL,
|
URL: m.URL,
|
||||||
|
@ -169,7 +191,6 @@ func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interactio
|
||||||
case "in-reply-to":
|
case "in-reply-to":
|
||||||
i.Emoji = "💬"
|
i.Emoji = "💬"
|
||||||
case "mention-of":
|
case "mention-of":
|
||||||
i.Comment = "_A wibble_"
|
|
||||||
i.Emoji = "🗣️"
|
i.Emoji = "🗣️"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue