Repository navigation
Expand file tree
/
Copy pathmirror_routes.v
More file actions
75 lines (69 loc) · 3.2 KB
/
Copy pathmirror_routes.v
File metadata and controls
75 lines (69 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2019-2026 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main
import veb
@['/:username/:repo_name/settings/mirrors']
pub fn (mut app App) repo_mirrors(mut ctx Context, username string, repo_name string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
}
mirrors := app.list_repo_mirrors(repo.id)
return $veb.html('templates/repo/mirrors.html')
}
@['/:username/:repo_name/settings/mirrors'; post]
pub fn (mut app App) handle_add_repo_mirror(mut ctx Context, username string, repo_name string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
}
app.add_repo_mirror(repo.id, ctx.user.id, ctx.form['url'], ctx.form['mirror_username'],
ctx.form['mirror_password'], ctx.form['ssh_private_key'], ctx.form['ssh_known_hosts'],
ctx.form['direction'], ctx.form['overwrite_diverged'] == 'on',
ctx.form['only_protected'] == 'on', ctx.form['interval_minutes'].int()) or {
ctx.error(err.str())
return app.repo_mirrors(mut ctx, username, repo_name)
}
return ctx.redirect('/${username}/${repo_name}/settings/mirrors')
}
@['/:username/:repo_name/settings/mirrors/:id/sync'; post]
pub fn (mut app App) handle_sync_repo_mirror(mut ctx Context, username string, repo_name string, id string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
}
mirror := app.find_repo_mirror(id.int()) or { return ctx.not_found() }
if mirror.repo_id != repo.id {
return ctx.not_found()
}
app.sync_repo_mirror(mirror, false) or { ctx.error(err.str()) }
return app.repo_mirrors(mut ctx, username, repo_name)
}
@['/:username/:repo_name/settings/mirrors/:id/toggle'; post]
pub fn (mut app App) handle_toggle_repo_mirror(mut ctx Context, username string, repo_name string, id string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
}
mirror := app.find_repo_mirror(id.int()) or { return ctx.not_found() }
if mirror.repo_id != repo.id {
return ctx.not_found()
}
app.set_repo_mirror_enabled(repo.id, mirror.id, !mirror.enabled) or {
ctx.error('Could not update the mirror')
}
return ctx.redirect('/${username}/${repo_name}/settings/mirrors')
}
@['/:username/:repo_name/settings/mirrors/:id/delete'; post]
pub fn (mut app App) handle_delete_repo_mirror(mut ctx Context, username string, repo_name string, id string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
}
mirror := app.find_repo_mirror(id.int()) or { return ctx.not_found() }
if mirror.repo_id != repo.id {
return ctx.not_found()
}
app.delete_repo_mirror(repo.id, mirror.id) or { ctx.error('Could not delete the mirror') }
return ctx.redirect('/${username}/${repo_name}/settings/mirrors')
}