Improve webmentions

This commit is contained in:
Jan-Lukas Else 2020-11-17 20:01:02 +01:00
parent fc6c883eca
commit eed86794ff
4 changed files with 14 additions and 6 deletions

View File

@ -12,7 +12,7 @@
{{ else }}
{{ $mention.Source }}
{{ end }}
</a>{{ with $mention.Title }} <i>{{.}}</i>{{ end }}</li>
</a>{{ with $mention.Title }} <b>{{.}}</b>{{ end }}{{ with $mention.Content }} <i>{{.}}</i>{{ end }}</li>
{{ end }}
</ul>
{{ end }}

View File

@ -101,6 +101,14 @@ func resolveURLReferences(base string, refs ...string) ([]string, error) {
return urls, nil
}
func unescapedPath(p string) string {
u, err := url.PathUnescape(p)
if err != nil {
return p
}
return u
}
func slashIfEmpty(s string) string {
if s == "" {
return "/"

View File

@ -128,7 +128,7 @@ func webmentionAdminApprove(w http.ResponseWriter, r *http.Request) {
func webmentionExists(source, target string) bool {
result := 0
row, err := appDbQueryRow("select exists(select 1 from webmentions where source = ? and target = ?)", source, target)
row, err := appDbQueryRow("select exists(select 1 from webmentions where source = ? and target = ?)", source, unescapedPath(target))
if err != nil {
return false
}
@ -140,9 +140,9 @@ func webmentionExists(source, target string) bool {
func createWebmention(source, target string) (err error) {
if webmentionExists(source, target) {
_, err = appDbExec("update webmentions set status = ? where source = ? and target = ?", webmentionStatusRenew, source, target)
_, err = appDbExec("update webmentions set status = ? where source = ? and target = ?", webmentionStatusRenew, source, unescapedPath(target))
} else {
_, err = appDbExec("insert into webmentions (source, target, created) values (?, ?, ?)", source, target, time.Now().Unix())
_, err = appDbExec("insert into webmentions (source, target, created) values (?, ?, ?)", source, unescapedPath(target), time.Now().Unix())
}
return err
}
@ -172,7 +172,7 @@ func getWebmentions(config *webmentionsRequestConfig) ([]*mention, error) {
if config != nil {
if config.target != "" && config.status != "" {
filter = "where target = @target and status = @status"
args = append(args, sql.Named("target", config.target), sql.Named("status", config.status))
args = append(args, sql.Named("target", unescapedPath(config.target)), sql.Named("status", config.status))
} else if config.target != "" {
filter = "where target = @target"
args = append(args, sql.Named("target", config.target))

View File

@ -79,7 +79,7 @@ func wmVerifyReader(body io.Reader, m *mention) error {
}
hasLink := false
for _, link := range links {
if link == m.Target {
if unescapedPath(link) == unescapedPath(m.Target) {
hasLink = true
break
}