mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 03:55:59 +00:00
Merge branch 'main' into boris/dev-1126
This commit is contained in:
@@ -2,12 +2,10 @@ use eyre::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use validator::Validate;
|
||||
use xredis::RedisPool;
|
||||
|
||||
use crate::{
|
||||
database::{
|
||||
models::{DBProjectId, DBVersionId},
|
||||
redis::RedisPool,
|
||||
},
|
||||
database::models::{DBProjectId, DBVersionId},
|
||||
models::{
|
||||
exp::{
|
||||
component::{
|
||||
@@ -257,14 +255,14 @@ pub async fn fetch_query_context(
|
||||
{
|
||||
HashMap::new()
|
||||
} else {
|
||||
let ping_keys = minecraft_java_server_pings
|
||||
.iter()
|
||||
.map(|project_id| {
|
||||
redis.key().entity(server_ping::REDIS_NAMESPACE, project_id)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
redis
|
||||
.get_many_deserialized::<minecraft::JavaServerPing>(
|
||||
server_ping::REDIS_NAMESPACE,
|
||||
&minecraft_java_server_pings
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.get_many_deserialized::<minecraft::JavaServerPing>(&ping_keys)
|
||||
.await?
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
@@ -280,14 +278,14 @@ pub async fn fetch_query_context(
|
||||
let minecraft_server_analytics = if minecraft_server_analytics.is_empty() {
|
||||
HashMap::new()
|
||||
} else {
|
||||
let analytics_keys = minecraft_server_analytics
|
||||
.iter()
|
||||
.map(|project_id| {
|
||||
redis.key().entity(MINECRAFT_SERVER_ANALYTICS, project_id)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
redis
|
||||
.get_many_deserialized::<MinecraftServerAnalytics>(
|
||||
MINECRAFT_SERVER_ANALYTICS,
|
||||
&minecraft_server_analytics
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.get_many_deserialized::<MinecraftServerAnalytics>(&analytics_keys)
|
||||
.await?
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
|
||||
@@ -4,7 +4,6 @@ use std::collections::HashMap;
|
||||
|
||||
use super::super::ids::OrganizationId;
|
||||
use crate::database::models::{DatabaseError, version_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::{ProjectId, TeamId, ThreadId, VersionId};
|
||||
use crate::models::projects::{
|
||||
Dependency, License, Link, Loader, ModeratorMessage, MonetizationStatus,
|
||||
@@ -16,6 +15,7 @@ use chrono::{DateTime, Utc};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
use xredis::RedisPool;
|
||||
|
||||
/// A project returned from the API
|
||||
#[derive(Serialize, Deserialize, Clone, utoipa::ToSchema)]
|
||||
|
||||
@@ -31,6 +31,7 @@ impl From<ItemType> for LegacyItemType {
|
||||
ItemType::Project => LegacyItemType::Project,
|
||||
ItemType::Version => LegacyItemType::Version,
|
||||
ItemType::User => LegacyItemType::User,
|
||||
ItemType::SharedInstance => LegacyItemType::Unknown,
|
||||
ItemType::Unknown => LegacyItemType::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ pub struct LegacyUser {
|
||||
pub has_totp: Option<bool>,
|
||||
pub payout_data: Option<UserPayoutData>, // this was changed in v3, but not ones we want to keep out of v2
|
||||
|
||||
// DEPRECATED. Always returns None
|
||||
pub github_id: Option<u64>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::database::models::report_item::ReportQueryResult as DBReport;
|
||||
use crate::models::ids::{ProjectId, ReportId, ThreadId, VersionId};
|
||||
use ariadne::ids::UserId;
|
||||
use ariadne::ids::base62_impl::to_base62;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -10,6 +11,8 @@ pub struct Report {
|
||||
pub report_type: String,
|
||||
pub item_id: String,
|
||||
pub item_type: ItemType,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub shared_instance_version_id: Option<i32>,
|
||||
pub reporter: UserId,
|
||||
pub body: String,
|
||||
pub created: DateTime<Utc>,
|
||||
@@ -23,6 +26,7 @@ pub enum ItemType {
|
||||
Project,
|
||||
Version,
|
||||
User,
|
||||
SharedInstance,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@@ -32,6 +36,7 @@ impl ItemType {
|
||||
ItemType::Project => "project",
|
||||
ItemType::Version => "version",
|
||||
ItemType::User => "user",
|
||||
ItemType::SharedInstance => "shared-instance",
|
||||
ItemType::Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
@@ -41,6 +46,7 @@ impl From<DBReport> for Report {
|
||||
fn from(x: DBReport) -> Self {
|
||||
let mut item_id = "".to_string();
|
||||
let mut item_type = ItemType::Unknown;
|
||||
let mut shared_instance_version_id = None;
|
||||
|
||||
if let Some(project_id) = x.project_id {
|
||||
item_id = ProjectId::from(project_id).to_string();
|
||||
@@ -51,6 +57,10 @@ impl From<DBReport> for Report {
|
||||
} else if let Some(user_id) = x.user_id {
|
||||
item_id = UserId::from(user_id).to_string();
|
||||
item_type = ItemType::User;
|
||||
} else if let Some(shared_instance_id) = x.shared_instance_id {
|
||||
item_id = to_base62(shared_instance_id.0 as u64);
|
||||
item_type = ItemType::SharedInstance;
|
||||
shared_instance_version_id = x.shared_instance_version_id;
|
||||
}
|
||||
|
||||
Report {
|
||||
@@ -58,6 +68,7 @@ impl From<DBReport> for Report {
|
||||
report_type: x.report_type,
|
||||
item_id,
|
||||
item_type,
|
||||
shared_instance_version_id,
|
||||
reporter: x.reporter.into(),
|
||||
body: x.body,
|
||||
created: x.created,
|
||||
|
||||
@@ -70,8 +70,11 @@ pub struct User {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub moderation_notes: Option<Option<ModerationNote>>,
|
||||
|
||||
// DEPRECATED. Always returns None
|
||||
pub github_id: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub discord_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub steam_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
@@ -119,6 +122,8 @@ impl From<DBUser> for User {
|
||||
has_password: None,
|
||||
has_totp: None,
|
||||
github_id: None,
|
||||
discord_id: None,
|
||||
steam_id: None,
|
||||
stripe_customer_id: None,
|
||||
allow_friend_requests: None,
|
||||
eligibility_verified_at: None,
|
||||
@@ -180,6 +185,8 @@ impl User {
|
||||
has_password: Some(db_user.password.is_some()),
|
||||
has_totp: Some(db_user.totp_secret.is_some()),
|
||||
github_id: None,
|
||||
discord_id: None,
|
||||
steam_id: None,
|
||||
payout_data: Some(UserPayoutData {
|
||||
paypal_address: db_user.paypal_email,
|
||||
paypal_country: db_user.paypal_country,
|
||||
|
||||
Reference in New Issue
Block a user