view src/private/tools/save_config.txt.luan @ 88:7b339b1ccd11

add tools/users.html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 16:18:39 -0600
parents e229f4aacde0
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local parse = Luan.parse or error()
local stringify = Luan.stringify or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Db = require "site:/lib/Db.luan"
local run_in_transaction = Db.run_in_transaction or error()


return function()
	local config = Http.request.parameters.config or error()
	config = parse(config)
	run_in_transaction( function()
		local doc = Db.get_document("type:config") or {
			type = "config"
		}
		doc.config = stringify(config)
		Db.save(doc)
	end )
	Http.reset_luan()
	Io.stdout = Http.response.text_writer()
	%>saved<%
end