aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db/files.rs14
-rw-r--r--src/db/mod.rs12
-rw-r--r--src/db/utils.rs3
-rw-r--r--src/model.rs6
4 files changed, 13 insertions, 22 deletions
diff --git a/src/db/files.rs b/src/db/files.rs
index 995a2ed..f9b669d 100644
--- a/src/db/files.rs
+++ b/src/db/files.rs
@@ -1,7 +1,6 @@
use chrono::{DateTime, Local};
use tokio_rusqlite::{named_params, Connection, Result};
-use crate::db::utils;
use crate::model::{decode_datetime, encode_datetime, File};
pub async fn insert(conn: &Connection, file: File) -> Result<()> {
@@ -20,7 +19,6 @@ pub async fn insert(conn: &Connection, file: File) -> Result<()> {
":content_length": file.content_length
],
)
- .map_err(tokio_rusqlite::Error::Rusqlite)
})
.await
.map(|_| ())
@@ -54,12 +52,16 @@ pub async fn get(conn: &Connection, file_id: impl Into<String>) -> Result<Option
expires_at,
content_length,
})),
- _ => Err(utils::rusqlite_other_error(format!(
- "Error decoding datetime: {expires_at}"
- ))),
+ _ => {
+ log::error!("Error decoding datetime: {expires_at}");
+ Ok(None)
+ }
}
}
- Some(_) => Err(utils::rusqlite_other_error("Error reading file in DB")),
+ Some(_) => {
+ log::error!("Error reading file in DB");
+ Ok(None)
+ },
None => Ok(None),
}
})
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 37769d2..c3c2258 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -3,7 +3,6 @@ use rusqlite_migration::{Migrations, M};
use tokio_rusqlite::Connection;
pub mod files;
-mod utils;
pub async fn init(path: &str) -> Result<Connection> {
let connection = Connection::open(path)
@@ -23,11 +22,7 @@ async fn apply_migrations(conn: &Connection) -> Result<()> {
]);
Ok(conn
- .call(move |conn| {
- migrations
- .to_latest(conn)
- .map_err(|migration_err| tokio_rusqlite::Error::Other(Box::new(migration_err)))
- })
+ .call(move |conn| migrations .to_latest(conn))
.await?)
}
@@ -39,9 +34,6 @@ async fn set_pragma(
let key = key.into();
let value = value.into();
Ok(conn
- .call(move |conn| {
- conn.pragma_update(None, &key, &value)
- .map_err(tokio_rusqlite::Error::Rusqlite)
- })
+ .call(move |conn| conn.pragma_update(None, &key, &value))
.await?)
}
diff --git a/src/db/utils.rs b/src/db/utils.rs
deleted file mode 100644
index 0b3e029..0000000
--- a/src/db/utils.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-pub fn rusqlite_other_error(msg: impl Into<String>) -> tokio_rusqlite::Error {
- tokio_rusqlite::Error::Other(msg.into().into())
-}
diff --git a/src/model.rs b/src/model.rs
index 12b0433..e7cbc6d 100644
--- a/src/model.rs
+++ b/src/model.rs
@@ -1,5 +1,5 @@
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
-use rand::{distributions::Alphanumeric, Rng};
+use rand::RngExt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct File {
@@ -23,8 +23,8 @@ pub fn local_time() -> DateTime<Local> {
const FILE_ID_CHARS: usize = 28;
pub fn generate_file_id() -> String {
- rand::thread_rng()
- .sample_iter(&Alphanumeric)
+ rand::rng()
+ .sample_iter(rand::distr::Alphanumeric)
.take(FILE_ID_CHARS)
.map(char::from)
.collect()