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.Post("/delete", webmentionAdminDelete)
r.Post("/approve", webmentionAdminApprove)
r.Post("/reverify", webmentionAdminReverify)
})
}

View File

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

View File

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

View File

@ -112,9 +112,24 @@ func approveWebmention(id int) error {
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 {
target string
status webmentionStatus
id int
asc bool
offset, limit int
}
@ -132,6 +147,9 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
} else if config.status != "" {
filter = "where status = @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"

View File

@ -124,3 +124,17 @@ func webmentionAdminApprove(w http.ResponseWriter, r *http.Request) {
purgeCache()
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 {
if mfHasType(mf, "h-entry") {
if name, ok := mf.Properties["name"]; ok && len(name) > 0 {
if title, ok := name[0].(string); ok {
m.Title = title
}
}
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 = contentValue
// Check URL
if url, ok := mf.Properties["url"]; ok && len(url) > 0 {
if url0, ok := url[0].(string); ok {
if url0 != m.Source {
// Not correct URL
return false
}
}
}
// 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 author, ok := authors[0].(*microformats.Microformat); ok {
if names, ok := author.Properties["name"]; ok && len(names) > 0 {
if name, ok := names[0].(string); ok {
m.Author = name
m.Author = strings.TrimSpace(name)
}
}
}
}
return true
} else if len(mf.Children) > 0 {
}
if len(mf.Children) > 0 {
for _, mfc := range mf.Children {
if m.fill(mfc) {
return true