Skip to content

Commit

Permalink
file name fix
Browse files Browse the repository at this point in the history
  • Loading branch information
acedward committed Dec 23, 2024
1 parent b6afbfe commit 7fc2256
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ pub fn app_files_routes(
.or(delete_file_route)
}

pub fn safe_folder_name(tool_router_key: &str) -> String {
pub fn safe_folder_name(tool_router_key: &str, is_file_name: bool) -> String {
tool_router_key
.chars()
.map(|c| {
if c.is_ascii_alphanumeric() || c == '-' || c == '_' {
if c.is_ascii_alphanumeric() || c == '-' || c == '_' || (is_file_name && c == '.') {
c
} else {
'_'
Expand Down Expand Up @@ -109,7 +109,7 @@ pub async fn upload_file_handler(
bytes.extend_from_slice(chunk.chunk());
}
file_name = String::from_utf8_lossy(&bytes).into_owned();
file_name = safe_folder_name(&file_name);
file_name = safe_folder_name(&file_name, true);
}
"file" => {
// Read file data
Expand Down Expand Up @@ -140,8 +140,8 @@ pub async fn upload_file_handler(
sender
.send(NodeCommand::V2ApiUploadAppFile {
bearer,
tool_id: safe_folder_name(&tool_id),
app_id: safe_folder_name(&app_id),
tool_id: safe_folder_name(&tool_id, false),
app_id: safe_folder_name(&app_id, false),
file_name,
file_data: file_data.unwrap(),
res: res_sender,
Expand Down Expand Up @@ -222,7 +222,7 @@ pub async fn update_file_handler(
while let Ok(Some(chunk)) = stream.try_next().await {
bytes.extend_from_slice(chunk.chunk());
}
new_name = Some(safe_folder_name(&String::from_utf8_lossy(&bytes).into_owned()));
new_name = Some(safe_folder_name(&String::from_utf8_lossy(&bytes).into_owned(), true));
}
_ => {}
}
Expand All @@ -241,8 +241,8 @@ pub async fn update_file_handler(
sender
.send(NodeCommand::V2ApiUpdateAppFile {
bearer,
tool_id: safe_folder_name(&tool_id),
app_id: safe_folder_name(&app_id),
tool_id: safe_folder_name(&tool_id, false),
app_id: safe_folder_name(&app_id, false),
file_name,
new_name,
file_data,
Expand Down Expand Up @@ -302,8 +302,8 @@ pub async fn get_file_handler(
sender
.send(NodeCommand::V2ApiGetAppFile {
bearer,
tool_id: safe_folder_name(&tool_id),
app_id: safe_folder_name(&app_id),
tool_id: safe_folder_name(&tool_id, false),
app_id: safe_folder_name(&app_id, false),
file_name,
res: res_sender,
})
Expand Down Expand Up @@ -351,8 +351,8 @@ pub async fn list_files_handler(
sender
.send(NodeCommand::V2ApiListAppFiles {
bearer,
tool_id: safe_folder_name(&tool_id),
app_id: safe_folder_name(&app_id),
tool_id: safe_folder_name(&tool_id, false),
app_id: safe_folder_name(&app_id, false),
res: res_sender,
})
.await
Expand Down Expand Up @@ -409,8 +409,8 @@ pub async fn delete_file_handler(
sender
.send(NodeCommand::V2ApiDeleteAppFile {
bearer,
tool_id: safe_folder_name(&tool_id),
app_id: safe_folder_name(&app_id),
tool_id: safe_folder_name(&tool_id, false),
app_id: safe_folder_name(&app_id, false),
file_name,
res: res_sender,
})
Expand Down

0 comments on commit 7fc2256

Please sign in to comment.