fix panic when files table is empty

This commit is contained in:
neri 2021-09-24 22:51:13 +02:00
parent a065787487
commit 95dacb20b4
3 changed files with 6 additions and 5 deletions

View File

@ -8,3 +8,4 @@ CREATE TABLE IF NOT EXISTS files (
);
ALTER TABLE files ADD COLUMN IF NOT EXISTS delete_on_download boolean;
ALTER TABLE files ALTER COLUMN delete_on_download set not null;

View File

@ -54,13 +54,13 @@ async fn delete_content(file_id: &str, files_dir: &Path) -> Result<(), std::io::
}
async fn wait_for_file_expiry(receiver: &Receiver<()>, db: &PgPool) {
let valid_till: Option<(NaiveDateTime,)> =
let valid_till: (Option<NaiveDateTime>,) =
sqlx::query_as("SELECT MIN(valid_till) as min from files")
.fetch_optional(db)
.fetch_one(db)
.await
.expect("could not fetch expiring files from database");
let next_timeout = match valid_till {
Some((valid_till,)) => valid_till.signed_duration_since(Local::now().naive_local()),
let next_timeout = match valid_till.0 {
Some(valid_till) => valid_till.signed_duration_since(Local::now().naive_local()),
None => Duration::days(1),
};
let positive_timeout = next_timeout

View File

@ -53,7 +53,7 @@ pub(crate) async fn parse_multipart(
size = create_file(file_name, field, config.max_file_size).await?;
}
"delete_on_download" => {
delete_on_download = dbg!(parse_string(name, field).await?) != "false";
delete_on_download = parse_string(name, field).await? != "false";
}
"password" => {
password = Some(parse_string(name, field).await?);