refactor: Add lints to use in future and fix some

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-12-03 07:33:32 +11:00
parent f7735fa88a
commit 51b469962a
7 changed files with 387 additions and 23 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf, time::Instant};
use std::{collections::HashMap, hash::RandomState, time::Instant};
use droplet_rs::versions::{create_backend_constructor, types::VersionBackend};
use reqwest::StatusCode;
@@ -9,7 +9,7 @@ use crate::{
util::ErrorOption,
};
pub async fn create_download_context<'a>(
pub async fn create_download_context(
init_data: &AppInitData,
game_id: String,
version_name: String,
@@ -21,7 +21,7 @@ pub async fn create_download_context<'a>(
let mut chunk_lookup_table = HashMap::with_capacity_and_hasher(
context.manifest.values().map(|v| v.ids.len()).sum(),
Default::default(),
RandomState::default(),
);
for (path, file_chunks) in context.manifest {
+12 -11
View File
@@ -4,7 +4,7 @@ use droplet_rs::versions::types::{MinimumFileObject, VersionBackend, VersionFile
use reqwest::header;
use simple_logger::SimpleLogger;
use std::{
collections::HashMap, env::set_current_dir, path::PathBuf, str::FromStr, sync::Arc,
collections::HashMap, env::set_current_dir, path::PathBuf, str::FromStr as _, sync::Arc,
time::Instant,
};
use tokio_util::io::ReaderStream;
@@ -101,7 +101,7 @@ async fn set_token(
let valid_library_sources = filter_library_sources(library_sources);
set_generated_token(state, token, valid_library_sources)?;
set_generated_token(&state, token, valid_library_sources)?;
info!("connected to drop server successfully");
@@ -139,7 +139,7 @@ fn initialise_logger() {
}
async fn acquire_permit<'a>() -> SemaphorePermit<'a> {
GLOBAL_CONTEXT_SEMAPHORE
return GLOBAL_CONTEXT_SEMAPHORE
.acquire()
.await
.expect("failed to acquire semaphore")
@@ -164,12 +164,12 @@ async fn get_file_reader(
.backend
.reader(
&VersionFile {
relative_filename: relative_filename.to_string(),
relative_filename: relative_filename.clone(),
permission: 0,
size: 0,
},
start.try_into().unwrap(),
end.try_into().unwrap(),
start as u64,
end as u64,
)
.await
.map_err(|v| {
@@ -221,14 +221,15 @@ async fn healthcheck(State(state): State<Arc<AppState>>) -> StatusCode {
if !initialised {
return StatusCode::SERVICE_UNAVAILABLE;
}
return StatusCode::OK;
StatusCode::OK
}
fn check_token_exists(state: &Arc<AppState>, payload: &TokenPayload) -> bool {
if let Some(existing_data) = state.token.get() {
if existing_data.token != payload.token {
panic!("already set up but provided with a different token");
}
assert!(
existing_data.token == payload.token,
"already set up but provided with a different token"
);
return true;
}
false
@@ -261,7 +262,7 @@ fn filter_library_sources(
.collect()
}
fn set_generated_token(
state: Arc<AppState>,
state: &Arc<AppState>,
token: String,
libraries: HashMap<String, (PathBuf, LibraryBackend)>,
) -> Result<(), StatusCode> {
+5 -5
View File
@@ -35,7 +35,7 @@ static REMOTE_URL: LazyLock<Url> = LazyLock::new(|| {
.map_or("http://localhost:3000", |v| v),
)
.expect("failed to parse URL");
info!("using Drop server url {}", url);
info!("using Drop server url {url}");
url
});
@@ -50,7 +50,7 @@ pub async fn fetch_download_context(
game: game_id,
version: version_name,
})
.header("Authorization", format!("Bearer {}", token))
.header("Authorization", format!("Bearer {token}"))
.send()
.await?;
@@ -65,7 +65,7 @@ pub async fn fetch_download_context(
context_response
.text()
.await
.unwrap_or("(failed to read body)".to_string())
.unwrap_or("(failed to read body)".to_owned())
)
.into());
}
@@ -92,7 +92,7 @@ pub struct LibrarySource {
pub async fn fetch_library_sources(token: &String) -> Result<Vec<LibrarySource>> {
let source_response = CLIENT
.get(REMOTE_URL.join("/api/v1/admin/library/sources")?)
.header("Authorization", format!("Bearer {}", token))
.header("Authorization", format!("Bearer {token}"))
.send()
.await?;
@@ -103,7 +103,7 @@ pub async fn fetch_library_sources(token: &String) -> Result<Vec<LibrarySource>>
source_response
.text()
.await
.unwrap_or("(failed to read body)".to_string())
.unwrap_or("(failed to read body)".to_owned())
));
}
+1 -1
View File
@@ -30,7 +30,7 @@ impl From<ErrorOption> for StatusCode {
Ok(status) => status,
Err(err) => {
error!("{err:?}");
StatusCode::INTERNAL_SERVER_ERROR
Self::INTERNAL_SERVER_ERROR
}
}
}