mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-15 04:11:40 -06:00
refactor: apply clippy suggestions
This commit is contained in:
@@ -320,7 +320,7 @@ pub async fn notify(req: &mut Request, res: &mut Response) {
|
||||
let target_session = store
|
||||
.sessions
|
||||
.iter_mut()
|
||||
.find(|(_, session)| session.downloads.iter().find(|d| d.token == key).is_some());
|
||||
.find(|(_, session)| session.downloads.iter().any(|d| d.token == key));
|
||||
|
||||
match target_session {
|
||||
Some((_, session)) => {
|
||||
@@ -373,10 +373,7 @@ fn get_session_id(req: &Request, depot: &Depot) -> Option<u32> {
|
||||
|
||||
// Otherwise, just use whatever the Cookie might have
|
||||
match req.cookie("Session") {
|
||||
Some(cookie) => match cookie.value().parse::<u32>() {
|
||||
Ok(id) => Some(id),
|
||||
_ => None,
|
||||
},
|
||||
Some(cookie) => cookie.value().parse::<u32>().ok(),
|
||||
None => {
|
||||
tracing::warn!("Session was not provided in cookie or depot");
|
||||
None
|
||||
|
||||
@@ -47,7 +47,7 @@ impl Session {
|
||||
"{}-{:08x}{}{}",
|
||||
exe.name,
|
||||
token,
|
||||
if exe.extension.len() > 0 { "." } else { "" },
|
||||
if !exe.extension.is_empty() { "." } else { "" },
|
||||
exe.extension
|
||||
),
|
||||
last_used: chrono::Utc::now(),
|
||||
@@ -55,7 +55,7 @@ impl Session {
|
||||
};
|
||||
|
||||
self.downloads.push(download);
|
||||
return self.downloads.last().unwrap();
|
||||
self.downloads.last().unwrap()
|
||||
}
|
||||
|
||||
// Delete a download from the session
|
||||
@@ -81,8 +81,8 @@ impl Session {
|
||||
let result = tx.send(Ok(Message::text(serde_json::to_string(&message).unwrap())));
|
||||
|
||||
match result {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(e) => return Err(anyhow::anyhow!("Error sending message: {}", e)),
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(anyhow::anyhow!("Error sending message: {}", e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ impl State {
|
||||
}
|
||||
|
||||
pub fn add_executable(&mut self, exe_type: &str, exe_path: &str) {
|
||||
let data = std::fs::read(&exe_path).expect("Unable to read file");
|
||||
let data = std::fs::read(exe_path).expect("Unable to read file");
|
||||
|
||||
let pattern = "a".repeat(1024);
|
||||
let key_start = search(&data, pattern.as_bytes(), 0).unwrap();
|
||||
@@ -142,8 +142,8 @@ impl State {
|
||||
filename: path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
name: name.to_string(),
|
||||
extension: extension.to_string(),
|
||||
key_start: key_start,
|
||||
key_end: key_end,
|
||||
key_start,
|
||||
key_end,
|
||||
};
|
||||
|
||||
self.executables.insert(exe_type.to_string(), exe);
|
||||
@@ -183,7 +183,7 @@ impl State {
|
||||
.build(),
|
||||
);
|
||||
|
||||
return id;
|
||||
id
|
||||
}
|
||||
|
||||
pub fn executable_json(&self) -> Vec<ExecutableJson> {
|
||||
@@ -197,7 +197,7 @@ impl State {
|
||||
});
|
||||
}
|
||||
|
||||
return executables;
|
||||
executables
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,12 +222,12 @@ impl Executable {
|
||||
|
||||
// If the new key is shorter than the old key, we just write over the remaining data
|
||||
if new_key.len() < self.key_end - self.key_start {
|
||||
for i in self.key_start + new_key.len()..self.key_end {
|
||||
data[i] = b' ';
|
||||
for item in data.iter_mut().take(self.key_end).skip(self.key_start + new_key.len()) {
|
||||
*item = b' ';
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,8 @@ pub async fn fetch_build_logs() -> Result<crate::models::BuildLogs> {
|
||||
serde_json::from_value::<Vec<BuildLogEntry>>(build_logs_value.clone())
|
||||
{
|
||||
let mut filtered_logs = Vec::new();
|
||||
let starting_container_pattern =
|
||||
regex::Regex::new(r"(?i)Starting\s+Container").unwrap();
|
||||
|
||||
for entry in build_logs {
|
||||
// Check if we should stop at this message
|
||||
@@ -210,8 +212,6 @@ pub async fn fetch_build_logs() -> Result<crate::models::BuildLogs> {
|
||||
// For "Build time" messages, include them
|
||||
// For "Starting Container" messages, stop before them
|
||||
let clean_message = strip_ansi_codes(&entry.message);
|
||||
let starting_container_pattern =
|
||||
regex::Regex::new(r"(?i)Starting\s+Container").unwrap();
|
||||
|
||||
if starting_container_pattern.is_match(&clean_message) {
|
||||
// Stop before "Starting Container" message
|
||||
|
||||
@@ -7,7 +7,7 @@ pub(crate) fn search(buf: &[u8], pattern: &[u8], start_index: usize) -> Option<u
|
||||
}
|
||||
|
||||
// If the pattern is empty
|
||||
if pattern.len() == 0 {
|
||||
if pattern.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user