annotate src/new_post.js.luan @ 58:31c895b73bd0

improve change email
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Nov 2022 16:09:17 -0700
parents 7ce54f6d93f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local String = require "luan:String.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local to_number = String.to_number or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Time = require "luan:Time.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local time_now = Time.now or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Parsers = require "luan:Parsers.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local json_string = Parsers.json_string or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Io = require "luan:Io.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local output_of = Io.output_of or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Http = require "luan:http/Http.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local User = require "site:/lib/User.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local Post = require "site:/lib/Post.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local Db = require "site:/lib/Db.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local Shared = require "site:/lib/Shared.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local base_url = Shared.base_url or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local show_post = Shared.show_post or error()
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
18 local Bbcode = require "site:/bbcode/Bbcode.luan"
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
19 local preprocess = Bbcode.preprocess or error()
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local Logging = require "luan:logging/Logging.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local logger = Logging.logger "new_post.js"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 return function()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local user = User.current() or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local root_id = Http.request.parameters.root or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 local text = Http.request.parameters.text or error()
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
28 local convert_urls = Http.request.parameters.convert_urls or error()
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
29 if convert_urls == "true" then
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
30 text = preprocess(text)
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
31 end
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local post = Post.new{
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 root_id = to_number(root_id) or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 content = text
56
7ce54f6d93f2 add change name
Franklin Schmidt <fschmidt@gmail.com>
parents: 52
diff changeset
35 author_id = user.id
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 }
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 Db.run_in_transaction( function()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 post.save()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 end )
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 local html = output_of(function() show_post(post,time_now()) end)
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 local js = output_of(function()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 %>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 added( '<%=post.id%>', <%= json_string(html) %>, <%=Post.thread_size(root_id)%> );
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <%
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 end)
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 local url = base_url().."/thread.html?root="..root_id
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 Http.push(url,js)
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 end