view src/admin/add.txt.luan @ 18:64eee582fec1

add move logs while restart
author Vadim Filimonov <fffilimonov@yandex.ru>
date Wed, 19 Jun 2024 11:45:10 +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