Verify mention: Check if URL is present and if it is present, check if it is correct

Also add option to reverify a mention
This commit is contained in:
Jan-Lukas Else 2021-05-23 20:11:48 +02:00
parent 93849d289b
commit deb3189673
6 changed files with 59 additions and 11 deletions

View File

@ -205,6 +205,7 @@ func buildStaticHandlersRouters() error {
r.Get(paginationPath, webmentionAdmin) r.Get(paginationPath, webmentionAdmin)
r.Post("/delete", webmentionAdminDelete) r.Post("/delete", webmentionAdminDelete)
r.Post("/approve", webmentionAdminApprove) r.Post("/approve", webmentionAdminApprove)
r.Post("/reverify", webmentionAdminReverify)
}) })
} }

View File

@ -34,6 +34,7 @@ posts: "Posts"
prev: "Previous" prev: "Previous"
publishedon: "Published on" publishedon: "Published on"
replyto: "Reply to" replyto: "Reply to"
reverify: "Reverify"
scopes: "Scopes" scopes: "Scopes"
search: "Search" search: "Search"
send: "Send (to review)" send: "Send (to review)"

View File

@ -19,6 +19,7 @@
<input type="submit" formaction="/webmention/approve" value="{{ string $blog.Lang "approve" }}"> <input type="submit" formaction="/webmention/approve" value="{{ string $blog.Lang "approve" }}">
{{ end }} {{ end }}
<input type="submit" formaction="/webmention/delete" value="{{ string $blog.Lang "delete" }}"> <input type="submit" formaction="/webmention/delete" value="{{ string $blog.Lang "delete" }}">
<input type="submit" formaction="/webmention/reverify" value="{{ string $blog.Lang "reverify" }}">
</form> </form>
</div> </div>
{{ end }} {{ end }}

View File

@ -112,9 +112,24 @@ func approveWebmention(id int) error {
return err return err
} }
func reverifyWebmention(id int) error {
m, err := getWebmentions(&webmentionsRequestConfig{
id: id,
limit: 1,
})
if err != nil {
return err
}
if len(m) > 0 {
queueMention(m[0])
}
return nil
}
type webmentionsRequestConfig struct { type webmentionsRequestConfig struct {
target string target string
status webmentionStatus status webmentionStatus
id int
asc bool asc bool
offset, limit int offset, limit int
} }
@ -132,6 +147,9 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
} else if config.status != "" { } else if config.status != "" {
filter = "where status = @status" filter = "where status = @status"
args = append(args, sql.Named("status", config.status)) args = append(args, sql.Named("status", config.status))
} else if config.id != 0 {
filter = "where id = @id"
args = append(args, sql.Named("id", config.id))
} }
} }
order := "desc" order := "desc"

View File

@ -124,3 +124,17 @@ func webmentionAdminApprove(w http.ResponseWriter, r *http.Request) {
purgeCache() purgeCache()
http.Redirect(w, r, ".", http.StatusFound) http.Redirect(w, r, ".", http.StatusFound)
} }
func webmentionAdminReverify(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.FormValue("mentionid"))
if err != nil {
serveError(w, r, err.Error(), http.StatusBadRequest)
return
}
err = reverifyWebmention(id)
if err != nil {
serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, ".", http.StatusFound)
}

View File

@ -155,29 +155,42 @@ func (m *mention) fillFromData(mf *microformats.Data) {
func (m *mention) fill(mf *microformats.Microformat) bool { func (m *mention) fill(mf *microformats.Microformat) bool {
if mfHasType(mf, "h-entry") { if mfHasType(mf, "h-entry") {
if name, ok := mf.Properties["name"]; ok && len(name) > 0 { // Check URL
if title, ok := name[0].(string); ok { if url, ok := mf.Properties["url"]; ok && len(url) > 0 {
m.Title = title if url0, ok := url[0].(string); ok {
} if url0 != m.Source {
} // Not correct URL
if contents, ok := mf.Properties["content"]; ok && len(contents) > 0 { return false
if content, ok := contents[0].(map[string]string); ok {
if contentValue, ok := content["value"]; ok {
m.Content = contentValue
} }
} }
} }
// Title
if name, ok := mf.Properties["name"]; ok && len(name) > 0 {
if title, ok := name[0].(string); ok {
m.Title = strings.TrimSpace(title)
}
}
// Content
if contents, ok := mf.Properties["content"]; ok && len(contents) > 0 {
if content, ok := contents[0].(map[string]string); ok {
if contentValue, ok := content["value"]; ok {
m.Content = strings.TrimSpace(contentValue)
}
}
}
// Author
if authors, ok := mf.Properties["author"]; ok && len(authors) > 0 { if authors, ok := mf.Properties["author"]; ok && len(authors) > 0 {
if author, ok := authors[0].(*microformats.Microformat); ok { if author, ok := authors[0].(*microformats.Microformat); ok {
if names, ok := author.Properties["name"]; ok && len(names) > 0 { if names, ok := author.Properties["name"]; ok && len(names) > 0 {
if name, ok := names[0].(string); ok { if name, ok := names[0].(string); ok {
m.Author = name m.Author = strings.TrimSpace(name)
} }
} }
} }
} }
return true return true
} else if len(mf.Children) > 0 { }
if len(mf.Children) > 0 {
for _, mfc := range mf.Children { for _, mfc := range mf.Children {
if m.fill(mfc) { if m.fill(mfc) {
return true return true