Mercurial Hosting > chat
changeset 69:e229f4aacde0
config in lucene
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 06 Mar 2025 20:08:19 -0700 |
parents | 329c3f70fd78 |
children | effa1e0af52a |
files | src/lib/Shared.luan src/private/tools/config.html.luan src/private/tools/save_config.txt.luan |
diffstat | 3 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/Shared.luan Thu Mar 06 19:43:18 2025 -0700 +++ b/src/lib/Shared.luan Thu Mar 06 20:08:19 2025 -0700 @@ -2,8 +2,6 @@ local error = Luan.error local ipairs = Luan.ipairs or error() local parse = Luan.parse or error() -local Io = require "luan:Io.luan" -local uri = Io.uri or error() local Time = require "luan:Time.luan" local Thread = require "luan:Thread.luan" local thread_run = Thread.run or error() @@ -18,6 +16,7 @@ local chat_search = Chat.search or error() local Utils = require "site:/lib/Utils.luan" local base_url = Utils.base_url or error() +local Db = require "site:/lib/Db.luan" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "Shared" @@ -87,16 +86,14 @@ } end -local config_file = uri("site:/private/local/config.luano") -Shared.config_file = config_file - do - if config_file.exists() then - Shared.config = parse( config_file.read_text() ) + local doc = Db.get_document("type:config") + if doc ~= nil then + Shared.config = parse( doc.config ) else Shared.config = { mail_server = { - host = "smtpcorp.com" + host = "mail.smtp2go.com" port = 465 username = "xxx" password = "xxx" @@ -114,7 +111,6 @@ function Shared.send_mail_async(mail) mail.From = mail.From or default_from -logger.info(mail.From) thread_run( function() send_mail0(mail) end )
--- a/src/private/tools/config.html.luan Thu Mar 06 19:43:18 2025 -0700 +++ b/src/private/tools/config.html.luan Thu Mar 06 20:08:19 2025 -0700 @@ -34,7 +34,7 @@ <h1>Configure</h1> <form method=post action="save_config.txt"> <p> - <textarea name=config autofocus><%= stringify(config) %></textarea> + <textarea name=config autofocus><%= stringify(config).."\n" %></textarea> </p> <p> <input type=submit value="Update">
--- a/src/private/tools/save_config.txt.luan Thu Mar 06 19:43:18 2025 -0700 +++ b/src/private/tools/save_config.txt.luan Thu Mar 06 20:08:19 2025 -0700 @@ -3,17 +3,21 @@ local parse = Luan.parse or error() local stringify = Luan.stringify or error() local Io = require "luan:Io.luan" -local uri = Io.uri or error() local Http = require "luan:http/Http.luan" -local Shared = require "site:/lib/Shared.luan" -local config_file = Shared.config_file or error() +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) - uri("site:/private/local/").mkdir() - config_file.write_text(stringify(config).."\n") + 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<%