Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::config::Configuration;
use crate::databases::database::Database;
use crate::errors::ServiceError;
use crate::models::user::{UserClaims, UserCompact};
use crate::utils::time::current_time;
use crate::utils::clock::current_time;

pub struct AuthorizationService {
cfg: Arc<Configuration>,
Expand Down
2 changes: 1 addition & 1 deletion src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
use crate::models::tracker_key::TrackerKey;
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
use crate::utils::clock::current_time;
use crate::utils::hex::bytes_to_hex;
use crate::utils::time::current_time;

pub struct MysqlDatabase {
pub pool: MySqlPool,
Expand Down
2 changes: 1 addition & 1 deletion src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
use crate::models::tracker_key::TrackerKey;
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
use crate::utils::clock::current_time;
use crate::utils::hex::bytes_to_hex;
use crate::utils::time::current_time;

pub struct SqliteDatabase {
pub pool: SqlitePool,
Expand Down
2 changes: 1 addition & 1 deletion src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use crate::config::Configuration;
use crate::errors::ServiceError;
use crate::utils::time::current_time;
use crate::utils::clock::current_time;

pub struct MailerService {
cfg: Arc<Configuration>,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::errors::{ServiceError, ServiceResult};
use crate::mailer::VerifyClaims;
use crate::models::response::{OkResponse, TokenResponse};
use crate::models::user::UserAuthentication;
use crate::utils::clock::current_time;
use crate::utils::regex::validate_email_address;
use crate::utils::time::current_time;

pub fn init_routes(cfg: &mut web::ServiceConfig) {
cfg.service(
Expand Down
6 changes: 4 additions & 2 deletions src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct TorrentRecordV2 {
}

impl TorrentRecordV2 {
#[must_use]
pub fn from_v1_data(torrent: &TorrentRecordV1, torrent_info: &TorrentInfo, uploader: &UserRecordV1) -> Self {
Self {
torrent_id: torrent.torrent_id,
Expand All @@ -46,11 +47,12 @@ impl TorrentRecordV2 {
}
}

#[must_use]
pub fn convert_timestamp_to_datetime(timestamp: i64) -> String {
// The expected format in database is: 2022-11-04 09:53:57
// MySQL uses a DATETIME column and SQLite uses a TEXT column.

let naive_datetime = NaiveDateTime::from_timestamp(timestamp, 0);
let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp, 0).expect("Overflow of i64 seconds, very future!");
let datetime_again: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);

// Format without timezone
Expand All @@ -74,7 +76,7 @@ impl SqliteDatabaseV2_0_0 {
sqlx::migrate!("migrations/sqlite3")
.run(&self.pool)
.await
.expect("Could not run database migrations.")
.expect("Could not run database migrations.");
}

pub async fn reset_categories_sequence(&self) -> Result<SqliteQueryResult, DatabaseError> {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[must_use]
pub fn current_time() -> u64 {
u64::try_from(chrono::prelude::Utc::now().timestamp()).expect("timestamp should be positive")
}
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod clock;
pub mod hex;
pub mod parse_torrent;
pub mod regex;
pub mod time;
3 changes: 0 additions & 3 deletions src/utils/time.rs

This file was deleted.