annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
2 local error = Luan.error
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local get_user = Shared.get_user or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local user = get_user()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13 local repo_name = Http.request.parameters.repo or error "missing repo param"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14 repo_name~="_all" and repo_name~="_private" or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15 local mode = Http.request.parameters.mode or error "missing mode param"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16 mode=="public" or mode=="private" or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19 local repo = raw_config.repos[repo_name]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 if repo == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 raw_config.repos[repo_name] = {
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 mode = mode
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 users = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 admins = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 %>added<%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 else
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 repo.mode==mode or error "mode mismatch"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 %>exists<%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 end