Mercurial Hosting > lang
view src/save_chat.js.luan @ 51:4581a20b8124
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 15 Aug 2025 23:24:38 +0900 |
parents | cc20eebaa74a |
children | 27758f3b2d69 |
line wrap: on
line source
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 Http = require "luan:http/Http.luan" local Chat = require "site:/lib/Chat.luan" local get_chat_by_id = Chat.get_by_id or error() local User = require "site:/lib/User.luan" local current_user = User.current or error() local Db = require "site:/lib/Db.luan" local run_in_transaction = Db.run_in_transaction or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "save_chat.js" return function() local chat = Http.request.parameters.chat or error() local name = Http.request.parameters.name or error() local voice = Http.request.parameters.voice or error() local show_text = Http.request.parameters.show_text local autoplay = Http.request.parameters.autoplay local is_private = Http.request.parameters.is_private run_in_transaction( function() chat = get_chat_by_id(chat) or error() chat.user_id == current_user().id or error() chat.name = name chat.voice = voice chat.show_text = show_text ~= nil chat.autoplay = autoplay ~= nil chat.is_private = is_private ~= nil chat.save() end ) Io.stdout = Http.response.text_writer() %> setChat(<%= json_string(chat.info()) %>); <% end