comparison src/save_edit.js.luan @ 16:bff178656073

delete function
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Jul 2022 22:42:42 -0600
parents 0edde02b908c
children da006d1c1eba
comparison
equal deleted inserted replaced
15:0edde02b908c 16:bff178656073
8 local Post = require "site:/lib/Post.luan" 8 local Post = require "site:/lib/Post.luan"
9 local Bbcode = require "site:/lib/Bbcode.luan" 9 local Bbcode = require "site:/lib/Bbcode.luan"
10 local bbcode_preprocess = Bbcode.preprocess or error() 10 local bbcode_preprocess = Bbcode.preprocess or error()
11 local bbcode_to_html = Bbcode.to_html or error() 11 local bbcode_to_html = Bbcode.to_html or error()
12 local Db = require "site:/lib/Db.luan" 12 local Db = require "site:/lib/Db.luan"
13 local User = require "site:/lib/User.luan"
14 13
15 14
16 return function() 15 return function()
17 local post = Http.request.parameters.post or error() 16 local post = Http.request.parameters.post or error()
18 local text = Http.request.parameters.text or error() 17 local text = Http.request.parameters.text or error()
19 text = bbcode_preprocess(text) 18 text = bbcode_preprocess(text)
20 Db.run_in_transaction( function() 19 Db.run_in_transaction( function()
21 post = Post.get_by_id(post) or error() 20 post = Post.get_by_id(post) or error()
22 local user = User.current() or error() 21 post.author_is_current() or error()
23 user.name = post.author_name or error()
24 post.content = text 22 post.content = text
25 post.save() 23 post.save()
26 end ) 24 end )
27 local html = output_of(function() bbcode_to_html(post.content) end) 25 local html = output_of(function() bbcode_to_html(post.content) end)
28 Io.stdout = Http.response.text_writer() 26 Io.stdout = Http.response.text_writer()