diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/add_server.js.luan	Mon Oct 30 14:59:45 2023 -0600
@@ -0,0 +1,31 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local String = require "luan:String.luan"
+local regex = String.regex or error()
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Shared = require "site:/lib/Shared.luan"
+local js_error = Shared.js_error or error()
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "add_server.js"
+
+
+local invite_regex = regex[[^https://discord.gg/(\w+)$]]
+
+return function()
+	Io.stdout = Http.response.text_writer()
+	local parameters = Http.request.parameters
+	local id = parameters.id or error()
+	local name = parameters.name or error()
+	local icon = parameters.icon or error()
+	local invite = parameters.invite or error()
+	invite = invite_regex.match(invite)
+	logger.info("invite = "..invite)
+	if invite==nil then
+		js_error( "invite", [[Invalid Discord invite URL]] )
+		return
+	end
+%>
+	location = '/servers.html';
+<%
+end