diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/Cargo.toml | 10 | ||||
-rw-r--r-- | server/src/main.rs | 7 | ||||
-rw-r--r-- | server/src/routes/stream.rs | 18 | ||||
-rw-r--r-- | server/src/routes/ui/account/settings.rs | 1 | ||||
-rw-r--r-- | server/src/routes/ui/admin/log.rs | 28 | ||||
-rw-r--r-- | server/src/routes/ui/admin/mod.rs | 12 | ||||
-rw-r--r-- | server/src/routes/ui/admin/user.rs | 4 | ||||
-rw-r--r-- | server/src/routes/ui/assets.rs | 12 | ||||
-rw-r--r-- | server/src/routes/ui/error.rs | 2 | ||||
-rw-r--r-- | server/src/routes/ui/home.rs | 2 | ||||
-rw-r--r-- | server/src/routes/ui/layout.rs | 4 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 21 | ||||
-rw-r--r-- | server/src/routes/ui/player.rs | 7 | ||||
-rw-r--r-- | server/src/routes/ui/search.rs | 4 | ||||
-rw-r--r-- | server/src/routes/ui/sort.rs | 2 |
15 files changed, 56 insertions, 78 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index 6d5ece3..5029408 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -10,15 +10,15 @@ jellystream = { path = "../stream" } jellytranscoder = { path = "../transcoder" } jellyimport = { path = "../import" } -serde = { version = "1.0.197", features = ["derive"] } +serde = { version = "1.0.203", features = ["derive"] } bincode = { version = "2.0.0-rc.3", features = ["serde", "derive"] } -serde_json = "1.0.115" +serde_json = "1.0.117" log = { workspace = true } anyhow = { workspace = true } env_logger = "0.11.3" rand = "0.8.5" -base64 = "0.22.0" +base64 = "0.22.1" chrono = { version = "0.4.38", features = ["serde"] } vte = "0.13.0" chashmap = "2.2.2" @@ -27,10 +27,10 @@ humansize = "2.1.3" argon2 = "0.5.3" aes-gcm-siv = "0.11.1" -async-recursion = "1.1.0" +async-recursion = "1.1.1" futures = "0.3.30" tokio = { workspace = true } -tokio-util = { version = "0.7.10", features = ["io", "io-util"] } +tokio-util = { version = "0.7.11", features = ["io", "io-util"] } markup = "0.15.0" rocket = { workspace = true, features = ["secrets", "json"] } diff --git a/server/src/main.rs b/server/src/main.rs index 2cc8b98..dae2da4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -3,9 +3,8 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2024 metamuffin <metamuffin.org> */ -#![feature(lazy_cell)] -#![feature(int_roundings)] -#![feature(let_chains)] +#![feature(int_roundings, let_chains)] +#![allow(clippy::needless_borrows_for_generic_args)] use crate::routes::ui::{account::hash_password, admin::log::enable_logging}; use anyhow::Context; @@ -48,7 +47,7 @@ async fn main() { Ser(User { admin: true, name: username.clone(), - password: hash_password(&username, &password), + password: hash_password(username, password), ..admin.unwrap_or_else(|| User { display_name: "Admin".to_string(), ..Default::default() diff --git a/server/src/routes/stream.rs b/server/src/routes/stream.rs index ecfa3e7..756c502 100644 --- a/server/src/routes/stream.rs +++ b/server/src/routes/stream.rs @@ -54,7 +54,7 @@ pub async fn r_stream( spec: StreamSpec, ) -> Result<Either<StreamResponse, RedirectResponse>, MyError> { let node = T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))?; let source = node @@ -86,7 +86,7 @@ pub async fn r_stream( .ok_or(anyhow!("no credentials on the server-side"))?; info!("creating session on {host}"); - let instance = federation.get_instance(&host)?.to_owned(); + let instance = federation.get_instance(host)?.to_owned(); let session = instance .login(CreateSessionParams { username: username.to_owned(), @@ -116,12 +116,12 @@ pub async fn r_stream( range .as_ref() .map(|r| r.to_cr_hv()) - .unwrap_or(format!("none")) + .unwrap_or("none".to_string()) ); let urange = match &range { Some(r) => { - let r = r.0.get(0).unwrap_or(&(None..None)); + let r = r.0.first().unwrap_or(&(None..None)); r.start.unwrap_or(0)..r.end.unwrap_or(isize::MAX as usize) } None => 0..(isize::MAX as usize), @@ -192,14 +192,8 @@ impl RequestRange { assert_eq!(self.0.len(), 1); format!( "bytes {}-{}/*", - self.0[0] - .start - .map(|e| format!("{e}")) - .unwrap_or(String::new()), - self.0[0] - .end - .map(|e| format!("{e}")) - .unwrap_or(String::new()) + self.0[0].start.map(|e| e.to_string()).unwrap_or_default(), + self.0[0].end.map(|e| e.to_string()).unwrap_or_default() ) } pub fn from_hv(s: &str) -> Result<Self> { diff --git a/server/src/routes/ui/account/settings.rs b/server/src/routes/ui/account/settings.rs index 492e8ca..7d54d75 100644 --- a/server/src/routes/ui/account/settings.rs +++ b/server/src/routes/ui/account/settings.rs @@ -98,7 +98,6 @@ fn settings_page(session: Session, flash: Option<MyResult<String>>) -> DynLayout p { "The secret can be found in " code{"$XDG_CONFIG_HOME/jellynative_secret"} " or by clicking " a.button[href="jellynative://show-secret-v1"] { "Show Secret" } "." } } }, - ..Default::default() } } diff --git a/server/src/routes/ui/admin/log.rs b/server/src/routes/ui/admin/log.rs index 5b81a52..884ad7a 100644 --- a/server/src/routes/ui/admin/log.rs +++ b/server/src/routes/ui/admin/log.rs @@ -22,7 +22,7 @@ use std::{ const MAX_LOG_LEN: usize = 4096; -static LOGGER: LazyLock<Log> = LazyLock::new(Log::new); +static LOGGER: LazyLock<Log> = LazyLock::new(Log::default); pub fn enable_logging() { log::set_logger(&*LOGGER).unwrap(); @@ -63,9 +63,8 @@ pub fn r_admin_log<'a>(_session: AdminSession, warnonly: bool) -> MyResult<DynLa ..Default::default() }) } - -impl Log { - pub fn new() -> Self { +impl Default for Log { + fn default() -> Self { Self { inner: env_logger::builder() .filter_level(log::LevelFilter::Warn) @@ -74,6 +73,8 @@ impl Log { log: Default::default(), } } +} +impl Log { fn should_log(&self, metadata: &log::Metadata) -> bool { let level = metadata.level(); level @@ -152,18 +153,11 @@ fn format_level(level: Level) -> impl markup::Render { markup::new! { span[style=format!("color:{c}")] {@s} } } +#[derive(Default)] pub struct HtmlOut { s: String, color: bool, } -impl Default for HtmlOut { - fn default() -> Self { - Self { - color: false, - s: String::new(), - } - } -} impl HtmlOut { pub fn set_color(&mut self, [r, g, b]: [u8; 3]) { self.reset_color(); @@ -184,16 +178,12 @@ impl vte::Perform for HtmlOut { x => write!(self.s, "&#{};", x as u32).unwrap(), } } - fn execute(&mut self, _byte: u8) {} fn hook(&mut self, _params: &vte::Params, _i: &[u8], _ignore: bool, _a: char) {} fn put(&mut self, _byte: u8) {} fn unhook(&mut self) {} fn osc_dispatch(&mut self, _params: &[&[u8]], _bell_terminated: bool) {} - fn esc_dispatch(&mut self, _intermediates: &[u8], _ignore: bool, _byte: u8) { - // self.s += &format!(" {:?} ", (_intermediates, _byte)) - } - + fn esc_dispatch(&mut self, _intermediates: &[u8], _ignore: bool, _byte: u8) {} fn csi_dispatch( &mut self, params: &vte::Params, @@ -202,9 +192,9 @@ impl vte::Perform for HtmlOut { action: char, ) { let mut k = params.iter(); - // self.s += &format!(" {:?} ", (params, action)); + #[allow(clippy::single_match)] match action { - 'm' => match k.next().unwrap_or(&[0]).get(0).unwrap_or(&0) { + 'm' => match k.next().unwrap_or(&[0]).first().unwrap_or(&0) { c @ (30..=37 | 40..=47) => { let c = if *c >= 40 { *c - 10 } else { *c }; self.set_color(match c { diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index 540ac72..25f1f42 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -134,7 +134,7 @@ pub async fn r_admin_invite( database: &State<DataAcid>, ) -> MyResult<DynLayoutPage<'static>> { let i = format!("{}", rand::thread_rng().gen::<u128>()); - T_INVITE.insert(&database, &*i, ())?; + T_INVITE.insert(database, &*i, ())?; admin_dashboard(database, Some(Ok(format!("Invite: {}", i)))).await } @@ -152,7 +152,7 @@ pub async fn r_admin_remove_invite( ) -> MyResult<DynLayoutPage<'static>> { drop(session); T_INVITE - .remove(&database, form.invite.as_str())? + .remove(database, form.invite.as_str())? .ok_or(anyhow!("invite did not exist"))?; admin_dashboard(database, Some(Ok("Invite invalidated".into()))).await @@ -166,9 +166,9 @@ pub async fn r_admin_import( ) -> MyResult<DynLayoutPage<'static>> { drop(session); let t = Instant::now(); - let r = import(&database, &federation).await; + let r = import(database, federation).await; admin_dashboard( - &database, + database, Some( r.map_err(|e| e.into()) .map(|_| format!("Import successful; took {:?}", t.elapsed())), @@ -187,7 +187,7 @@ pub async fn r_admin_delete_cache( let r = tokio::fs::remove_dir_all(&CONF.cache_path).await; tokio::fs::create_dir(&CONF.cache_path).await?; admin_dashboard( - &database, + database, Some( r.map_err(|e| e.into()) .map(|_| format!("Cache deleted; took {:?}", t.elapsed())), @@ -233,7 +233,7 @@ pub async fn r_admin_transcode_posters( drop(_permit); admin_dashboard( - &database, + database, Some(Ok(format!( "All posters pre-transcoded; took {:?}", t.elapsed() diff --git a/server/src/routes/ui/admin/user.rs b/server/src/routes/ui/admin/user.rs index 4d77191..26c1837 100644 --- a/server/src/routes/ui/admin/user.rs +++ b/server/src/routes/ui/admin/user.rs @@ -76,7 +76,7 @@ fn manage_single_user<'a>( name: String, ) -> MyResult<DynLayoutPage<'a>> { let user = T_USER - .get(&database, &*name)? + .get(database, &*name)? .ok_or(anyhow!("user does not exist"))?; let flash = flash.map(|f| f.map_err(|e| format!("{e:?}"))); @@ -193,7 +193,7 @@ pub fn r_admin_remove_user( ) -> MyResult<DynLayoutPage<'static>> { drop(session); T_USER - .remove(&database, form.name.as_str())? + .remove(database, form.name.as_str())? .ok_or(anyhow!("user did not exist"))?; user_management(database, Some(Ok("User removed".into()))) } diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index c278a31..ad31240 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -75,7 +75,7 @@ pub async fn r_item_assets( width: Option<usize>, ) -> MyResult<Redirect> { let node = T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))?; @@ -83,10 +83,10 @@ pub async fn r_item_assets( AssetRole::Backdrop => node.public.backdrop, AssetRole::Poster => node.public.poster, }; - if let None = asset { + if asset.is_none() { if let Some(parent) = &node.public.path.last() { let parent = T_NODE - .get(&db, parent.as_str())? + .get(db, parent.as_str())? .ok_or(anyhow!("node does not exist"))?; asset = match role { AssetRole::Backdrop => parent.public.backdrop, @@ -113,7 +113,7 @@ pub async fn r_person_asset( width: Option<usize>, ) -> MyResult<Redirect> { T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))?; @@ -129,7 +129,7 @@ pub async fn r_person_asset( .person .headshot .to_owned() - .unwrap_or(AssetInner::Assets(format!("fallback-Person.avif").into()).ser()); + .unwrap_or(AssetInner::Assets("fallback-Person.avif".into()).ser()); Ok(Redirect::temporary(rocket::uri!(r_asset(asset.0, width)))) } @@ -146,7 +146,7 @@ pub async fn r_node_thumbnail( width: Option<usize>, ) -> MyResult<Redirect> { let node = T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))?; diff --git a/server/src/routes/ui/error.rs b/server/src/routes/ui/error.rs index b8a132d..ba1dc88 100644 --- a/server/src/routes/ui/error.rs +++ b/server/src/routes/ui/error.rs @@ -41,7 +41,7 @@ pub fn r_catch<'a>(status: Status, _request: &Request) -> DynLayoutPage<'a> { } #[catch(default)] -pub fn r_api_catch<'a>(status: Status, _request: &Request) -> Value { +pub fn r_api_catch(status: Status, _request: &Request) -> Value { json!({ "error": format!("{status}") }) } diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index 2fa9212..0a1089a 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -50,7 +50,7 @@ pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { .collect::<Vec<_>>(); let toplevel = T_NODE - .get(&db, "library")? + .get(db, "library")? .context("root node missing")? .public .children diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs index 1696ac4..9f9038c 100644 --- a/server/src/routes/ui/layout.rs +++ b/server/src/routes/ui/layout.rs @@ -74,7 +74,7 @@ markup::define! { @if let Some(flash) = &flash { @match flash { Ok(mesg) => { section.message { p.success { @mesg } } } - Err(err) => { section.message { p.error { @format!("{err}") } } } + Err(err) => { section.message { p.error { @err } } } } } } @@ -110,7 +110,7 @@ impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> { title: self.title, class: &format!( "{} theme-{:?}", - self.class.as_deref().unwrap_or(""), + self.class.unwrap_or(""), session .as_ref() .map(|s| s.user.theme) diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index bd839fb..d99ddb7 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -47,7 +47,7 @@ pub async fn r_library_node_ext<'a>( db: &'a State<DataAcid>, ) -> MyResult<Json<ExtendedNode>> { T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))?; @@ -63,14 +63,14 @@ pub async fn r_library_node_filter<'a>( filter: NodeFilterSort, ) -> MyResult<Either<DynLayoutPage<'a>, Json<NodePublic>>> { let node = T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))? .public; let node_ext = T_NODE_EXTENDED.get(db, id)?.unwrap_or_default(); let udata = T_USER_NODE - .get(&db, &(session.user.name.as_str(), id))? + .get(db, &(session.user.name.as_str(), id))? .unwrap_or_default(); if *aj { @@ -80,7 +80,7 @@ pub async fn r_library_node_filter<'a>( let mut children = node .children .iter() - .map(|c| Ok(db.get_node_with_userdata(c, &session)?)) + .map(|c| db.get_node_with_userdata(c, &session)) .collect::<anyhow::Result<Vec<_>>>()? .into_iter() .collect(); @@ -113,7 +113,7 @@ pub async fn r_library_node_filter<'a>( Ok(Either::Left(LayoutPage { title: node.title.clone().unwrap_or_default(), content: markup::new! { - @NodePage { node: &node, id: &id, udata: &udata, children: &children, path: &path, filter: &filter, node_ext: &node_ext } + @NodePage { node: &node, id, udata: &udata, children: &children, path: &path, filter: &filter, node_ext: &node_ext } }, ..Default::default() })) @@ -220,10 +220,10 @@ markup::define! { } .title { @pe.person.name br; - @if let Some(c) = pe.characters.get(0) { + @if let Some(c) = pe.characters.first() { .subtitle { @c } } - @if let Some(c) = pe.jobs.get(0) { + @if let Some(c) = pe.jobs.first() { .subtitle { @c } } } @@ -359,11 +359,8 @@ impl MediaInfoExt for MediaInfo { fn resolution_name(&self) -> &'static str { let mut maxdim = 0; for t in &self.tracks { - match &t.kind { - SourceTrackKind::Video { width, height, .. } => { - maxdim = maxdim.max(*width.max(height)) - } - _ => (), + if let SourceTrackKind::Video { width, height, .. } = &t.kind { + maxdim = maxdim.max(*width.max(height)) } } diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs index 69445ed..55e1303 100644 --- a/server/src/routes/ui/player.rs +++ b/server/src/routes/ui/player.rs @@ -108,9 +108,9 @@ pub fn r_player<'a>( let spec = StreamSpec { track: None .into_iter() - .chain(conf.v.into_iter()) - .chain(conf.a.into_iter()) - .chain(conf.s.into_iter()) + .chain(conf.v) + .chain(conf.a) + .chain(conf.s) .collect::<Vec<_>>(), format: StreamFormat::Matroska, webm: Some(true), @@ -131,7 +131,6 @@ pub fn r_player<'a>( } @conf }, - ..Default::default() })) } diff --git a/server/src/routes/ui/search.rs b/server/src/routes/ui/search.rs index 4ea5716..5ca4b51 100644 --- a/server/src/routes/ui/search.rs +++ b/server/src/routes/ui/search.rs @@ -49,12 +49,12 @@ pub async fn r_search<'a>( let id = doc.get_first(db.node_index.id).unwrap().as_str().unwrap(); let node = T_NODE - .get(&db, id)? + .get(db, id)? .only_if_permitted(&session.user.permissions) .ok_or(anyhow!("node does not exist"))? .public; let udata = T_USER_NODE - .get(&db, &(session.user.name.as_str(), id))? + .get(db, &(session.user.name.as_str(), id))? .unwrap_or_default(); results.push((id.to_owned(), node, udata)); diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs index a779b15..88f262b 100644 --- a/server/src/routes/ui/sort.rs +++ b/server/src/routes/ui/sort.rs @@ -220,7 +220,7 @@ markup::define! { .category { h3 { @cname } @for (value, label) in *cat { - label { input[type="checkbox", name="filter_kind", value=value, checked=f.filter_kind.as_ref().map(|k|k.contains(&value)).unwrap_or(true)]; @label } br; + label { input[type="checkbox", name="filter_kind", value=value, checked=f.filter_kind.as_ref().map(|k|k.contains(value)).unwrap_or(true)]; @label } br; } } } |