local zlib = require("zlib") local sql = require("lsqlite3") local db = require("db") local queries = require("queries") local util = require("util") local pages = require("pages") local tags = require("tags") local session = require("session") local config = require("config") local stmnt_edit local oldconfigure = configure function configure(...) stmnt_edit = assert(db.conn:prepare(queries.select_edit)) return oldconfigure(...) end local function edit_get(req) local host = http_request_get_host(req) local path = http_request_get_path(req) local author, authorid = session.get(req) http_request_populate_qs(req) local story = assert(http_argument_get_string(req,"story")) local story_id = util.decode_id(story) local ret --Check that the logged in user is the owner of the story --sql-side. If we're not the owner, we'll get 0 rows back. stmnt_edit:bind_names{ postid = story_id, authorid = authorid } local err = util.do_sql(stmnt_edit) if err == sql.DONE then --No rows, we're probably not the owner (it might --also be because there's no such story) ret = pages.cantedit{ path = story, } stmnt_edit:reset() http_response(req,200,ret) return end assert(err == sql.ROW) local data = stmnt_edit:get_values() local txt_compressed, markup, isanon, title, unlisted = unpack(data) print("from query, unlisted was:",unlisted) local text = zlib.decompress(txt_compressed) local tags = tags.get(story_id) local tags_txt = table.concat(tags,";") stmnt_edit:reset() ret = pages.edit{ title = title, text = text, markup = markup, user = author, isanon = isanon == 1, domain = config.domain, story = story_id, err = "", tags = tags_txt, unlisted = unlisted } http_response(req,200,ret) end return edit_get