fix panic when files table is empty

master
neri 1 year ago
parent a065787487
commit 95dacb20b4
  1. 1
      init-db.sql
  2. 8
      src/deleter.rs
  3. 2
      src/multipart.rs

@ -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;

@ -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

@ -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?);

Loading…
Cancel
Save