comparison src/new_post.js.luan @ 42:0c1b820fff34

use push
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2022 14:02:28 -0700
parents
children 9f8ebc757814
comparison
equal deleted inserted replaced
41:acb730710328 42:0c1b820fff34
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()
18 local Logging = require "luan:logging/Logging.luan"
19 local logger = Logging.logger "new_post.js"
20
21
22 return function()
23 local user = User.current() or error()
24 local root_id = Http.request.parameters.root or error()
25 local text = Http.request.parameters.text or error()
26 local post = Post.new{
27 root_id = to_number(root_id) or error()
28 content = text
29 author_name = user.name
30 }
31 Db.run_in_transaction( function()
32 post.save()
33 end )
34 local html = output_of(function() show_post(post,time_now()) end)
35 local js = output_of(function()
36 %>
37 added( '<%=post.id%>', <%= json_string(html) %>, <%=Post.thread_size(root_id)%> );
38 console.log(<%=post.id%>);
39 <%
40 end)
41 local url = base_url().."/thread.html?root="..root_id
42 Http.push(url,js)
43 end