Switch to time crate, add file sizes (#329)

* Switch to time crate, add file sizes

* Update deps, adjust pack format

* Run formatter, fix clippy
This commit is contained in:
Geometrically
2022-03-29 19:35:09 -07:00
committed by GitHub
parent a3d5479878
commit 80e00a80d5
38 changed files with 563 additions and 318 deletions

View File

@@ -7,10 +7,10 @@ use crate::util::auth::get_github_user_from_token;
use actix_web::http::StatusCode;
use actix_web::web::{scope, Data, Query, ServiceConfig};
use actix_web::{get, HttpResponse};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use thiserror::Error;
use time::OffsetDateTime;
pub fn config(cfg: &mut ServiceConfig) {
cfg.service(scope("auth").service(auth_callback).service(init));
@@ -145,10 +145,10 @@ pub async fn auth_callback(
.await?;
if let Some(result) = result_option {
let now = Utc::now();
let duration = result.expires.signed_duration_since(now);
let now = OffsetDateTime::now_utc();
let duration = now - result.expires;
if duration.num_seconds() < 0 {
if duration.whole_seconds() < 0 {
return Err(AuthorizationError::InvalidCredentials);
}
@@ -225,7 +225,7 @@ pub async fn auth_callback(
email: user.email,
avatar_url: Some(user.avatar_url),
bio: user.bio,
created: Utc::now(),
created: OffsetDateTime::now_utc(),
role: Role::Developer.to_string(),
}
.insert(&mut transaction)

View File

@@ -108,7 +108,7 @@ pub async fn maven_metadata(
.map(|x| x.version_number.clone())
.collect::<Vec<_>>(),
},
last_updated: data.inner.updated.format("%Y%m%d%H%M%S").to_string(),
last_updated: data.inner.updated.format("%Y%m%d%H%M%S"),
},
};

View File

@@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use std::sync::Arc;
use thiserror::Error;
use time::OffsetDateTime;
use validator::Validate;
#[derive(Error, Debug)]
@@ -498,7 +499,7 @@ pub async fn project_create_inner(
featured: item.featured,
title: item.title.clone(),
description: item.description.clone(),
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
});
continue;
@@ -693,7 +694,7 @@ pub async fn project_create_inner(
.collect(),
};
let now = chrono::Utc::now();
let now = OffsetDateTime::now_utc();
let response = crate::models::projects::Project {
id: project_id,

View File

@@ -17,6 +17,7 @@ use futures::StreamExt;
use serde::{Deserialize, Serialize};
use sqlx::{PgPool, Row};
use std::sync::Arc;
use time::OffsetDateTime;
use validator::Validate;
#[get("search")]
@@ -1134,7 +1135,7 @@ pub async fn add_gallery_item(
featured: item.featured,
title: item.title,
description: item.description,
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
}
.insert(&mut transaction)
.await?;

View File

@@ -8,6 +8,7 @@ use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
use futures::StreamExt;
use serde::Deserialize;
use sqlx::PgPool;
use time::OffsetDateTime;
#[derive(Deserialize)]
pub struct CreateReport {
@@ -59,7 +60,7 @@ pub async fn report_create(
user_id: None,
body: new_report.body.clone(),
reporter: current_user.id.into(),
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
};
match new_report.item_type {
@@ -108,7 +109,7 @@ pub async fn report_create(
item_type: new_report.item_type.clone(),
reporter: current_user.id,
body: new_report.body.clone(),
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
}))
}

View File

@@ -7,6 +7,7 @@ use crate::util::auth::check_is_admin_from_headers;
use actix_web::{delete, get, put, web, HttpRequest, HttpResponse};
use models::categories::{Category, GameVersion, Loader};
use sqlx::PgPool;
use time::OffsetDateTime;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
@@ -201,7 +202,8 @@ pub async fn loader_delete(
pub struct GameVersionQueryData {
pub version: String,
pub version_type: String,
pub date: chrono::DateTime<chrono::Utc>,
#[serde(with = "crate::util::time_ser")]
pub date: OffsetDateTime,
pub major: bool,
}
@@ -241,7 +243,7 @@ pub async fn game_version_list(
pub struct GameVersionData {
#[serde(rename = "type")]
type_: String,
date: Option<chrono::DateTime<chrono::Utc>>,
date: Option<OffsetDateTime>,
}
#[put("game_version/{name}")]

View File

@@ -7,10 +7,10 @@ use crate::util::auth::{
};
use actix_web::web;
use actix_web::{get, post, HttpRequest, HttpResponse};
use chrono::{DateTime, Utc};
use futures::StreamExt;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use time::OffsetDateTime;
#[derive(Serialize, Deserialize)]
pub struct Report {
@@ -20,7 +20,8 @@ pub struct Report {
pub item_type: ItemType,
pub reporter: UserId,
pub body: String,
pub created: DateTime<Utc>,
#[serde(with = "crate::util::time_ser")]
pub created: OffsetDateTime,
}
#[derive(Serialize, Deserialize, Clone)]
@@ -92,7 +93,7 @@ pub async fn report_create(
user_id: None,
body: new_report.body.clone(),
reporter: current_user.id.into(),
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
};
match new_report.item_type {
@@ -141,7 +142,7 @@ pub async fn report_create(
item_type: new_report.item_type.clone(),
reporter: current_user.id,
body: new_report.body.clone(),
created: chrono::Utc::now(),
created: OffsetDateTime::now_utc(),
}))
}

View File

@@ -9,10 +9,10 @@ use crate::routes::ApiError;
use crate::util::auth::get_user_from_headers;
use crate::{database, models};
use actix_web::{delete, get, web, HttpRequest, HttpResponse};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use std::sync::Arc;
use time::OffsetDateTime;
/// A specific version of a mod
#[derive(Serialize, Deserialize)]
@@ -25,7 +25,8 @@ pub struct LegacyVersion {
pub version_number: String,
pub changelog: String,
pub changelog_url: Option<String>,
pub date_published: DateTime<Utc>,
#[serde(with = "crate::util::time_ser")]
pub date_published: OffsetDateTime,
pub downloads: u32,
pub version_type: VersionType,
pub files: Vec<VersionFile>,

View File

@@ -20,6 +20,7 @@ use actix_web::{post, HttpRequest, HttpResponse};
use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use time::OffsetDateTime;
use validator::Validate;
#[derive(Serialize, Deserialize, Validate, Clone)]
@@ -398,7 +399,7 @@ async fn version_create_inner(
version_number: builder.version_number.clone(),
changelog: builder.changelog.clone(),
changelog_url: None,
date_published: chrono::Utc::now(),
date_published: OffsetDateTime::now_utc(),
downloads: 0,
version_type: version_data.release_channel,
files: builder
@@ -422,6 +423,7 @@ async fn version_create_inner(
url: file.url.clone(),
filename: file.filename.clone(),
primary: file.primary,
size: file.size,
})
.collect::<Vec<_>>(),
dependencies: version_data.dependencies,
@@ -719,6 +721,7 @@ pub async fn upload_file(
&& version_files.iter().all(|x| !x.primary)
&& !ignore_primary)
|| force_primary,
size: upload_data.content_length,
});
Ok(())