mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-16 06:11:42 -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
|
let target_session = store
|
||||||
.sessions
|
.sessions
|
||||||
.iter_mut()
|
.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 {
|
match target_session {
|
||||||
Some((_, 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
|
// Otherwise, just use whatever the Cookie might have
|
||||||
match req.cookie("Session") {
|
match req.cookie("Session") {
|
||||||
Some(cookie) => match cookie.value().parse::<u32>() {
|
Some(cookie) => cookie.value().parse::<u32>().ok(),
|
||||||
Ok(id) => Some(id),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
tracing::warn!("Session was not provided in cookie or depot");
|
tracing::warn!("Session was not provided in cookie or depot");
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ impl Session {
|
|||||||
"{}-{:08x}{}{}",
|
"{}-{:08x}{}{}",
|
||||||
exe.name,
|
exe.name,
|
||||||
token,
|
token,
|
||||||
if exe.extension.len() > 0 { "." } else { "" },
|
if !exe.extension.is_empty() { "." } else { "" },
|
||||||
exe.extension
|
exe.extension
|
||||||
),
|
),
|
||||||
last_used: chrono::Utc::now(),
|
last_used: chrono::Utc::now(),
|
||||||
@@ -55,7 +55,7 @@ impl Session {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.downloads.push(download);
|
self.downloads.push(download);
|
||||||
return self.downloads.last().unwrap();
|
self.downloads.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a download from the session
|
// 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())));
|
let result = tx.send(Ok(Message::text(serde_json::to_string(&message).unwrap())));
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => return Err(anyhow::anyhow!("Error sending message: {}", e)),
|
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) {
|
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 pattern = "a".repeat(1024);
|
||||||
let key_start = search(&data, pattern.as_bytes(), 0).unwrap();
|
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(),
|
filename: path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
extension: extension.to_string(),
|
extension: extension.to_string(),
|
||||||
key_start: key_start,
|
key_start,
|
||||||
key_end: key_end,
|
key_end,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.executables.insert(exe_type.to_string(), exe);
|
self.executables.insert(exe_type.to_string(), exe);
|
||||||
@@ -183,7 +183,7 @@ impl State {
|
|||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return id;
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn executable_json(&self) -> Vec<ExecutableJson> {
|
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 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 {
|
if new_key.len() < self.key_end - self.key_start {
|
||||||
for i in self.key_start + new_key.len()..self.key_end {
|
for item in data.iter_mut().take(self.key_end).skip(self.key_start + new_key.len()) {
|
||||||
data[i] = b' ';
|
*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())
|
serde_json::from_value::<Vec<BuildLogEntry>>(build_logs_value.clone())
|
||||||
{
|
{
|
||||||
let mut filtered_logs = Vec::new();
|
let mut filtered_logs = Vec::new();
|
||||||
|
let starting_container_pattern =
|
||||||
|
regex::Regex::new(r"(?i)Starting\s+Container").unwrap();
|
||||||
|
|
||||||
for entry in build_logs {
|
for entry in build_logs {
|
||||||
// Check if we should stop at this message
|
// 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 "Build time" messages, include them
|
||||||
// For "Starting Container" messages, stop before them
|
// For "Starting Container" messages, stop before them
|
||||||
let clean_message = strip_ansi_codes(&entry.message);
|
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) {
|
if starting_container_pattern.is_match(&clean_message) {
|
||||||
// Stop before "Starting Container" 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 the pattern is empty
|
||||||
if pattern.len() == 0 {
|
if pattern.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user