annotate src/save_edit.js.luan @ 59:02d8876dc41d

improve change email
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Nov 2022 18:45:22 -0700
parents 9f8ebc757814
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Parsers = require "luan:Parsers.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local json_string = Parsers.json_string or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local output_of = Io.output_of or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Post = require "site:/lib/Post.luan"
44
96f0c3d65698 add /bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
9 local Bbcode = require "site:/bbcode/Bbcode.luan"
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
10 local preprocess = Bbcode.preprocess or error()
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local bbcode_to_html = Bbcode.to_html or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Db = require "site:/lib/Db.luan"
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
13 local Shared = require "site:/lib/Shared.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
14 local base_url = Shared.base_url or error()
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
15 local Logging = require "luan:logging/Logging.luan"
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
16 local logger = Logging.logger "save_edit.js"
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 return function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local post = Http.request.parameters.post or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local text = Http.request.parameters.text or error()
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
22 local convert_urls = Http.request.parameters.convert_urls or error()
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
23 if convert_urls == "true" then
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
24 text = preprocess(text)
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
25 end
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 Db.run_in_transaction( function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 post = Post.get_by_id(post) or error()
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
28 post.author_is_current() or error()
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 post.content = text
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 post.save()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end )
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local html = output_of(function() bbcode_to_html(post.content) end)
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
33 local js = output_of(function()
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 %>
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
35 updated( '<%=post.id%>', <%= json_string(html) %> );
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <%
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
37 end)
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
38 local url = base_url().."/thread.html?root="..post.root_id
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
39 Http.push(url,js)
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 end