42
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local String = require "luan:String.luan"
|
|
4 local to_number = String.to_number or error()
|
|
5 local Time = require "luan:Time.luan"
|
|
6 local time_now = Time.now or error()
|
|
7 local Parsers = require "luan:Parsers.luan"
|
|
8 local json_string = Parsers.json_string or error()
|
|
9 local Io = require "luan:Io.luan"
|
|
10 local output_of = Io.output_of or error()
|
|
11 local Http = require "luan:http/Http.luan"
|
|
12 local User = require "site:/lib/User.luan"
|
|
13 local Post = require "site:/lib/Post.luan"
|
|
14 local Db = require "site:/lib/Db.luan"
|
|
15 local Shared = require "site:/lib/Shared.luan"
|
|
16 local base_url = Shared.base_url or error()
|
|
17 local show_post = Shared.show_post or error()
|
52
|
18 local Bbcode = require "site:/bbcode/Bbcode.luan"
|
|
19 local preprocess = Bbcode.preprocess or error()
|
42
|
20 local Logging = require "luan:logging/Logging.luan"
|
|
21 local logger = Logging.logger "new_post.js"
|
|
22
|
|
23
|
|
24 return function()
|
|
25 local user = User.current() or error()
|
|
26 local root_id = Http.request.parameters.root or error()
|
|
27 local text = Http.request.parameters.text or error()
|
52
|
28 local convert_urls = Http.request.parameters.convert_urls or error()
|
|
29 if convert_urls == "true" then
|
|
30 text = preprocess(text)
|
|
31 end
|
42
|
32 local post = Post.new{
|
|
33 root_id = to_number(root_id) or error()
|
|
34 content = text
|
56
|
35 author_id = user.id
|
42
|
36 }
|
|
37 Db.run_in_transaction( function()
|
|
38 post.save()
|
|
39 end )
|
|
40 local html = output_of(function() show_post(post,time_now()) end)
|
|
41 local js = output_of(function()
|
|
42 %>
|
|
43 added( '<%=post.id%>', <%= json_string(html) %>, <%=Post.thread_size(root_id)%> );
|
|
44 <%
|
|
45 end)
|
|
46 local url = base_url().."/thread.html?root="..root_id
|
|
47 Http.push(url,js)
|
|
48 end
|