view src/admin/add.txt.luan @ 14:49461857ed79

fix log name for rm
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 28 Jul 2022 16:28:27 +0300
parents dfc36e7ed22c
children
line wrap: on
line source

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