diff --git a/theseus/src/api/shared_profile.rs b/theseus/src/api/shared_profile.rs index fe840660c..e97acb008 100644 --- a/theseus/src/api/shared_profile.rs +++ b/theseus/src/api/shared_profile.rs @@ -46,6 +46,30 @@ pub struct SharedProfileOverrideHashes { pub sha512: String, } +// Simplified version of SharedProfile- this is what is returned from the Labrinth API +// This is not used, except for requests where we are not a member of the shared profile +// (ie: previewing a shared profile from a link, before accepting it) +#[derive(Deserialize, Serialize, Debug)] +pub struct SharedProfileResponse { + pub id: String, + pub name: String, + pub owner_id: String, + pub created: DateTime, + pub updated: DateTime, + pub icon_url: Option, + + pub loader: ModLoader, + pub game : String, + + pub loader_version: String, + pub game_version: String, + + // Present only if we are the owner + pub share_links: Option>, + pub users: Option>, +} + + // Create a new shared profile from ProfilePathId // This converts the LinkedData to a SharedProfile and uploads it to the Labrinth API #[tracing::instrument] @@ -177,27 +201,6 @@ pub async fn get_all() -> crate::Result> { let creds = state.credentials.read().await; let creds = creds.0.as_ref().ok_or_else(|| crate::ErrorKind::NoCredentialsError)?; - // First, get list of shared profiles the user has access to - #[derive(Deserialize, Serialize, Debug)] - pub struct SharedProfileResponse { - pub id: String, - pub name: String, - pub owner_id: String, - pub created: DateTime, - pub updated: DateTime, - pub icon_url: Option, - - pub loader: ModLoader, - pub game : String, - - pub loader_version: String, - pub game_version: String, - - // Present only if we are the owner - pub share_links: Option>, - pub users: Option>, - } - let response = REQWEST_CLIENT .get( format!("{MODRINTH_API_URL_INTERNAL}client/user"), @@ -205,6 +208,7 @@ pub async fn get_all() -> crate::Result> { .header("Authorization", &creds.session) .send().await?.error_for_status()?; + // First, get list of shared profiles the user has access to let profiles = response.json::>().await?; // Next, get files for each shared profile @@ -253,8 +257,9 @@ pub async fn get_all() -> crate::Result> { } #[tracing::instrument] -pub async fn install(shared_profile : SharedProfile) -> crate::Result { +pub async fn install(shared_profile_id : String) -> crate::Result { let state = crate::State::get().await?; + let shared_profile = get_all().await?.into_iter().find(|x| x.id == shared_profile_id).ok_or_else(|| crate::ErrorKind::OtherError("Profile not found".to_string()))?; let linked_data = LinkedData::SharedProfile { profile_id: shared_profile.id, @@ -647,10 +652,32 @@ pub async fn accept_share_link( REQWEST_CLIENT .post( - format!("{MODRINTH_API_URL_INTERNAL}client/profile/share/{link}/accept"), + format!("{MODRINTH_API_URL_INTERNAL}client/share/{link}/accept"), ) .header("Authorization", &creds.session) .send().await?.error_for_status()?; Ok(()) +} + +// Gets a shared profile from a share link +// This is done without accepting it- so would not include any link information, and is only usable for basic info +pub async fn get_from_link( + link: String +) -> crate::Result { + let state = crate::State::get().await?; + + let creds = state.credentials.read().await; + let creds = creds.0.as_ref().ok_or_else(|| crate::ErrorKind::NoCredentialsError)?; + + let response = REQWEST_CLIENT + .get( + format!("{MODRINTH_API_URL_INTERNAL}client/share/{link}"), + ) + .header("Authorization", &creds.session) + .send().await?.error_for_status()?; + + let profile = response.json::().await?; + + Ok(profile) } \ No newline at end of file diff --git a/theseus_gui/src-tauri/src/api/profile_share.rs b/theseus_gui/src-tauri/src/api/profile_share.rs index f077374cf..4b0b9b4c4 100644 --- a/theseus_gui/src-tauri/src/api/profile_share.rs +++ b/theseus_gui/src-tauri/src/api/profile_share.rs @@ -1,5 +1,5 @@ use crate::api::Result; -use theseus::{prelude::*, shared_profile::SharedProfile}; +use theseus::{prelude::*, shared_profile::{SharedProfile,SharedProfileResponse}}; pub fn init() -> tauri::plugin::TauriPlugin { tauri::plugin::Builder::new("profile_share") @@ -12,7 +12,8 @@ pub fn init() -> tauri::plugin::TauriPlugin { profile_share_generate_share_link, profile_share_accept_share_link, profile_share_remove_users, - profile_share_remove_links + profile_share_remove_links, + profile_share_get_link_id, ]) .build() } @@ -28,9 +29,9 @@ pub async fn profile_share_get_all( #[tauri::command] pub async fn profile_share_install( - profile: SharedProfile, + shared_profile_id: String, ) -> Result { - let res = shared_profile::install(profile) + let res = shared_profile::install(shared_profile_id) .await?; Ok(res) } @@ -77,6 +78,17 @@ pub async fn profile_share_accept_share_link( Ok(()) } +// Gets a shared profile from a share link +// This is done without accepting it- so would not include any link information, and is only usable for basic info +#[tauri::command] +pub async fn profile_share_get_link_id( + link : String +) -> Result { + let res = shared_profile::get_from_link(link).await?; + Ok(res) +} + + #[tauri::command] pub async fn profile_share_remove_users( path : ProfilePathId, diff --git a/theseus_gui/src-tauri/src/api/utils.rs b/theseus_gui/src-tauri/src/api/utils.rs index e7e7543df..007a7af0e 100644 --- a/theseus_gui/src-tauri/src/api/utils.rs +++ b/theseus_gui/src-tauri/src/api/utils.rs @@ -20,7 +20,8 @@ pub fn init() -> tauri::plugin::TauriPlugin { get_opening_command, await_sync, is_offline, - refresh_offline + refresh_offline, + test_command, ]) .build() } @@ -159,6 +160,11 @@ pub async fn get_opening_command() -> Result> { Ok(None) } +#[tauri::command] +pub async fn test_command(command: String) -> Result<()> { + Ok(handle_command(command).await?) +} + // helper function called when redirected by a weblink (ie: modrith://do-something) or when redirected by a .mrpack file (in which case its a filepath) // We hijack the deep link library (which also contains functionality for instance-checking) pub async fn handle_command(command: String) -> Result<()> { diff --git a/theseus_gui/src/components/ui/AcceptSharedProfileModal.vue b/theseus_gui/src/components/ui/AcceptSharedProfileModal.vue index 3dda939db..0e9cf9cfa 100644 --- a/theseus_gui/src/components/ui/AcceptSharedProfileModal.vue +++ b/theseus_gui/src/components/ui/AcceptSharedProfileModal.vue @@ -1,10 +1,8 @@