fix(server): return the correct file on multiple files with same name (#234)

* fix(server): file not found, even though on server and not expired

* test: rename test
This commit is contained in:
Helmut K. C. Tessarek 2024-02-09 15:38:33 -05:00 committed by GitHub
parent e06c18279e
commit 8e6393c6f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,9 @@
[server]
address = "127.0.0.1:8000"
max_content_length = "10MB"
upload_path = "./upload"
[paste]
default_extension = "txt"
duplicate_files = true
delete_expired_files = { enabled = true, interval = "1h" }

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
content="test data"
setup() {
echo "$content" > file
}
run_test() {
file_url=$(curl -s -F "file=@file" -H "expire:2s" localhost:8000)
file_url=$(curl -s -F "file=@file" -H "expire:1s" localhost:8000)
sleep 2
file_url=$(curl -s -F "file=@file" -H "expire:1m" localhost:8000)
test "$content" = "$(curl -s $file_url)"
}
teardown() {
rm file
rm -r upload
}

View File

@ -37,7 +37,7 @@ pub fn glob_match_file(mut path: PathBuf) -> Result<PathBuf, ActixError> {
);
if let Some(glob_path) = glob(&format!("{}.[0-9]*", path.to_string_lossy()))
.map_err(error::ErrorInternalServerError)?
.next()
.last()
{
let glob_path = glob_path.map_err(error::ErrorInternalServerError)?;
if let Some(extension) = glob_path