Mercurial > prosody-modules
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 513:5e8843a869a3 | 514:46e1983486e9 |
|---|---|
| 41 local pastes = {}; | 41 local pastes = {}; |
| 42 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; | 42 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; |
| 43 | 43 |
| 44 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; | 44 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; |
| 45 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; | 45 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; |
| 46 | |
| 47 if expire_after == 0 then | |
| 48 local dm = require "util.datamanager"; | |
| 49 setmetatable(pastes, { | |
| 50 __index = function (pastes, id) | |
| 51 if type(id) == "string" then | |
| 52 return dm.load(id, module.host, "pastebin"); | |
| 53 end | |
| 54 end; | |
| 55 __newindex = function (pastes, id, data) | |
| 56 if type(id) == "string" then | |
| 57 dm.store(id, module.host, "pastebin", data); | |
| 58 end | |
| 59 end; | |
| 60 }); | |
| 61 else | |
| 62 setmetatable(pastes, nil); | |
| 63 end | |
| 46 | 64 |
| 47 function pastebin_text(text) | 65 function pastebin_text(text) |
| 48 local uuid = uuid_new(); | 66 local uuid = uuid_new(); |
| 49 pastes[uuid] = { body = text, time = os_time(), headers = default_headers }; | 67 pastes[uuid] = { body = text, time = os_time(), headers = default_headers }; |
| 50 pastes[#pastes+1] = uuid; | 68 pastes[#pastes+1] = uuid; |
