15
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Parsers = require "luan:Parsers.luan"
|
|
4 local json_string = Parsers.json_string or error()
|
|
5 local Io = require "luan:Io.luan"
|
|
6 local output_of = Io.output_of or error()
|
|
7 local Http = require "luan:http/Http.luan"
|
|
8 local Post = require "site:/lib/Post.luan"
|
44
|
9 local Bbcode = require "site:/bbcode/Bbcode.luan"
|
15
|
10 local bbcode_to_html = Bbcode.to_html or error()
|
|
11 local Db = require "site:/lib/Db.luan"
|
42
|
12 local Shared = require "site:/lib/Shared.luan"
|
|
13 local base_url = Shared.base_url or error()
|
|
14 local Logging = require "luan:logging/Logging.luan"
|
|
15 local logger = Logging.logger "save_edit.js"
|
15
|
16
|
|
17
|
|
18 return function()
|
|
19 local post = Http.request.parameters.post or error()
|
|
20 local text = Http.request.parameters.text or error()
|
|
21 Db.run_in_transaction( function()
|
|
22 post = Post.get_by_id(post) or error()
|
16
|
23 post.author_is_current() or error()
|
15
|
24 post.content = text
|
|
25 post.save()
|
|
26 end )
|
|
27 local html = output_of(function() bbcode_to_html(post.content) end)
|
42
|
28 local js = output_of(function()
|
15
|
29 %>
|
42
|
30 updated( '<%=post.id%>', <%= json_string(html) %> );
|
15
|
31 <%
|
42
|
32 end)
|
|
33 local url = base_url().."/thread.html?root="..post.root_id
|
|
34 Http.push(url,js)
|
15
|
35 end
|