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"
|
52
|
10 local preprocess = Bbcode.preprocess or error()
|
15
|
11 local bbcode_to_html = Bbcode.to_html or error()
|
|
12 local Db = require "site:/lib/Db.luan"
|
42
|
13 local Shared = require "site:/lib/Shared.luan"
|
|
14 local base_url = Shared.base_url or error()
|
|
15 local Logging = require "luan:logging/Logging.luan"
|
|
16 local logger = Logging.logger "save_edit.js"
|
15
|
17
|
|
18
|
|
19 return function()
|
|
20 local post = Http.request.parameters.post or error()
|
|
21 local text = Http.request.parameters.text or error()
|
52
|
22 local convert_urls = Http.request.parameters.convert_urls or error()
|
|
23 if convert_urls == "true" then
|
|
24 text = preprocess(text)
|
|
25 end
|
15
|
26 Db.run_in_transaction( function()
|
|
27 post = Post.get_by_id(post) or error()
|
16
|
28 post.author_is_current() or error()
|
15
|
29 post.content = text
|
|
30 post.save()
|
|
31 end )
|
|
32 local html = output_of(function() bbcode_to_html(post.content) end)
|
42
|
33 local js = output_of(function()
|
15
|
34 %>
|
42
|
35 updated( '<%=post.id%>', <%= json_string(html) %> );
|
15
|
36 <%
|
42
|
37 end)
|
|
38 local url = base_url().."/thread.html?root="..post.root_id
|
|
39 Http.push(url,js)
|
15
|
40 end
|