# HG changeset patch # User Emmanuel Gil Peyrot # Date 1527883546 -7200 # Node ID 1cff081abbedc20df817b861b6f1bf8b576e92fc # Parent e0ef90e9693149cc56ecaaaff5136c891623ba89 mod_http_avatar: Add a module to serve vCard-temp avatars over HTTP. diff -r e0ef90e96931 -r 1cff081abbed mod_http_avatar/README.markdown --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_avatar/README.markdown Fri Jun 01 22:05:46 2018 +0200 @@ -0,0 +1,28 @@ +--- +summary: Serve avatars from HTTP +... + +Introduction +============ + +This module serves avatars from local users who have one set in their +vCard, see XEP-0054 and XEP-0153. + +Configuring +=========== + +Simply load the module. Avatars are then available at +http://:5280/avatar/ + + modules_enabled = { + ... + "http_avatar"; + } + +Compatibility +============= + + ------- -------------- + trunk Works + 0.10 Should work + ------- -------------- diff -r e0ef90e96931 -r 1cff081abbed mod_http_avatar/mod_http_avatar.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_avatar/mod_http_avatar.lua Fri Jun 01 22:05:46 2018 +0200 @@ -0,0 +1,43 @@ +-- Prosody IM +-- Copyright (C) 2018 Emmanuel Gil Peyrot +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. + +local base64 = require"util.encodings".base64; +local st = require"util.stanza"; +module:depends"http"; + +local vcard_storage = module:open_store"vcard"; + +local default_avatar = [[ + +? +]]; + +local function get_avatar(event, path) + local request, response = event.request, event.response; + local photo_type, binval; + local vcard, err = vcard_storage:get(path); + if vcard then + vcard = st.deserialize(vcard); + local photo = vcard:get_child("PHOTO", "vcard-temp"); + if photo then + photo_type = photo:get_child_text("TYPE", "vcard-temp"); + binval = photo:get_child_text("BINVAL", "vcard-temp"); + end + end + if not photo_type or not binval then + response.status_code = 404; + response.headers.content_type = "image/svg+xml"; + return default_avatar; + end + response.headers.content_type = photo_type; + return base64.decode(binval); +end + +module:provides("http", { + route = { + ["GET /*"] = get_avatar; + }; +});