webmention-handler
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "webmention-handler", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A handler for web mentions", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -87,11 +87,14 @@ import { convertHEntryToMention } from "../functions/convert-h-entry-to-mention"; | ||
const {html, status, error} = await fetchHtml(mention.source); | ||
// Delete exisiting webmentions with the current source and target to avoid duplication | ||
await this.storageHandler.deleteMention(mention); | ||
// A status of 410 indicates that the webmention that previously existed was deleted | ||
// If we got an error or there was no html body, then the source is invalid and | ||
// we should delete any stored version of the webmention as per the specification | ||
if(error || !html || status === 410) return this.storageHandler.deleteMention(mention); | ||
// we should delete any stored version of the webmention as per the specification without | ||
// adding new ones | ||
if(error || !html || status === 410) return null; | ||
const hEntries = parseHtml(html, mention.source, mention.target); | ||
let mentionedUrls = hEntries.find(({type}) => type && type.includes("mention-of")); | ||
// If the page does not include any mention of the target, then delete any previously | ||
// acknowledged mentions and retun null; | ||
if(!mentionedUrls) return this.storageHandler.deleteMention(mention); | ||
// If the page does not include any mention of the target, then we can return | ||
// early as we have already deleted any stored mentions with this target and source | ||
if(!mentionedUrls) return null; | ||
@@ -98,0 +101,0 @@ let mentions = hEntries.map(h => convertHEntryToMention(h, mention.source, mention.target)); |
94304
1060