fix panic when files table is empty
This commit is contained in:
parent
a065787487
commit
95dacb20b4
|
@ -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 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) {
|
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")
|
sqlx::query_as("SELECT MIN(valid_till) as min from files")
|
||||||
.fetch_optional(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.expect("could not fetch expiring files from database");
|
.expect("could not fetch expiring files from database");
|
||||||
let next_timeout = match valid_till {
|
let next_timeout = match valid_till.0 {
|
||||||
Some((valid_till,)) => valid_till.signed_duration_since(Local::now().naive_local()),
|
Some(valid_till) => valid_till.signed_duration_since(Local::now().naive_local()),
|
||||||
None => Duration::days(1),
|
None => Duration::days(1),
|
||||||
};
|
};
|
||||||
let positive_timeout = next_timeout
|
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?;
|
size = create_file(file_name, field, config.max_file_size).await?;
|
||||||
}
|
}
|
||||||
"delete_on_download" => {
|
"delete_on_download" => {
|
||||||
delete_on_download = dbg!(parse_string(name, field).await?) != "false";
|
delete_on_download = parse_string(name, field).await? != "false";
|
||||||
}
|
}
|
||||||
"password" => {
|
"password" => {
|
||||||
password = Some(parse_string(name, field).await?);
|
password = Some(parse_string(name, field).await?);
|
||||||
|
|
Loading…
Reference in New Issue