Mercurial > prosody-modules
diff mod_pastebin/mod_pastebin.lua @ 514:46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 19 Dec 2011 12:29:03 +0000 |
parents | 5e8843a869a3 |
children | 3d3687fef751 |
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua Mon Dec 19 11:38:57 2011 +0000 +++ b/mod_pastebin/mod_pastebin.lua Mon Dec 19 12:29:03 2011 +0000 @@ -44,6 +44,24 @@ local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; +if expire_after == 0 then + local dm = require "util.datamanager"; + setmetatable(pastes, { + __index = function (pastes, id) + if type(id) == "string" then + return dm.load(id, module.host, "pastebin"); + end + end; + __newindex = function (pastes, id, data) + if type(id) == "string" then + dm.store(id, module.host, "pastebin", data); + end + end; + }); +else + setmetatable(pastes, nil); +end + function pastebin_text(text) local uuid = uuid_new(); pastes[uuid] = { body = text, time = os_time(), headers = default_headers };