annotate src/add_server.js.luan @ 12:3e2cb946d511

form handling
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 30 Oct 2023 14:59:45 -0600
parents
children af2b95854072
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local String = require "luan:String.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local regex = String.regex or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Shared = require "site:/lib/Shared.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local js_error = Shared.js_error or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Logging = require "luan:logging/Logging.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local logger = Logging.logger "add_server.js"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local invite_regex = regex[[^https://discord.gg/(\w+)$]]
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return function()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 Io.stdout = Http.response.text_writer()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local parameters = Http.request.parameters
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local id = parameters.id or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local name = parameters.name or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local icon = parameters.icon or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local invite = parameters.invite or error()
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 invite = invite_regex.match(invite)
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 logger.info("invite = "..invite)
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 if invite==nil then
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 js_error( "invite", [[Invalid Discord invite URL]] )
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 return
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 %>
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 location = '/servers.html';
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <%
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end