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
|
/*
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) 2023 metamuffin <metamuffin.org>
*/
use crate::{database::Database, library::Library, routes::ui::error::MyResult, CONF};
use api::{r_api_account_login, r_api_version, r_api_library_node};
use jellyremuxer::RemuxerContext;
use rocket::{
catchers, config::SecretKey, fairing::AdHoc, fs::FileServer, get, http::Header, routes, Build,
Config, Rocket,
};
use std::fs::File;
use stream::r_stream;
use ui::{
account::{
admin::{r_account_admin_dashboard, r_account_admin_invite, r_account_admin_remove_user},
r_account_login, r_account_login_post, r_account_logout, r_account_logout_post,
r_account_register, r_account_register_post,
settings::{r_account_settings, r_account_settings_post},
},
error::r_catch,
home::{r_home, r_home_unpriv},
node::{r_item_assets, r_library_node},
player::r_player,
style::{r_assets_font, r_assets_js, r_assets_style},
};
pub mod api;
pub mod stream;
pub mod ui;
#[macro_export]
macro_rules! uri {
($kk:stmt) => {
&rocket::uri!($kk).to_string()
};
}
pub fn build_rocket(
remuxer: RemuxerContext,
library: Library,
database: Database,
) -> Rocket<Build> {
rocket::build()
.configure(Config {
secret_key: SecretKey::derive_from(CONF.cookie_key.as_bytes()),
..Default::default()
})
.manage(remuxer)
.manage(library)
.manage(database)
.attach(AdHoc::on_response("set server header", |_req, res| {
res.set_header(Header::new("server", "jellything"));
Box::pin(async {})
}))
.register("/", catchers![r_catch])
.mount("/assets", FileServer::from(&CONF.asset_path))
.mount(
"/",
routes![
r_home,
r_home_unpriv,
r_favicon,
r_item_assets,
r_library_node,
r_assets_style,
r_assets_font,
r_assets_js,
r_stream,
r_player,
r_account_login,
r_account_login_post,
r_account_register,
r_account_register_post,
r_account_logout,
r_account_logout_post,
r_account_admin_dashboard,
r_account_admin_invite,
r_account_admin_remove_user,
r_account_settings,
r_account_settings_post,
r_api_version,
r_api_account_login,
r_api_library_node,
],
)
}
#[get("/favicon.ico")]
fn r_favicon() -> MyResult<File> {
Ok(File::open(CONF.asset_path.join("favicon.ico"))?)
}
|