mirror of https://github.com/jlelse/GoBlog
Fix webmention verification
This commit is contained in:
parent
4c5e77dcab
commit
597dc35470
|
@ -86,7 +86,7 @@ func extractMention(r *http.Request) (*mention, error) {
|
||||||
|
|
||||||
func (db *database) webmentionExists(source, target string) bool {
|
func (db *database) webmentionExists(source, target string) bool {
|
||||||
result := 0
|
result := 0
|
||||||
row, err := db.queryRow("select exists(select 1 from webmentions where source = ? and target = ?)", source, target)
|
row, err := db.queryRow("select exists(select 1 from webmentions where lower(source) = lower(@source) and lower(target) = lower(@target))", sql.Named("source", source), sql.Named("target", target))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
|
||||||
if config != nil {
|
if config != nil {
|
||||||
filter = "where 1 = 1"
|
filter = "where 1 = 1"
|
||||||
if config.target != "" {
|
if config.target != "" {
|
||||||
filter += " and target = @target"
|
filter += " and lower(target) = lower(@target)"
|
||||||
args = append(args, sql.Named("target", config.target))
|
args = append(args, sql.Named("target", config.target))
|
||||||
}
|
}
|
||||||
if config.status != "" {
|
if config.status != "" {
|
||||||
|
@ -151,8 +151,8 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
|
||||||
args = append(args, sql.Named("status", config.status))
|
args = append(args, sql.Named("status", config.status))
|
||||||
}
|
}
|
||||||
if config.sourcelike != "" {
|
if config.sourcelike != "" {
|
||||||
filter += " and source like @sourcelike"
|
filter += " and lower(source) like @sourcelike"
|
||||||
args = append(args, sql.Named("sourcelike", "%"+config.sourcelike+"%"))
|
args = append(args, sql.Named("sourcelike", "%"+strings.ToLower(config.sourcelike)+"%"))
|
||||||
}
|
}
|
||||||
if config.id != 0 {
|
if config.id != 0 {
|
||||||
filter += " and id = @id"
|
filter += " and id = @id"
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (a *goBlog) verifyMention(m *mention) error {
|
||||||
}
|
}
|
||||||
newStatus := webmentionStatusVerified
|
newStatus := webmentionStatusVerified
|
||||||
if a.db.webmentionExists(m.Source, m.Target) {
|
if a.db.webmentionExists(m.Source, m.Target) {
|
||||||
_, err = a.db.exec("update webmentions set status = @status, title = @title, content = @content, author = @author where source = @source and target = @target",
|
_, err = a.db.exec("update webmentions set status = @status, title = @title, content = @content, author = @author where lower(source) = lower(@source) and lower(target) = lower(@target)",
|
||||||
sql.Named("status", newStatus), sql.Named("title", m.Title), sql.Named("content", m.Content), sql.Named("author", m.Author), sql.Named("source", m.Source), sql.Named("target", m.Target))
|
sql.Named("status", newStatus), sql.Named("title", m.Title), sql.Named("content", m.Content), sql.Named("author", m.Author), sql.Named("source", m.Source), sql.Named("target", m.Target))
|
||||||
} else {
|
} else {
|
||||||
_, err = a.db.exec("insert into webmentions (source, target, created, status, title, content, author) values (@source, @target, @created, @status, @title, @content, @author)",
|
_, err = a.db.exec("insert into webmentions (source, target, created, status, title, content, author) values (@source, @target, @created, @status, @title, @content, @author)",
|
||||||
|
@ -156,7 +156,7 @@ func (m *mention) fill(mf *microformats.Microformat) bool {
|
||||||
// Check URL
|
// Check URL
|
||||||
if url, ok := mf.Properties["url"]; ok && len(url) > 0 {
|
if url, ok := mf.Properties["url"]; ok && len(url) > 0 {
|
||||||
if url0, ok := url[0].(string); ok {
|
if url0, ok := url[0].(string); ok {
|
||||||
if url0 != m.Source {
|
if strings.ToLower(url0) != strings.ToLower(m.Source) {
|
||||||
// Not correct URL
|
// Not correct URL
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue