2020-12-21 05:22:22 +01:00
|
|
|
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()
|
2021-01-11 04:34:22 +01:00
|
|
|
local txt_compressed, markup, isanon, title, unlisted = unpack(data)
|
2020-12-21 05:22:22 +01:00
|
|
|
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 = "",
|
2021-01-11 04:34:22 +01:00
|
|
|
tags = tags_txt,
|
2021-02-14 08:30:20 +01:00
|
|
|
unlisted = unlisted == 1,
|
|
|
|
extra_load = {
|
|
|
|
'<script src="/_js/suggest_tags.js"></script>'
|
|
|
|
}
|
2020-12-21 05:22:22 +01:00
|
|
|
}
|
|
|
|
http_response(req,200,ret)
|
|
|
|
end
|
|
|
|
|
|
|
|
return edit_get
|