comparison src/add_server.js.luan @ 13:af2b95854072

add server records
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 30 Oct 2023 21:32:42 -0600
parents 3e2cb946d511
children 552d6f944acb
comparison
equal deleted inserted replaced
12:3e2cb946d511 13:af2b95854072
4 local regex = String.regex or error() 4 local regex = String.regex or error()
5 local Io = require "luan:Io.luan" 5 local Io = require "luan:Io.luan"
6 local Http = require "luan:http/Http.luan" 6 local Http = require "luan:http/Http.luan"
7 local Shared = require "site:/lib/Shared.luan" 7 local Shared = require "site:/lib/Shared.luan"
8 local js_error = Shared.js_error or error() 8 local js_error = Shared.js_error or error()
9 local Server = require "site:/lib/Server.luan"
10 local Utils = require "site:/lib/Utils.luan"
11 local get_user = Utils.get_user or error()
12 local Db = require "site:/lib/Db.luan"
13 local run_in_transaction = Db.run_in_transaction or error()
9 local Logging = require "luan:logging/Logging.luan" 14 local Logging = require "luan:logging/Logging.luan"
10 local logger = Logging.logger "add_server.js" 15 local logger = Logging.logger "add_server.js"
11 16
12 17
13 local invite_regex = regex[[^https://discord.gg/(\w+)$]] 18 local invite_regex = regex[[^https://discord.gg/(\w+)$]]
23 logger.info("invite = "..invite) 28 logger.info("invite = "..invite)
24 if invite==nil then 29 if invite==nil then
25 js_error( "invite", [[Invalid Discord invite URL]] ) 30 js_error( "invite", [[Invalid Discord invite URL]] )
26 return 31 return
27 end 32 end
33 run_in_transaction( function()
34 local server = Server.new{
35 owner_discord_id = get_user() or error()
36 discord_id = id
37 name = name
38 icon = icon
39 invite = invite
40 }
41 server.save()
42 end )
28 %> 43 %>
29 location = '/servers.html'; 44 location = '/servers.html';
30 <% 45 <%
31 end 46 end