You've already forked AstralRinth
forked from didirus/AstralRinth
381ea51cce
* fix: files.vue bugs before styling changes * feat: move files tab to shared layout structure * fix: qa * fix: qa * fix: bugs * fix: lint * fix: admonition cleanup with progress + actions * fix: cleanup * fix: modals * fix: admon title * fix: i18n standard * fix: lint + i18n pass * fix: remove transition * fix: type errors * feat: files tab in app * fix: qa * fix: backup item minmax * fix: use ContentPageHeader for server panel * fix: lint * fix: lint * fix: lint * feat: page leave safety * fix: lint * fix: cargo fmt fix * fix: blank in prod * fix: content card table stuff * Revert "fix: blank in prod" This reverts commit 74758fe185cf85a4a20355857f889cb091b97ace. * fix: import * feat: browse worlds/servers flow * fix: worlds tab parity with content tab * fix: perf bug + shader filter pill copy * feat: singleplayer filter * fix: ordering * fix: breadcrumbs * fix: lint * fix: qa * feat: store server proj id when adding to a non-linked instance * fix: lint * fix: i18n + qa * fix: conflict * qa: already installed modal + placeholders not server-specific * fix: qa * fix: add + edit server modals * fix: qa * fix: security * fix: devin flags * fix: lint * chore: change file to break build cache * fix: admon * fix: import path stuff * feat: qa * fix: fmt fmt idiot --------- Signed-off-by: Calum H. <calum@modrinth.com>
133 lines
4.0 KiB
Rust
133 lines
4.0 KiB
Rust
use crate::worlds::{DisplayStatus, WorldType};
|
|
use paste::paste;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct AttachedWorldData {
|
|
pub display_status: DisplayStatus,
|
|
pub project_id: Option<String>,
|
|
pub content_kind: Option<String>,
|
|
}
|
|
|
|
impl AttachedWorldData {
|
|
pub async fn get_for_world(
|
|
instance: &str,
|
|
world_type: WorldType,
|
|
world_id: &str,
|
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
) -> crate::Result<Option<Self>> {
|
|
let world_type = world_type.as_str();
|
|
|
|
let attached_data = sqlx::query!(
|
|
"
|
|
SELECT display_status, project_id, content_kind
|
|
FROM attached_world_data
|
|
WHERE profile_path = $1 and world_type = $2 and world_id = $3
|
|
",
|
|
instance,
|
|
world_type,
|
|
world_id
|
|
)
|
|
.fetch_optional(exec)
|
|
.await?;
|
|
|
|
Ok(attached_data.map(|x| AttachedWorldData {
|
|
display_status: DisplayStatus::from_string(&x.display_status),
|
|
project_id: x.project_id,
|
|
content_kind: x.content_kind,
|
|
}))
|
|
}
|
|
|
|
pub async fn get_all_for_instance(
|
|
instance: &str,
|
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
) -> crate::Result<HashMap<(WorldType, String), Self>> {
|
|
let attached_data = sqlx::query!(
|
|
"
|
|
SELECT world_type, world_id, display_status, project_id, content_kind
|
|
FROM attached_world_data
|
|
WHERE profile_path = $1
|
|
",
|
|
instance
|
|
)
|
|
.fetch_all(exec)
|
|
.await?;
|
|
|
|
Ok(attached_data
|
|
.into_iter()
|
|
.map(|x| {
|
|
let world_type = WorldType::from_string(&x.world_type);
|
|
let display_status =
|
|
DisplayStatus::from_string(&x.display_status);
|
|
(
|
|
(world_type, x.world_id),
|
|
AttachedWorldData {
|
|
display_status,
|
|
project_id: x.project_id,
|
|
content_kind: x.content_kind,
|
|
},
|
|
)
|
|
})
|
|
.collect())
|
|
}
|
|
|
|
pub async fn remove_for_world(
|
|
instance: &str,
|
|
world_type: WorldType,
|
|
world_id: &str,
|
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
) -> crate::Result<()> {
|
|
let world_type = world_type.as_str();
|
|
|
|
sqlx::query!(
|
|
"
|
|
DELETE FROM attached_world_data
|
|
WHERE profile_path = $1 and world_type = $2 and world_id = $3
|
|
",
|
|
instance,
|
|
world_type,
|
|
world_id
|
|
)
|
|
.execute(exec)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
macro_rules! attached_data_setter {
|
|
($parameter:ident: $parameter_type:ty, $column:expr $(=> $adapter:expr)?) => {
|
|
paste! {
|
|
pub async fn [<set_ $parameter>](
|
|
instance: &str,
|
|
world_type: WorldType,
|
|
world_id: &str,
|
|
$parameter: $parameter_type,
|
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
) -> crate::Result<()> {
|
|
let world_type = world_type.as_str();
|
|
$(let $parameter = $adapter;)?
|
|
|
|
sqlx::query!(
|
|
"INSERT INTO attached_world_data (profile_path, world_type, world_id, " + $column + ")\n" +
|
|
"VALUES ($1, $2, $3, $4)\n" +
|
|
"ON CONFLICT (profile_path, world_type, world_id) DO UPDATE\n" +
|
|
" SET " + $column + " = $4",
|
|
instance,
|
|
world_type,
|
|
world_id,
|
|
$parameter
|
|
)
|
|
.execute(exec)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
attached_data_setter!(display_status: DisplayStatus, "display_status" => display_status.as_str());
|
|
attached_data_setter!(project_id: &str, "project_id");
|
|
attached_data_setter!(content_kind: &str, "content_kind");
|