You've already forked AstralRinth
forked from didirus/AstralRinth
Monetization status, additional files fix, deps fix (#574)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::ids::*;
|
||||
use crate::models::projects::ProjectStatus;
|
||||
use crate::models::projects::{MonetizationStatus, ProjectStatus};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -102,6 +102,7 @@ pub struct ProjectBuilder {
|
||||
pub gallery_items: Vec<GalleryItem>,
|
||||
pub color: Option<u32>,
|
||||
pub thread_id: ThreadId,
|
||||
pub monetization_status: MonetizationStatus,
|
||||
}
|
||||
|
||||
impl ProjectBuilder {
|
||||
@@ -141,13 +142,12 @@ impl ProjectBuilder {
|
||||
slug: self.slug,
|
||||
moderation_message: None,
|
||||
moderation_message_body: None,
|
||||
flame_anvil_project: None,
|
||||
flame_anvil_user: None,
|
||||
webhook_sent: false,
|
||||
color: self.color,
|
||||
loaders: vec![],
|
||||
game_versions: vec![],
|
||||
thread_id: Some(self.thread_id),
|
||||
monetization_status: self.monetization_status,
|
||||
};
|
||||
project_struct.insert(&mut *transaction).await?;
|
||||
|
||||
@@ -226,13 +226,12 @@ pub struct Project {
|
||||
pub slug: Option<String>,
|
||||
pub moderation_message: Option<String>,
|
||||
pub moderation_message_body: Option<String>,
|
||||
pub flame_anvil_project: Option<i32>,
|
||||
pub flame_anvil_user: Option<UserId>,
|
||||
pub webhook_sent: bool,
|
||||
pub color: Option<u32>,
|
||||
pub loaders: Vec<String>,
|
||||
pub game_versions: Vec<String>,
|
||||
pub thread_id: Option<ThreadId>,
|
||||
pub monetization_status: MonetizationStatus,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
@@ -247,14 +246,14 @@ impl Project {
|
||||
published, downloads, icon_url, issues_url,
|
||||
source_url, wiki_url, status, requested_status, discord_url,
|
||||
client_side, server_side, license_url, license,
|
||||
slug, project_type, color, thread_id
|
||||
slug, project_type, color, thread_id, monetization_status
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5,
|
||||
$6, $7, $8, $9,
|
||||
$10, $11, $12, $13, $14,
|
||||
$15, $16, $17, $18,
|
||||
LOWER($19), $20, $21, $22
|
||||
LOWER($19), $20, $21, $22, $23
|
||||
)
|
||||
",
|
||||
self.id as ProjectId,
|
||||
@@ -279,6 +278,7 @@ impl Project {
|
||||
self.project_type as ProjectTypeId,
|
||||
self.color.map(|x| x as i32),
|
||||
self.thread_id.map(|x| x.0),
|
||||
self.monetization_status.as_str(),
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
@@ -316,8 +316,8 @@ impl Project {
|
||||
updated, approved, queued, status, requested_status,
|
||||
issues_url, source_url, wiki_url, discord_url, license_url,
|
||||
team_id, client_side, server_side, license, slug,
|
||||
moderation_message, moderation_message_body, flame_anvil_project,
|
||||
flame_anvil_user, webhook_sent, color, loaders, game_versions, thread_id
|
||||
moderation_message, moderation_message_body,
|
||||
webhook_sent, color, loaders, game_versions, thread_id, monetization_status
|
||||
FROM mods
|
||||
WHERE id = ANY($1)
|
||||
",
|
||||
@@ -356,14 +356,13 @@ impl Project {
|
||||
moderation_message: m.moderation_message,
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
approved: m.approved,
|
||||
flame_anvil_project: m.flame_anvil_project,
|
||||
flame_anvil_user: m.flame_anvil_user.map(UserId),
|
||||
webhook_sent: m.webhook_sent,
|
||||
color: m.color.map(|x| x as u32),
|
||||
loaders: m.loaders,
|
||||
game_versions: m.game_versions,
|
||||
queued: m.queued,
|
||||
thread_id: m.thread_id.map(ThreadId),
|
||||
monetization_status: MonetizationStatus::from_str(&m.monetization_status),
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<Project>>()
|
||||
@@ -678,8 +677,8 @@ impl Project {
|
||||
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
|
||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
||||
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
|
||||
cs.name client_side_type, ss.name server_side_type, pt.name project_type_name, m.flame_anvil_project flame_anvil_project, m.flame_anvil_user flame_anvil_user, m.webhook_sent, m.color,
|
||||
m.loaders loaders, m.game_versions game_versions, m.thread_id thread_id,
|
||||
cs.name client_side_type, ss.name server_side_type, pt.name project_type_name, m.webhook_sent, m.color,
|
||||
m.loaders loaders, m.game_versions game_versions, m.thread_id thread_id, m.monetization_status monetization_status,
|
||||
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
|
||||
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
|
||||
JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,
|
||||
@@ -738,14 +737,15 @@ impl Project {
|
||||
moderation_message: m.moderation_message,
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
approved: m.approved,
|
||||
flame_anvil_project: m.flame_anvil_project,
|
||||
flame_anvil_user: m.flame_anvil_user.map(UserId),
|
||||
webhook_sent: m.webhook_sent,
|
||||
color: m.color.map(|x| x as u32),
|
||||
loaders: m.loaders,
|
||||
game_versions: m.game_versions,
|
||||
queued: m.queued,
|
||||
thread_id: m.thread_id.map(ThreadId),
|
||||
monetization_status: MonetizationStatus::from_str(
|
||||
&m.monetization_status,
|
||||
),
|
||||
},
|
||||
project_type: m.project_type_name,
|
||||
categories: m.categories.unwrap_or_default(),
|
||||
|
||||
@@ -133,7 +133,7 @@ impl TeamMember {
|
||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
|
||||
u.payout_address payout_address, u.flame_anvil_key flame_anvil_key
|
||||
u.payout_address payout_address
|
||||
FROM team_members tm
|
||||
INNER JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.team_id = ANY($1)
|
||||
@@ -166,7 +166,6 @@ impl TeamMember {
|
||||
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
|
||||
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: m.payout_address,
|
||||
flame_anvil_key: m.flame_anvil_key,
|
||||
},
|
||||
payouts_split: m.payouts_split,
|
||||
ordering: m.ordering,
|
||||
@@ -318,18 +317,6 @@ impl TeamMember {
|
||||
user_id: UserId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), super::DatabaseError> {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET flame_anvil_user = NULL
|
||||
WHERE (team_id = $1 AND flame_anvil_user = $2 )
|
||||
",
|
||||
id as TeamId,
|
||||
user_id as UserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM team_members
|
||||
|
||||
@@ -18,7 +18,6 @@ pub struct User {
|
||||
pub payout_wallet: Option<RecipientWallet>,
|
||||
pub payout_wallet_type: Option<RecipientType>,
|
||||
pub payout_address: Option<String>,
|
||||
pub flame_anvil_key: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
@@ -76,7 +75,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address, u.flame_anvil_key
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE u.github_id = $1
|
||||
",
|
||||
@@ -106,7 +105,6 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
flame_anvil_key: row.flame_anvil_key,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -126,7 +124,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address, u.flame_anvil_key
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE LOWER(u.username) = LOWER($1)
|
||||
",
|
||||
@@ -156,7 +154,6 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
flame_anvil_key: row.flame_anvil_key,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -179,7 +176,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address, u.flame_anvil_key
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE u.id = ANY($1)
|
||||
",
|
||||
@@ -206,7 +203,6 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: u.payout_address,
|
||||
flame_anvil_key: u.flame_anvil_key,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<User>>()
|
||||
|
||||
@@ -37,31 +37,20 @@ impl DependencyBuilder {
|
||||
version_id: VersionId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let (version_dependency_id, project_dependency_id): (
|
||||
Option<VersionId>,
|
||||
Option<ProjectId>,
|
||||
) = if self.version_id.is_some() {
|
||||
(self.version_id, None)
|
||||
} else if let Some(project_id) = self.project_id {
|
||||
let version_id = sqlx::query!(
|
||||
"
|
||||
SELECT version.id id FROM (
|
||||
SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v
|
||||
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id IN (SELECT game_version_id FROM game_versions_versions WHERE joining_version_id = $2)
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id IN (SELECT loader_id FROM loaders_versions WHERE version_id = $2)
|
||||
WHERE v.mod_id = $1
|
||||
) AS version
|
||||
ORDER BY version.date_published DESC
|
||||
LIMIT 1
|
||||
let project_id = if let Some(project_id) = self.project_id {
|
||||
Some(project_id)
|
||||
} else if let Some(version_id) = self.version_id {
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT mod_id FROM versions WHERE id = $1
|
||||
",
|
||||
project_id as ProjectId,
|
||||
version_id as VersionId,
|
||||
)
|
||||
.fetch_optional(&mut *transaction).await?.map(|x| VersionId(x.id));
|
||||
|
||||
(version_id, Some(project_id))
|
||||
version_id as VersionId,
|
||||
)
|
||||
.fetch_optional(&mut *transaction)
|
||||
.await?
|
||||
.map(|x| ProjectId(x.mod_id))
|
||||
} else {
|
||||
(None, None)
|
||||
None
|
||||
};
|
||||
|
||||
sqlx::query!(
|
||||
@@ -71,8 +60,8 @@ impl DependencyBuilder {
|
||||
",
|
||||
version_id as VersionId,
|
||||
self.dependency_type,
|
||||
version_dependency_id.map(|x| x.0),
|
||||
project_dependency_id.map(|x| x.0),
|
||||
project_id.map(|x| x.0),
|
||||
self.version_id.map(|x| x.0),
|
||||
self.file_name,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
@@ -206,41 +195,6 @@ impl VersionBuilder {
|
||||
.await?;
|
||||
}
|
||||
|
||||
// Sync dependencies
|
||||
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let dependencies = sqlx::query!(
|
||||
"
|
||||
SELECT d.id id
|
||||
FROM dependencies d
|
||||
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = d.dependent_id AND gvv.game_version_id = ANY($2)
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = d.dependent_id AND lv.loader_id = ANY($3)
|
||||
WHERE d.mod_dependency_id = $1
|
||||
",
|
||||
self.project_id as ProjectId,
|
||||
&self.game_versions.iter().map(|x| x.0).collect::<Vec<i32>>(),
|
||||
&self.loaders.iter().map(|x| x.0).collect::<Vec<i32>>(),
|
||||
)
|
||||
.fetch_many(&mut *transaction)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|d| d.id as i64))
|
||||
})
|
||||
.try_collect::<Vec<i64>>()
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE dependencies
|
||||
SET dependency_id = $2
|
||||
WHERE id = ANY($1::bigint[])
|
||||
",
|
||||
dependencies.as_slice(),
|
||||
self.version_id as VersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(self.version_id)
|
||||
}
|
||||
}
|
||||
@@ -325,32 +279,6 @@ impl Version {
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
use futures::TryStreamExt;
|
||||
|
||||
let game_versions: Vec<i32> = sqlx::query!(
|
||||
"
|
||||
SELECT game_version_id id FROM game_versions_versions
|
||||
WHERE joining_version_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_many(&mut *transaction)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| c.id)) })
|
||||
.try_collect::<Vec<i32>>()
|
||||
.await?;
|
||||
|
||||
let loaders: Vec<i32> = sqlx::query!(
|
||||
"
|
||||
SELECT loader_id id FROM loaders_versions
|
||||
WHERE version_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_many(&mut *transaction)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| c.id)) })
|
||||
.try_collect::<Vec<i32>>()
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM game_versions_versions gvv
|
||||
@@ -406,32 +334,14 @@ impl Version {
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
let new_version_id = sqlx::query!(
|
||||
"
|
||||
SELECT v.id id
|
||||
FROM versions v
|
||||
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id = ANY($2)
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id = ANY($3)
|
||||
WHERE v.mod_id = $1
|
||||
ORDER BY v.date_published DESC
|
||||
LIMIT 1
|
||||
",
|
||||
project_id.mod_id,
|
||||
&game_versions,
|
||||
&loaders,
|
||||
)
|
||||
.fetch_optional(&mut *transaction)
|
||||
.await?
|
||||
.map(|x| x.id);
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE dependencies
|
||||
SET dependency_id = $2
|
||||
SET dependency_id = NULL, mod_dependency_id = $2
|
||||
WHERE dependency_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
new_version_id,
|
||||
project_id.mod_id,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user