Skip to content

Commit d19a088

Browse files
metamejoepio
authored andcommitted
possibly fix issue with :
1 parent 38f44d5 commit d19a088

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

server/src/handlers/download.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ pub async fn handle_download(
2929

3030
let for_agent = get_client_agent(headers, &appstate, subject.clone())?;
3131
tracing::info!("handle_download: {}", subject);
32-
let resource = store.get_resource_extended(&subject, false, &for_agent)?;
32+
let resource = store.get_resource_extended(&urlencoding::encode(&subject).into_owned(), false, &for_agent)?;
3333
let file_id = resource
3434
.get(urls::INTERNAL_ID)
3535
.map_err(|e| format!("Internal ID of file could not be resolved. {}", e))?
3636
.to_string();
37-
let is_s3 = file_id.starts_with("s3-");
37+
let is_s3 = file_id.starts_with("s3:");
3838
if is_s3 {
3939
signed_url_redirect_handler(file_id.as_str(), &req, &appstate).await
4040
} else {
@@ -47,8 +47,10 @@ pub fn download_file_handler_partial(
4747
req: &HttpRequest,
4848
appstate: &AppState,
4949
) -> AtomicServerResult<HttpResponse> {
50+
println!("{file_id:?}");
51+
let fs_file_id = file_id.strip_prefix("fs:").unwrap_or(file_id);
5052
let mut file_path = appstate.config.uploads_path.clone();
51-
file_path.push(file_id.to_string());
53+
file_path.push(fs_file_id.to_string());
5254
let file = NamedFile::open(file_path)?;
5355
Ok(file.into_response(req))
5456
}

server/src/handlers/upload.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,16 @@ pub async fn upload_handler(
5656

5757
std::fs::create_dir_all(&appstate.config.uploads_path)?;
5858

59-
let is_s3 = appstate.config.opts.s3_bucket.is_some();
60-
let file_store = if is_s3 { "s3" } else { "fs" };
61-
let file_id = format!(
62-
"{}-{}-{}",
63-
file_store,
59+
let fs_file_id = format!(
60+
"{}-{}",
6461
now(),
6562
sanitize_filename::sanitize(filename)
6663
// Spacebars lead to very annoying bugs in browsers
6764
.replace(' ', "-")
6865
);
6966

7067
let mut file_path = appstate.config.uploads_path.clone();
71-
file_path.push(&file_id);
68+
file_path.push(&fs_file_id);
7269
let mut file = File::create(&file_path)?;
7370

7471
// Field in turn is stream of *Bytes* object
@@ -84,6 +81,9 @@ pub async fn upload_handler(
8481
.try_into()
8582
.map_err(|_e| "Too large")?;
8683

84+
let is_s3 = appstate.config.opts.s3_bucket.is_some();
85+
let file_store = if is_s3 { "s3" } else { "fs" };
86+
let file_id = format!("{}:{}", &file_store, &fs_file_id);
8787
if is_s3 {
8888
upload_object(&appstate, &file_id, &file_path).await?;
8989
fs::remove_file(&file_path)?;
@@ -176,16 +176,3 @@ async fn upload_object(
176176

177177
Ok(())
178178
}
179-
180-
#[cfg(test)]
181-
mod tests {
182-
use super::*;
183-
184-
#[actix_web::test]
185-
async fn upload_object_works() {
186-
let mut file = File::create(&"/tmp/test").unwrap();
187-
file.write_all("it works!".as_bytes()).unwrap();
188-
let _ = upload_object(&"it-works", file).await;
189-
assert!(true);
190-
}
191-
}

0 commit comments

Comments
 (0)