mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 17:44:50 +00:00
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>
This commit is contained in:
co-authored by
DJCheesusReal
Truman Gao
parent
ef4044534f
commit
734720e11e
@@ -1,5 +1,4 @@
|
||||
use crate::worlds::{DisplayStatus, WorldType};
|
||||
use paste::paste;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -11,7 +10,7 @@ pub struct AttachedWorldData {
|
||||
|
||||
impl AttachedWorldData {
|
||||
pub async fn get_for_world(
|
||||
instance: &str,
|
||||
instance_id: &str,
|
||||
world_type: WorldType,
|
||||
world_id: &str,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
||||
@@ -20,51 +19,51 @@ impl AttachedWorldData {
|
||||
|
||||
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,
|
||||
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
|
||||
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,
|
||||
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: &str,
|
||||
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 profile_path = $1
|
||||
",
|
||||
instance
|
||||
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(|x| {
|
||||
let world_type = WorldType::from_string(&x.world_type);
|
||||
.map(|row| {
|
||||
let world_type = WorldType::from_string(&row.world_type);
|
||||
let display_status =
|
||||
DisplayStatus::from_string(&x.display_status);
|
||||
DisplayStatus::from_string(&row.display_status);
|
||||
(
|
||||
(world_type, x.world_id),
|
||||
(world_type, row.world_id),
|
||||
AttachedWorldData {
|
||||
display_status,
|
||||
project_id: x.project_id,
|
||||
content_kind: x.content_kind,
|
||||
project_id: row.project_id,
|
||||
content_kind: row.content_kind,
|
||||
},
|
||||
)
|
||||
})
|
||||
@@ -72,7 +71,7 @@ impl AttachedWorldData {
|
||||
}
|
||||
|
||||
pub async fn remove_for_world(
|
||||
instance: &str,
|
||||
instance_id: &str,
|
||||
world_type: WorldType,
|
||||
world_id: &str,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
||||
@@ -81,12 +80,12 @@ impl AttachedWorldData {
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM attached_world_data
|
||||
WHERE profile_path = $1 and world_type = $2 and world_id = $3
|
||||
",
|
||||
instance,
|
||||
DELETE FROM attached_world_data
|
||||
WHERE instance_id = ? and world_type = ? and world_id = ?
|
||||
",
|
||||
instance_id,
|
||||
world_type,
|
||||
world_id
|
||||
world_id,
|
||||
)
|
||||
.execute(exec)
|
||||
.await?;
|
||||
@@ -95,38 +94,84 @@ impl AttachedWorldData {
|
||||
}
|
||||
}
|
||||
|
||||
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;)?
|
||||
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 (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?;
|
||||
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(())
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user