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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
pub mod log;
pub mod user;
use super::error::MyResult;
use crate::helper::{language::AcceptLanguage, A};
use jellycommon::routes::u_admin_dashboard;
use jellyimport::is_importing;
use jellylogic::{
admin::{
create_invite, delete_invite, do_import, get_import_errors, list_invites,
update_search_index,
},
session::AdminSession,
};
use jellyui::{
admin::AdminDashboardPage,
render_page,
scaffold::{RenderInfo, SessionInfo},
};
use rocket::{
form::Form,
get, post,
response::{content::RawHtml, Redirect},
FromForm,
};
#[get("/admin/dashboard")]
pub async fn r_admin_dashboard(
session: A<AdminSession>,
lang: AcceptLanguage,
) -> MyResult<RawHtml<String>> {
let AcceptLanguage(lang) = lang;
let flash = None;
let invites = list_invites(&session.0)?;
let last_import_err = get_import_errors(&session.0).await;
let busy = if is_importing() {
Some("An import is currently running.")
} else {
None
};
Ok(RawHtml(render_page(
&AdminDashboardPage {
busy,
last_import_err: &last_import_err,
invites: &invites,
flash,
lang: &lang,
},
RenderInfo {
importing: is_importing(),
session: Some(SessionInfo {
user: session.0 .0.user,
}),
},
lang,
)))
}
#[post("/admin/generate_invite")]
pub async fn r_admin_invite(session: A<AdminSession>) -> MyResult<Redirect> {
let _ = create_invite(&session.0)?;
Ok(Redirect::temporary(u_admin_dashboard()))
}
#[derive(FromForm)]
pub struct DeleteInvite {
invite: String,
}
#[post("/admin/remove_invite", data = "<form>")]
pub async fn r_admin_remove_invite(
session: A<AdminSession>,
form: Form<DeleteInvite>,
) -> MyResult<Redirect> {
delete_invite(&session.0, &form.invite)?;
Ok(Redirect::temporary(u_admin_dashboard()))
}
#[post("/admin/import?<incremental>")]
pub async fn r_admin_import(session: A<AdminSession>, incremental: bool) -> MyResult<Redirect> {
do_import(&session.0, incremental).await?.1?;
Ok(Redirect::temporary(u_admin_dashboard()))
}
#[post("/admin/update_search")]
pub async fn r_admin_update_search(session: A<AdminSession>) -> MyResult<Redirect> {
update_search_index(&session.0).await?;
Ok(Redirect::temporary(u_admin_dashboard()))
}
|