Mercurial Hosting > freedit
diff src/save_edit.js.luan @ 15:0edde02b908c
edit in place
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Jul 2022 23:27:54 -0600 |
parents | |
children | bff178656073 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/save_edit.js.luan Tue Jul 05 23:27:54 2022 -0600 @@ -0,0 +1,34 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Parsers = require "luan:Parsers.luan" +local json_string = Parsers.json_string or error() +local Io = require "luan:Io.luan" +local output_of = Io.output_of or error() +local Http = require "luan:http/Http.luan" +local Post = require "site:/lib/Post.luan" +local Bbcode = require "site:/lib/Bbcode.luan" +local bbcode_preprocess = Bbcode.preprocess or error() +local bbcode_to_html = Bbcode.to_html or error() +local Db = require "site:/lib/Db.luan" +local User = require "site:/lib/User.luan" + + +return function() + local post = Http.request.parameters.post or error() + local text = Http.request.parameters.text or error() + text = bbcode_preprocess(text) + Db.run_in_transaction( function() + post = Post.get_by_id(post) or error() + local user = User.current() or error() + user.name = post.author_name or error() + post.content = text + post.save() + end ) + local html = output_of(function() bbcode_to_html(post.content) end) + Io.stdout = Http.response.text_writer() +%> +cancelEdit('<%=post.id%>'); +let postDiv = document.querySelector('[post="<%=post.id%>"]'); +postDiv.querySelector('[message]').innerHTML = <%= json_string(html) %>; +<% +end