Skip to content

Instantly share code, notes, and snippets.

@barryf
Created May 14, 2021 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryf/ae4fbfd018cf11334ef120dcfd5cab41 to your computer and use it in GitHub Desktop.
Save barryf/ae4fbfd018cf11334ef120dcfd5cab41 to your computer and use it in GitHub Desktop.
Webmention receiver notes

Layout

  • http
    • post-webmention :source, :target
      • Return 400 if source and target are not valid URLs
      • Return 400 if source is the same as target
      • Return 400 if target is not a known domain
      • Return 400 if source’s domain is found in blocks table
      • Create random ID to represent webmention
      • Put id, source, target, created_at in webmentions table
      • Put id, webmention_id, created_at, description in statuses table
      • Publish to queues/verify (webmention_id)
      • Return 201 with Location header /webmention/:webmention_id
    • get-webmention :webmention_id
      • Return 400 if webmention_id is not correct format
      • Get status records for webmention_id from statuses table
      • Return 200 with HTML or JSON depending on header
  • queues
    • verify (webmention_id)
      • Get the webmention record
      • Head request on source
        • Put status and abort if Content-Type is not valid or length > 1Mb
      • Fetch the source, following any redirects (limiting to 20 redirects, 5 sec timeout)
        • Put status and abort if there is no mention of the target
          • HTML: look for href or src attributes
          • JSON: look for exact values
          • Text: look for string
        • Return 500 if response is an error
      • Put new status record
      • Publish to queues/parse (webmention_id)
    • parse (webmention_id)
      • Get the webmention record
      • Send source to Granary to parse into MF2
      • Sanitise and truncate HTML to safe_html
      • Upload author photo to Cloudinary and resize to 128px
      • Create safe properties object and add to webmention object
      • Put updated webmention in webmentions table
      • Publish to queues/send (webmention_id)
    • send (webmention_id)
      • Get the webmention record
      • Get the webhook_url from the account record
      • Send request to webhook_url with webmention object
        • Return 200 if successful
        • Auto retries
  • shared
    • status
      • log (webmention_id, description)
        • Create random ID to represent status
        • Put new record in statuses table

Tables

  • accounts table: domain, secret, webhook_url
  • webmentions: id, source, target, created_at, post {jf2}
  • statuses: id, webmention_id, created_at, description
  • blocks: domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment