Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix more
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Oct 10, 2023
1 parent d1e004d commit 1dc2557
Show file tree
Hide file tree
Showing 13 changed files with 625 additions and 794 deletions.
1,327 changes: 556 additions & 771 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sha2 = "0.9.9"
hmac = "0.11.0"
argon2 = { version = "0.5.0", features = ["std"] }
bitflags = { version = "2.4.0", features = ["serde"] }
bitflags-serde-legacy = "0.1.1"
hex = "0.4.3"
zxcvbn = "2.2.2"
totp-rs = { version = "5.0.2", features = ["gen_secret"] }
Expand Down Expand Up @@ -96,7 +97,7 @@ maxminddb = "0.23.0"
flate2 = "1.0.25"
tar = "0.4.38"

sentry = { version = "0.31.5", features = ["profiling"] }
sentry = { version = "0.31.5" }
sentry-actix = "0.31.5"

image = "0.24.6"
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ async fn main() -> std::io::Result<()> {
let sentry = sentry::init(sentry::ClientOptions {
release: sentry::release_name!(),
traces_sample_rate: 0.1,
enable_profiling: true,
profiles_sample_rate: 0.1,
..Default::default()
});
if sentry.is_enabled() {
Expand Down
15 changes: 13 additions & 2 deletions src/models/pats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use serde::{Deserialize, Serialize};
pub struct PatId(pub u64);

bitflags::bitflags! {
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct Scopes: u64 {
// read a user's email
const USER_READ_EMAIL = 1 << 0;
Expand Down Expand Up @@ -126,6 +125,18 @@ impl Scopes {
}
}

impl serde::Serialize for Scopes {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
bitflags_serde_legacy::serialize(self, "Flags", serializer)
}
}

impl<'de> serde::Deserialize<'de> for Scopes {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
bitflags_serde_legacy::deserialize("Flags", deserializer)
}
}

#[derive(Serialize, Deserialize)]
pub struct PersonalAccessToken {
pub id: PatId,
Expand Down
30 changes: 26 additions & 4 deletions src/models/teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub struct Team {
}

bitflags::bitflags! {
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct ProjectPermissions: u64 {
const UPLOAD_VERSION = 1 << 0;
const DELETE_VERSION = 1 << 1;
Expand All @@ -40,6 +39,18 @@ bitflags::bitflags! {
}
}

impl serde::Serialize for ProjectPermissions {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
bitflags_serde_legacy::serialize(self, "Flags", serializer)
}
}

impl<'de> serde::Deserialize<'de> for ProjectPermissions {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
bitflags_serde_legacy::deserialize("Flags", deserializer)
}
}

impl Default for ProjectPermissions {
fn default() -> ProjectPermissions {
ProjectPermissions::UPLOAD_VERSION | ProjectPermissions::DELETE_VERSION
Expand Down Expand Up @@ -77,8 +88,7 @@ impl ProjectPermissions {
}

bitflags::bitflags! {
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct OrganizationPermissions: u64 {
const EDIT_DETAILS = 1 << 0;
const EDIT_BODY = 1 << 1;
Expand All @@ -94,6 +104,18 @@ bitflags::bitflags! {
}
}

impl serde::Serialize for OrganizationPermissions {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
bitflags_serde_legacy::serialize(self, "Flags", serializer)
}
}

impl<'de> serde::Deserialize<'de> for OrganizationPermissions {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
bitflags_serde_legacy::deserialize("Flags", deserializer)
}
}

impl Default for OrganizationPermissions {
fn default() -> OrganizationPermissions {
OrganizationPermissions::NONE
Expand Down
15 changes: 13 additions & 2 deletions src/models/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pub struct UserId(pub u64);
pub const DELETED_USER: UserId = UserId(127155982985829);

bitflags::bitflags! {
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct Badges: u64 {
// 1 << 0 unused - ignore + replace with something later
const MIDAS = 1 << 0;
Expand All @@ -29,6 +28,18 @@ bitflags::bitflags! {
}
}

impl serde::Serialize for Badges {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
bitflags_serde_legacy::serialize(self, "Flags", serializer)
}
}

impl<'de> serde::Deserialize<'de> for Badges {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
bitflags_serde_legacy::deserialize("Flags", deserializer)
}
}

impl Default for Badges {
fn default() -> Badges {
Badges::NONE
Expand Down
2 changes: 1 addition & 1 deletion src/queue/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub async fn process_payout(
redis: &RedisPool,
client: &clickhouse::Client,
) -> Result<(), ApiError> {
let start: DateTime<Utc> = DateTime::from_utc(
let start: DateTime<Utc> = DateTime::from_naive_utc_and_offset(
(Utc::now() - Duration::days(1))
.date_naive()
.and_hms_nano_opt(0, 0, 0, 0)
Expand Down
6 changes: 4 additions & 2 deletions src/routes/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub async fn page_view_ingest(

let mut view = PageView {
id: Uuid::new_v4(),
recorded: Utc::now().timestamp_nanos() / 100_000,
// safe unwrap, can only panic after 2225
recorded: Utc::now().timestamp_nanos_opt().unwrap() / 100_000,
domain: domain.to_string(),
site_path: url.path().to_string(),
user_id: 0,
Expand Down Expand Up @@ -205,7 +206,8 @@ pub async fn playtime_ingest(
analytics_queue
.add_playtime(Playtime {
id: Default::default(),
recorded: Utc::now().timestamp_nanos() / 100_000,
// safe unwrap, can only panic after 2225
recorded: Utc::now().timestamp_nanos_opt().unwrap() / 100_000,
seconds: playtime.seconds as u64,
user_id: user.id.0,
project_id: version.inner.project_id.0 as u64,
Expand Down
3 changes: 2 additions & 1 deletion src/routes/v2/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ pub async fn count_download(
analytics_queue
.add_download(Download {
id: Uuid::new_v4(),
recorded: Utc::now().timestamp_nanos() / 100_000,
// safe unwrap, can only panic after 2225
recorded: Utc::now().timestamp_nanos_opt().unwrap() / 100_000,
domain: url.host_str().unwrap_or_default().to_string(),
site_path: url.path().to_string(),
user_id: user
Expand Down
2 changes: 1 addition & 1 deletion src/validate/fabric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl super::Validator for FabricValidator {

fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 18w49a, the first fabric version
SupportedGameVersions::PastDate(DateTime::from_utc(
SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1543969469, 0).unwrap(),
Utc,
))
Expand Down
6 changes: 3 additions & 3 deletions src/validate/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl super::Validator for ForgeValidator {

fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 1.13, the first forge version which uses the new TOML system
SupportedGameVersions::PastDate(DateTime::<Utc>::from_utc(
SupportedGameVersions::PastDate(DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1540122067, 0).unwrap(),
Utc,
))
Expand Down Expand Up @@ -58,11 +58,11 @@ impl super::Validator for LegacyForgeValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Times between versions 1.5.2 to 1.12.2, which all use the legacy way of defining mods
SupportedGameVersions::Range(
DateTime::from_utc(
DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1366818300, 0).unwrap(),
Utc,
),
DateTime::from_utc(
DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1505810340, 0).unwrap(),
Utc,
),
Expand Down
2 changes: 1 addition & 1 deletion src/validate/quilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl super::Validator for QuiltValidator {
}

fn get_supported_game_versions(&self) -> SupportedGameVersions {
SupportedGameVersions::PastDate(DateTime::from_utc(
SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1646070100, 0).unwrap(),
Utc,
))
Expand Down
6 changes: 3 additions & 3 deletions src/validate/resourcepack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl super::Validator for PackValidator {

fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 13w24a which replaced texture packs with resource packs
SupportedGameVersions::PastDate(DateTime::from_utc(
SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1371137542, 0).unwrap(),
Utc,
))
Expand Down Expand Up @@ -58,11 +58,11 @@ impl super::Validator for TexturePackValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// a1.2.2a to 13w23b
SupportedGameVersions::Range(
DateTime::from_utc(
DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1289339999, 0).unwrap(),
Utc,
),
DateTime::from_utc(
DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1370651522, 0).unwrap(),
Utc,
),
Expand Down

0 comments on commit 1dc2557

Please sign in to comment.