50 lines
1.5 KiB
Lua
50 lines
1.5 KiB
Lua
|
|
local sql = require("lsqlite3")
|
|
local zlib = require("zlib")
|
|
|
|
local db = require("db")
|
|
local queries = require("queries")
|
|
local pages = require("pages")
|
|
local parsers = require("parsers")
|
|
local util = require("util")
|
|
local tagslib = require("tags")
|
|
local cache = require("cache")
|
|
local config = require("config")
|
|
local session = require("session")
|
|
|
|
local stmnt_update_bio
|
|
|
|
local oldconfigure = configure
|
|
function configure(...)
|
|
stmnt_update_bio = assert(db.conn:prepare(queries.update_bio))
|
|
return oldconfigure(...)
|
|
end
|
|
|
|
local function edit_bio(req)
|
|
local host = http_request_get_host(req)
|
|
local path = http_request_get_path(req)
|
|
local author, author_id = session.get(req)
|
|
|
|
http_request_populate_post(req)
|
|
local text = assert(http_argument_get_string(req,"text"))
|
|
|
|
local parsed = parsers.plain(text) -- Make sure the plain parser can deal with it, even though we don't store this result.
|
|
local compr_raw = zlib.compress(text)
|
|
local compr = zlib.compress(parsed)
|
|
|
|
assert(stmnt_update_bio:bind_blob(1,compr_raw) == sql.OK)
|
|
assert(stmnt_update_bio:bind(2, author_id) == sql.OK)
|
|
if util.do_sql(stmnt_update_bio) ~= sql.DONE then
|
|
stmnt_update_bio:reset()
|
|
error("Faled to update biography")
|
|
end
|
|
local loc = string.format("https://%s.%s",author,config.domain)
|
|
-- Dirty the cache for the author's index, the only place where the bio is displayed.
|
|
cache.dirty(string.format("%s.%s",author,config.domain))
|
|
http_response_header(req,"Location",loc)
|
|
http_response(req,303,"")
|
|
return
|
|
end
|
|
|
|
return edit_bio
|