aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-27 21:48:22 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-27 21:48:22 +0100
commita742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f (patch)
tree49ba83ef7aec7b2bf4ff61b41c621696c45c6e95 /server
parent04e3ebfdda613be0e58290a49536116cc57ad147 (diff)
downloadjellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar
jellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar.bz2
jellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar.zst
clippy
Diffstat (limited to 'server')
-rw-r--r--server/src/library.rs13
-rw-r--r--server/src/main.rs4
-rw-r--r--server/src/routes/stream.rs14
-rw-r--r--server/src/routes/ui/account/session.rs3
-rw-r--r--server/src/routes/ui/node.rs5
-rw-r--r--server/src/routes/ui/player.rs6
6 files changed, 20 insertions, 25 deletions
diff --git a/server/src/library.rs b/server/src/library.rs
index 6cb6c3a..258569e 100644
--- a/server/src/library.rs
+++ b/server/src/library.rs
@@ -39,9 +39,9 @@ pub struct Item {
}
impl Library {
- pub fn open(path: &PathBuf) -> anyhow::Result<Self> {
+ pub fn open(path: &Path) -> anyhow::Result<Self> {
Ok(Self {
- root: Node::from_path(path.clone(), PathBuf::new(), true)
+ root: Node::from_path(path.to_path_buf(), PathBuf::new(), true)
.context("indexing root")?
.ok_or(anyhow!("root need directory.json"))?,
})
@@ -51,10 +51,10 @@ impl Library {
}
pub fn nested(&self, path: &str) -> anyhow::Result<Arc<Node>> {
let mut n = self.root.clone();
- if path == "" {
+ if path.is_empty() {
return Ok(n);
}
- for seg in path.split("/") {
+ for seg in path.split('/') {
n = n
.get_directory()?
.child_by_ident(seg)
@@ -111,7 +111,7 @@ impl Node {
.read_dir()?
.filter_map(|e| {
let e = e.unwrap();
- if (e.path().extension() == None || e.metadata().unwrap().is_dir())
+ if (e.path().extension().is_none() || e.metadata().unwrap().is_dir())
&& !e.path().ends_with("directory.json")
{
Some(e.path())
@@ -124,7 +124,6 @@ impl Node {
.context(format!("loading {e:?}"))
.transpose()
})
- .into_iter()
.collect::<anyhow::Result<Vec<_>>>()?;
Ok(Some(
@@ -149,7 +148,7 @@ impl Node {
.to_string();
Ok(Some(
Node::Item(Arc::new(Item {
- fs_path: path.clone(),
+ fs_path: path,
lib_path: lib_path.join(identifier.clone()),
info: data,
identifier,
diff --git a/server/src/main.rs b/server/src/main.rs
index 00543ce..250e29c 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -18,7 +18,7 @@ pub mod database;
pub mod library;
pub mod routes;
-pub static CONF: Lazy<GlobalConfig> = Lazy::new(|| load_global_config());
+pub static CONF: Lazy<GlobalConfig> = Lazy::new(load_global_config);
#[launch]
fn rocket() -> _ {
@@ -28,7 +28,7 @@ fn rocket() -> _ {
.init();
#[cfg(feature = "bypass-auth")]
- warn!("authentification bypass enabled");
+ log::warn!("authentification bypass enabled");
let remuxer = RemuxerContext::new();
let library = Library::open(&CONF.library_path).unwrap();
diff --git a/server/src/routes/stream.rs b/server/src/routes/stream.rs
index 469ad07..e7547bd 100644
--- a/server/src/routes/stream.rs
+++ b/server/src/routes/stream.rs
@@ -17,15 +17,15 @@ use rocket::{
};
use std::{
ops::{Deref, Range},
- path::PathBuf,
+ path::{PathBuf, Path},
};
use tokio::io::{duplex, DuplexStream};
use tokio_util::io::SyncIoBridge;
-pub fn stream_uri(path: &PathBuf, tracks: &Vec<u64>, webm: bool) -> String {
+pub fn stream_uri(path: &Path, tracks: &[u64], webm: bool) -> String {
format!(
"/stream/{}?tracks={}&webm={}",
- path.to_str().unwrap().to_string(),
+ path.to_str().unwrap(),
tracks
.iter()
.map(|v| format!("{v}"))
@@ -54,9 +54,8 @@ pub fn r_stream(
.get_item()?;
let remuxer = remuxer.deref().clone();
let tracks = tracks
- .split(",")
+ .split(',')
.map(|e| e.parse().map_err(|_| anyhow!("invalid number")))
- .into_iter()
.collect::<Result<Vec<_>, _>>()?;
let b = SyncIoBridge::new(b);
@@ -119,10 +118,10 @@ impl RequestRange {
Ok(Self(
s.strip_prefix("bytes=")
.ok_or(anyhow!("prefix expected"))?
- .split(",")
+ .split(',')
.map(|s| {
let (l, r) = s
- .split_once("-")
+ .split_once('-')
.ok_or(anyhow!("range delimeter missing"))?;
let km = |s: &str| {
if s.is_empty() {
@@ -133,7 +132,6 @@ impl RequestRange {
};
Ok(km(l)?..km(r)?)
})
- .into_iter()
.collect::<Result<Vec<_>>>()?,
))
}
diff --git a/server/src/routes/ui/account/session.rs b/server/src/routes/ui/account/session.rs
index 3457d41..6059311 100644
--- a/server/src/routes/ui/account/session.rs
+++ b/server/src/routes/ui/account/session.rs
@@ -6,7 +6,6 @@
use crate::{
database::{Database, User},
routes::ui::error::MyError,
- CONF,
};
use anyhow::anyhow;
use rocket::{
@@ -29,7 +28,7 @@ impl Session {
#[cfg(not(feature = "bypass-auth"))]
let username = cookie.value();
#[cfg(feature = "bypass-auth")]
- let username = CONF.admin_username.to_string();
+ let username = crate::CONF.admin_username.to_string();
let db = req.guard::<&State<Database>>().await.unwrap();
let user = db
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index f216df2..dd98a61 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -26,10 +26,9 @@ pub async fn r_library_node(
) -> Result<DynLayoutPage<'_>, MyError> {
let node = library
.nested_path(&path)
- .context("retrieving library node")?
- .clone();
+ .context("retrieving library node")?;
Ok(LayoutPage {
- title: format!("{}", node.title()),
+ title: node.title().to_string(),
content: markup::new! {
@NodePage { node: node.clone() }
},
diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs
index 0fc0364..866787a 100644
--- a/server/src/routes/ui/player.rs
+++ b/server/src/routes/ui/player.rs
@@ -13,9 +13,9 @@ use crate::{
};
use jellycommon::SourceTrackKind;
use rocket::{get, FromForm, State};
-use std::{path::PathBuf, sync::Arc};
+use std::{path::{PathBuf, Path}, sync::Arc};
-pub fn player_uri(path: &PathBuf) -> String {
+pub fn player_uri(path: &Path) -> String {
format!("/player/{}", path.to_str().unwrap())
}
@@ -36,7 +36,7 @@ pub fn r_player(
) -> MyResult<DynLayoutPage<'_>> {
let item = library.nested_path(&path)?.get_item()?;
if conf.a.is_none() && conf.v.is_none() && conf.s.is_none() {
- return player_conf(item.clone());
+ return player_conf(item);
}
let tracks = []