You've already forked AstralRinth
forked from didirus/AstralRinth
Fix clippy errors + lint, use turbo CI
This commit is contained in:
@@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models::{
|
||||
ids::{
|
||||
NotificationId, OrganizationId, ProjectId, ReportId, TeamId, ThreadId, ThreadMessageId,
|
||||
UserId, VersionId,
|
||||
NotificationId, OrganizationId, ProjectId, ReportId, TeamId, ThreadId,
|
||||
ThreadMessageId, UserId, VersionId,
|
||||
},
|
||||
notifications::{Notification, NotificationAction, NotificationBody},
|
||||
projects::ProjectStatus,
|
||||
@@ -78,11 +78,21 @@ pub enum LegacyNotificationBody {
|
||||
impl LegacyNotification {
|
||||
pub fn from(notification: Notification) -> Self {
|
||||
let type_ = match ¬ification.body {
|
||||
NotificationBody::ProjectUpdate { .. } => Some("project_update".to_string()),
|
||||
NotificationBody::TeamInvite { .. } => Some("team_invite".to_string()),
|
||||
NotificationBody::OrganizationInvite { .. } => Some("organization_invite".to_string()),
|
||||
NotificationBody::StatusChange { .. } => Some("status_change".to_string()),
|
||||
NotificationBody::ModeratorMessage { .. } => Some("moderator_message".to_string()),
|
||||
NotificationBody::ProjectUpdate { .. } => {
|
||||
Some("project_update".to_string())
|
||||
}
|
||||
NotificationBody::TeamInvite { .. } => {
|
||||
Some("team_invite".to_string())
|
||||
}
|
||||
NotificationBody::OrganizationInvite { .. } => {
|
||||
Some("organization_invite".to_string())
|
||||
}
|
||||
NotificationBody::StatusChange { .. } => {
|
||||
Some("status_change".to_string())
|
||||
}
|
||||
NotificationBody::ModeratorMessage { .. } => {
|
||||
Some("moderator_message".to_string())
|
||||
}
|
||||
NotificationBody::LegacyMarkdown {
|
||||
notification_type, ..
|
||||
} => notification_type.clone(),
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::database::models::{version_item, DatabaseError};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::{ProjectId, VersionId};
|
||||
use crate::models::projects::{
|
||||
Dependency, License, Link, Loader, ModeratorMessage, MonetizationStatus, Project,
|
||||
ProjectStatus, Version, VersionFile, VersionStatus, VersionType,
|
||||
Dependency, License, Link, Loader, ModeratorMessage, MonetizationStatus,
|
||||
Project, ProjectStatus, Version, VersionFile, VersionStatus, VersionType,
|
||||
};
|
||||
use crate::models::threads::ThreadId;
|
||||
use crate::routes::v2_reroute::{self, capitalize_first};
|
||||
@@ -87,12 +87,13 @@ impl LegacyProject {
|
||||
.cloned()
|
||||
.unwrap_or("project".to_string()); // Default to 'project' if none are found
|
||||
|
||||
let project_type = if og_project_type == "datapack" || og_project_type == "plugin" {
|
||||
// These are not supported in V2, so we'll just use 'mod' instead
|
||||
"mod".to_string()
|
||||
} else {
|
||||
og_project_type.clone()
|
||||
};
|
||||
let project_type =
|
||||
if og_project_type == "datapack" || og_project_type == "plugin" {
|
||||
// These are not supported in V2, so we'll just use 'mod' instead
|
||||
"mod".to_string()
|
||||
} else {
|
||||
og_project_type.clone()
|
||||
};
|
||||
|
||||
(project_type, og_project_type)
|
||||
}
|
||||
@@ -102,7 +103,10 @@ impl LegacyProject {
|
||||
// - This can be any version, because the fields are ones that used to be on the project itself.
|
||||
// - Its conceivable that certain V3 projects that have many different ones may not have the same fields on all of them.
|
||||
// It's safe to use a db version_item for this as the only info is side types, game versions, and loader fields (for loaders), which used to be public on project anyway.
|
||||
pub fn from(data: Project, versions_item: Option<version_item::QueryVersion>) -> Self {
|
||||
pub fn from(
|
||||
data: Project,
|
||||
versions_item: Option<version_item::QueryVersion>,
|
||||
) -> Self {
|
||||
let mut client_side = LegacySideType::Unknown;
|
||||
let mut server_side = LegacySideType::Unknown;
|
||||
|
||||
@@ -110,7 +114,8 @@ impl LegacyProject {
|
||||
// We'll prioritize 'modpack' first, and if neither are found, use the first one.
|
||||
// If there are no project types, default to 'project'
|
||||
let project_types = data.project_types;
|
||||
let (mut project_type, og_project_type) = Self::get_project_type(&project_types);
|
||||
let (mut project_type, og_project_type) =
|
||||
Self::get_project_type(&project_types);
|
||||
|
||||
let mut loaders = data.loaders;
|
||||
|
||||
@@ -128,16 +133,22 @@ impl LegacyProject {
|
||||
let fields = versions_item
|
||||
.version_fields
|
||||
.iter()
|
||||
.map(|f| (f.field_name.clone(), f.value.clone().serialize_internal()))
|
||||
.map(|f| {
|
||||
(f.field_name.clone(), f.value.clone().serialize_internal())
|
||||
})
|
||||
.collect::<HashMap<_, _>>();
|
||||
(client_side, server_side) =
|
||||
v2_reroute::convert_side_types_v2(&fields, Some(&*og_project_type));
|
||||
(client_side, server_side) = v2_reroute::convert_side_types_v2(
|
||||
&fields,
|
||||
Some(&*og_project_type),
|
||||
);
|
||||
|
||||
// - if loader is mrpack, this is a modpack
|
||||
// the loaders are whatever the corresponding loader fields are
|
||||
if loaders.contains(&"mrpack".to_string()) {
|
||||
project_type = "modpack".to_string();
|
||||
if let Some(mrpack_loaders) = data.fields.iter().find(|f| f.0 == "mrpack_loaders") {
|
||||
if let Some(mrpack_loaders) =
|
||||
data.fields.iter().find(|f| f.0 == "mrpack_loaders")
|
||||
{
|
||||
let values = mrpack_loaders
|
||||
.1
|
||||
.iter()
|
||||
@@ -227,7 +238,8 @@ impl LegacyProject {
|
||||
.iter()
|
||||
.filter_map(|p| p.versions.first().map(|i| (*i).into()))
|
||||
.collect();
|
||||
let example_versions = version_item::Version::get_many(&version_ids, exec, redis).await?;
|
||||
let example_versions =
|
||||
version_item::Version::get_many(&version_ids, exec, redis).await?;
|
||||
let mut legacy_projects = Vec::new();
|
||||
for project in data {
|
||||
let version_item = example_versions
|
||||
@@ -308,7 +320,9 @@ pub struct LegacyVersion {
|
||||
impl From<Version> for LegacyVersion {
|
||||
fn from(data: Version) -> Self {
|
||||
let mut game_versions = Vec::new();
|
||||
if let Some(value) = data.fields.get("game_versions").and_then(|v| v.as_array()) {
|
||||
if let Some(value) =
|
||||
data.fields.get("game_versions").and_then(|v| v.as_array())
|
||||
{
|
||||
for gv in value {
|
||||
if let Some(game_version) = gv.as_str() {
|
||||
game_versions.push(game_version.to_string());
|
||||
@@ -318,14 +332,17 @@ impl From<Version> for LegacyVersion {
|
||||
|
||||
// - if loader is mrpack, this is a modpack
|
||||
// the v2 loaders are whatever the corresponding loader fields are
|
||||
let mut loaders = data.loaders.into_iter().map(|l| l.0).collect::<Vec<_>>();
|
||||
let mut loaders =
|
||||
data.loaders.into_iter().map(|l| l.0).collect::<Vec<_>>();
|
||||
if loaders.contains(&"mrpack".to_string()) {
|
||||
if let Some((_, mrpack_loaders)) = data
|
||||
.fields
|
||||
.into_iter()
|
||||
.find(|(key, _)| key == "mrpack_loaders")
|
||||
{
|
||||
if let Ok(mrpack_loaders) = serde_json::from_value(mrpack_loaders) {
|
||||
if let Ok(mrpack_loaders) =
|
||||
serde_json::from_value(mrpack_loaders)
|
||||
{
|
||||
loaders = mrpack_loaders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +92,16 @@ impl LegacyResultSearchProject {
|
||||
.cloned()
|
||||
.unwrap_or("project".to_string()); // Default to 'project' if none are found
|
||||
|
||||
let project_type = if og_project_type == "datapack" || og_project_type == "plugin" {
|
||||
// These are not supported in V2, so we'll just use 'mod' instead
|
||||
"mod".to_string()
|
||||
} else {
|
||||
og_project_type.clone()
|
||||
};
|
||||
let project_type =
|
||||
if og_project_type == "datapack" || og_project_type == "plugin" {
|
||||
// These are not supported in V2, so we'll just use 'mod' instead
|
||||
"mod".to_string()
|
||||
} else {
|
||||
og_project_type.clone()
|
||||
};
|
||||
|
||||
let project_loader_fields = result_search_project.project_loader_fields.clone();
|
||||
let project_loader_fields =
|
||||
result_search_project.project_loader_fields.clone();
|
||||
let get_one_bool_loader_field = |key: &str| {
|
||||
project_loader_fields
|
||||
.get(key)
|
||||
@@ -110,17 +112,20 @@ impl LegacyResultSearchProject {
|
||||
};
|
||||
|
||||
let singleplayer = get_one_bool_loader_field("singleplayer");
|
||||
let client_only = get_one_bool_loader_field("client_only").unwrap_or(false);
|
||||
let server_only = get_one_bool_loader_field("server_only").unwrap_or(false);
|
||||
let client_only =
|
||||
get_one_bool_loader_field("client_only").unwrap_or(false);
|
||||
let server_only =
|
||||
get_one_bool_loader_field("server_only").unwrap_or(false);
|
||||
let client_and_server = get_one_bool_loader_field("client_and_server");
|
||||
|
||||
let (client_side, server_side) = v2_reroute::convert_side_types_v2_bools(
|
||||
singleplayer,
|
||||
client_only,
|
||||
server_only,
|
||||
client_and_server,
|
||||
Some(&*og_project_type),
|
||||
);
|
||||
let (client_side, server_side) =
|
||||
v2_reroute::convert_side_types_v2_bools(
|
||||
singleplayer,
|
||||
client_only,
|
||||
server_only,
|
||||
client_and_server,
|
||||
Some(&*og_project_type),
|
||||
);
|
||||
let client_side = client_side.to_string();
|
||||
let server_side = server_side.to_string();
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::models::ids::{ImageId, ProjectId, ReportId, ThreadId, ThreadMessageId};
|
||||
use crate::models::ids::{
|
||||
ImageId, ProjectId, ReportId, ThreadId, ThreadMessageId,
|
||||
};
|
||||
use crate::models::projects::ProjectStatus;
|
||||
use crate::models::users::{User, UserId};
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -57,8 +59,12 @@ pub enum LegacyThreadType {
|
||||
impl From<crate::models::v3::threads::ThreadType> for LegacyThreadType {
|
||||
fn from(t: crate::models::v3::threads::ThreadType) -> Self {
|
||||
match t {
|
||||
crate::models::v3::threads::ThreadType::Report => LegacyThreadType::Report,
|
||||
crate::models::v3::threads::ThreadType::Project => LegacyThreadType::Project,
|
||||
crate::models::v3::threads::ThreadType::Report => {
|
||||
LegacyThreadType::Report
|
||||
}
|
||||
crate::models::v3::threads::ThreadType::Project => {
|
||||
LegacyThreadType::Project
|
||||
}
|
||||
crate::models::v3::threads::ThreadType::DirectMessage => {
|
||||
LegacyThreadType::DirectMessage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user