Fix download bug

This commit is contained in:
2024-05-31 15:25:27 +02:00
parent 2448305302
commit c64b6c16c0
2 changed files with 8 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
use std::{fs::File, io::Seek}; use std::{fs::File, io::Write};
use smallvec::SmallVec; use smallvec::SmallVec;
use smartstring::alias::String as SmartString; use smartstring::alias::String as SmartString;
@@ -134,7 +134,7 @@ pub async fn create_archive(
Err(err) => return Err(Box::new(err)), Err(err) => return Err(Box::new(err)),
}; };
archive_result.rewind().unwrap(); archive_result.flush()?;
Ok((archive_result, bytes_count)) Ok((archive_result, bytes_count))
} }

View File

@@ -10,7 +10,7 @@ use axum::{
Json, Router, Json, Router,
}; };
use axum_prometheus::PrometheusMetricLayer; use axum_prometheus::PrometheusMetricLayer;
use moka::future::Cache; use moka::{future::Cache, notification::RemovalCause};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use tokio::fs::File; use tokio::fs::File;
use tokio_util::io::ReaderStream; use tokio_util::io::ReaderStream;
@@ -28,8 +28,12 @@ pub static TASK_RESULTS: Lazy<Cache<String, Task>> = Lazy::new(|| {
Cache::builder() Cache::builder()
.time_to_idle(Duration::from_secs(3 * 60 * 60)) .time_to_idle(Duration::from_secs(3 * 60 * 60))
.max_capacity(2048) .max_capacity(2048)
.async_eviction_listener(|_key, value: Task, _reason| { .async_eviction_listener(|_key, value: Task, reason| {
Box::pin(async move { Box::pin(async move {
if reason == RemovalCause::Replaced {
return;
}
let _ = tokio::fs::remove_file(format!("/tmp/{}", value.id)).await; let _ = tokio::fs::remove_file(format!("/tmp/{}", value.id)).await;
}) })
}) })