diff src/admin/add.txt.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/admin/add.txt.luan	Thu May 12 13:51:59 2022 +0400
@@ -0,0 +1,32 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Shared = require "site:/lib/Shared.luan"
+local get_user = Shared.get_user or error()
+local get_raw_config = Shared.get_raw_config or error()
+local save_raw_config = Shared.save_raw_config or error()
+
+
+return function()
+	local user = get_user()
+	local repo_name = Http.request.parameters.repo or error "missing repo param"
+	repo_name~="_all" and repo_name~="_private" or error()
+	local mode = Http.request.parameters.mode or error "missing mode param"
+	mode=="public" or mode=="private" or error()
+	Io.stdout = Http.response.text_writer()
+	local raw_config = get_raw_config()
+	local repo = raw_config.repos[repo_name]
+	if repo == nil then
+		raw_config.repos[repo_name] = {
+			mode = mode
+			users = {user}
+			admins = {user}
+		}
+		save_raw_config(raw_config)
+		%>added<%
+	else
+		repo.mode==mode or error "mode mismatch"
+		%>exists<%
+	end
+end