Files
modrinth/packages/app-lib/src/state/attached_world_data.rs
T
734720e11e feat: instances v2 (#6431)
* feat: base of instances v2

* feat: use old profiles with compat layer

* prototype: instances v2

* fix: install_from using profile

* fix: skins migration fix

* fix: frontend still using profile path

* fix: add update proj multiselect guard

* fix: cargo fmt

* fix: content missing fields

* feat: break up app-lib/api/instance.rs

* fix: check_content_updates mismatch

* fix: updater modal cleanup w/new structure

* feat: better update all handling

* fix: remove preview_update_all

* fix: feedback on bulk update + lint

* fix: rem transitions

* fix: change to jsonb

* feat: app db backup after update

* fix: lint

* fix: sqlx prepare + use sqlx macros

* fix: lint

* fix: bugs

* feat: defuck the installing process up

* fix: bug of hell

* fix: shear

* fix: fmt

* fix: install progress spacing + change mc/content/overrides to bytes

* fix: lint

* fix: prepr

* fix: navtabs anim not working in app

* fix: worlds.vue improvements + browse page fixes

* feat: optimise queries + adapter fns

* fix: lint

* fix: lint

* feat: shared modrinth-content-management crate (#6469)

* feat: disable warnings setting

* feat: add instances shortcuts (#6329)

* Add modrinth://launch deep link to start a profile

Support external profile launching via modrinth://launch/{profile_path} for integrations such as Stream Deck.

* Change route to /launch/profile/{id} for future extensibility

* fix: ensure profile path is url decoded

* fix: URL-decode profile path from deep link

* fix: use urlencoding crate for URL decoding

* feat: implement app instance shortcuts

* feat: change windows shortcut creation to use windows api instead

* feat: implement creating a shortcut launching world/server

* format

* fmt

* fix multiline inline tables

* pnpm prepr

* feat: move create shortcut to last item

* refactor: split up shortcuts.rs for individual platforms

* refactor: turn profile launch url into url type

* use string literal and add safety comment

* pt2

* refactor: rename anything that's profile into instance

* update mac shortcut

---------

Co-authored-by: DJCheesusReal <134006619+DJCheesusReal@users.noreply.github.com>

---------

Co-authored-by: Truman Gao <106889354+tdgao@users.noreply.github.com>
Co-authored-by: DJCheesusReal <134006619+DJCheesusReal@users.noreply.github.com>
2026-06-25 21:19:29 +00:00

178 lines
4.5 KiB
Rust

use crate::worlds::{DisplayStatus, WorldType};
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_id: &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 instance_id = ? and world_type = ? and world_id = ?
",
instance_id,
world_type,
world_id,
)
.fetch_optional(exec)
.await?;
Ok(attached_data.map(|row| AttachedWorldData {
display_status: DisplayStatus::from_string(&row.display_status),
project_id: row.project_id,
content_kind: row.content_kind,
}))
}
pub async fn get_all_for_instance(
instance_id: &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 instance_id = ?
",
instance_id,
)
.fetch_all(exec)
.await?;
Ok(attached_data
.into_iter()
.map(|row| {
let world_type = WorldType::from_string(&row.world_type);
let display_status =
DisplayStatus::from_string(&row.display_status);
(
(world_type, row.world_id),
AttachedWorldData {
display_status,
project_id: row.project_id,
content_kind: row.content_kind,
},
)
})
.collect())
}
pub async fn remove_for_world(
instance_id: &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 instance_id = ? and world_type = ? and world_id = ?
",
instance_id,
world_type,
world_id,
)
.execute(exec)
.await?;
Ok(())
}
}
pub async fn set_display_status(
instance_id: &str,
world_type: WorldType,
world_id: &str,
display_status: DisplayStatus,
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
) -> crate::Result<()> {
let world_type = world_type.as_str();
let display_status = display_status.as_str();
sqlx::query!(
"
INSERT INTO attached_world_data (instance_id, world_type, world_id, display_status)
VALUES (?, ?, ?, ?)
ON CONFLICT (instance_id, world_type, world_id) DO UPDATE
SET display_status = excluded.display_status
",
instance_id,
world_type,
world_id,
display_status,
)
.execute(exec)
.await?;
Ok(())
}
pub async fn set_project_id(
instance_id: &str,
world_type: WorldType,
world_id: &str,
project_id: &str,
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
) -> crate::Result<()> {
let world_type = world_type.as_str();
sqlx::query!(
"
INSERT INTO attached_world_data (instance_id, world_type, world_id, project_id)
VALUES (?, ?, ?, ?)
ON CONFLICT (instance_id, world_type, world_id) DO UPDATE
SET project_id = excluded.project_id
",
instance_id,
world_type,
world_id,
project_id,
)
.execute(exec)
.await?;
Ok(())
}
pub async fn set_content_kind(
instance_id: &str,
world_type: WorldType,
world_id: &str,
content_kind: &str,
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
) -> crate::Result<()> {
let world_type = world_type.as_str();
sqlx::query!(
"
INSERT INTO attached_world_data (instance_id, world_type, world_id, content_kind)
VALUES (?, ?, ?, ?)
ON CONFLICT (instance_id, world_type, world_id) DO UPDATE
SET content_kind = excluded.content_kind
",
instance_id,
world_type,
world_id,
content_kind,
)
.execute(exec)
.await?;
Ok(())
}