You've already forked AstralRinth
forked from didirus/AstralRinth
7d92e4ec7f
* feat: base content card component * fix: tooltips + colors * feat: fix orgs * feat: base content tab internals rewrite * feat: fix invalidmodal * feat: add ContentModpackCard * fix: extract types * draft: layout * feat: unlink modal * feat: impl content tab * fix: lint * fix: toggling * temp: disable updating stuff * feat: selection v-model * feat: bulk selection * feat: mods tab rough draft * feat: use fuse.js * feat: add project combobox * clean up project combobox * feat: start install to play modal * fix: events * feat: use v-on * feat: bulk actions + fix floating action bar width * feat: figma alignments * feat: migrate toggle to tailwind * fix: row borders * feat: disabled state * feat: virtual list impl for card table based on window scroll * fix: lint * feat: virtualization + smaller contentcard items * feat: use ContentCardTable + ContentCardItems * feat: fix gap + border issues on last elm * feat: cleanup + use proper searching * fix: use TeleportOverflowMenu * fix: fallback to svg if src is invalid on avatar component * fix: storybook * feat: start on updater modal * feat: finish content updater modal * feat: i18n pass * feat: impl modal * feat(app): backend changes for content tab refactor (#5237) * feat: include_changelog=false for updater modal * fix: hash overrides * feat: update checking for modpack * feat: qa * feat: modpack content modal * fix: padding in table to match modals + tightness * fix: lint * feat: delete modal * feat: fix toggle bugs * fix: prepr * fix: duplicate messages * qa: full width search * qa: use bg-surface-1.5 * qa: animation for filter pills * qa: standardize hover colors * fix: border-[1px] is border * qa: mass de-select actually mass selecting * qa: match figma designs for floating action bar * qa: modal fixes * q: modal fixes x2 * fix: table border * qa: confirm modals * qa: modal alignment * qa: re-add stuck heading + dedupe logic * qa: dedupe virtual scrolling + remove dead components * qa: responsiveness for content table + link fixes * qa: version column link, tooltips + lint fixes * qa: instance busy protections * fix: installation freeze bug * chore: remove old mods page * refactor: deduplicate layout * chore: delete old content page(s) * qa * qa * qa * feat: sort btn - to iterate * fix: ml * feat: date added * fix: lint * fix: formatting.ts removal * feat: get_dependencies_as_content_items * qa: final QA changes * refactor: deduplicate + polish content.rs * feat: hook up content.vue with v1 * feat: hide v1 content api behind frontend feature flag * fix: query keys + copy on empty state * chore: i18n pass * feat: reimpl unlink + upload endpoint * feat: use bulk endpoints v1 * fix: lint * fix: flags * fix: responsiveness via container queries * fix: lint * qa: 1 * qa: fixes * qa: fix ssr issues with browse content * qa: header page divider * qa: modals * fix: prepr * fix: issues * fix: lint * fix: toggle v1 ff * qa: 5 * qa: delete modal copy * feat: creation flow modals (#5383) * refactor: delete content v0 usages + impl * feat: qa + fixes * feat: installing banner using state event * feat: fix modpack card bugs + filtering issues * refactor: delete backups v0 api module * feat: v1 servers GET endpoint * fix: backups * feat: swap to kyros upload v1 addon * fix: use tanstack for loader.vue * feat: finish install from discovery modal * qa: bug fixes * feat: set up installation settings * fix: lint * fix: typos * fix: bugs * fix: disable inline content * feat: content tab improvements — upload UX, installation settings, and client-only indicators Upload cancellation and navigation guard: - Add ConfirmLeaveModal that prompts when navigating away during upload - Cancel in-flight XHR uploads when user confirms leaving the page - Add beforeunload handler to warn on browser/tab close during upload - Track uploadedBytes/totalBytes in UploadState for progress display - Replace Collapsible with Transition for upload progress admonition - Show byte progress and percentage in upload banner - Clamp upload progress to prevent exceeding 100% Installation settings (server.properties): - Add KnownPropertiesFields and PropertiesFields types to Archon types - Add buildProperties() to creation flow context to collect gamemode, difficulty, seed, world type, structures, and generator settings - Pass properties through installContent on onboarding, discovery, and ServerSetupModal flows Server setup and discovery flow improvements: - Migrate ServerSetupModal from servers_v0.reinstall to content_v1.installContent - Replace loaderApiNames lookup with toApiLoader() helper - Remove eraseDataOnInstall toggle — always use soft_override: false - Simplify modpack install on discovery page to use first available version and route through creation flow modal for both onboarding and non-onboarding - Differentiate post-install navigation: content page for onboarding, loader options for existing servers Modpack update flow: - Replace updateModpack() call with installContent() using soft_override: true to support version selection in the content updater modal Client-only mod indicators: - Add environment field to AddonVersion (reuses Labrinth.Projects.v3.Environment) - Add environment to ContentItem and isClientOnly to ContentCardTableItem - Show orange TriangleAlertIcon with tooltip on client-only mods in content table - Add "Client-only" filter pill to content filtering (controlled via showClientOnlyFilter on ContentManagerContext) - Apply client-only indicators in both ContentPageLayout and ModpackContentModal Misc: - Add CLAUDE.md note about using prepr commands for lint checks - Export ConfirmLeaveModal from instances barrel * fix: piping * fix: switch content disable for linked server instances * feat: client only filter * fix: prepr * feat: hasUpdate shape update * feat: bulk update endpoint impl for content in panel * feat: websocket state impl again with new phases * fix: ws * fix: use timeout fn for sync admon + fix content card layout scroll for browsers with overflow anchor bug * fix: qa bugs * fix: lint, a11y and i18n * refactor: set up layouts folder properly * fix: linked data cache stuff + lint * feat: move installationsettings to shared layout * fix: lint * fix: issues * feat: temp fuck staging up * fix: lockfile * fix: data sync issues on loader.vue * fix: lint * Hide shader configuration files from content list (#5499) * feat: workaround search problem + split out reset * fix: qa * fix: changelog not showing on first open * fix: qa + optimistic updating improvements * fix: prepr+lint * fix: qa * feat: qa * fix: lint * fix: lint * fix: build * fix: build * fix: type errors * fix: fade and JAVA_HOME passthrough * feat: qa * feat: impl diff shit * fix: qa * fix: app qa * feat: update diff modal * fix: endpoint * fix: qa * fix: qa * fix: use bulk in modpack modal * feat: abort signal impl + fix issues * fix: diff modal trunc * feat: qa * fix: qa * feat: tooltip content tab * fix: prepr * fix: dismiss on settings btn * feat: qa * feat: dont clear handlers on disconnect * fix: lint * fix: wrangler + introduce staging-archon env file --------- Signed-off-by: Calum H. <calum@modrinth.com> Co-authored-by: tdgao <mr.trumgao@gmail.com> Co-authored-by: Artyom Ezri <61311568+Artezon@users.noreply.github.com>
454 lines
14 KiB
Rust
454 lines
14 KiB
Rust
use crate::State;
|
|
use crate::api::profile;
|
|
use crate::data::ModLoader;
|
|
use crate::event::emit::{emit_loading, init_loading};
|
|
use crate::event::{LoadingBarId, LoadingBarType};
|
|
use crate::state::{
|
|
CacheBehaviour, CachedEntry, LinkedData, ProfileInstallStage, SideType,
|
|
};
|
|
use crate::util::fetch::{fetch, fetch_advanced, write_cached_icon};
|
|
use crate::util::io;
|
|
|
|
use path_util::SafeRelativeUtf8UnixPathBuf;
|
|
use reqwest::Method;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Serialize, Deserialize, Eq, PartialEq)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct PackFormat {
|
|
pub game: String,
|
|
pub format_version: i32,
|
|
pub version_id: String,
|
|
pub name: String,
|
|
pub summary: Option<String>,
|
|
pub files: Vec<PackFile>,
|
|
pub dependencies: HashMap<PackDependency, String>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Eq, PartialEq)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct PackFile {
|
|
pub path: SafeRelativeUtf8UnixPathBuf,
|
|
pub hashes: HashMap<PackFileHash, String>,
|
|
pub env: Option<HashMap<EnvType, SideType>>,
|
|
pub downloads: Vec<String>,
|
|
pub file_size: u32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash)]
|
|
#[serde(rename_all = "camelCase", from = "String")]
|
|
pub enum PackFileHash {
|
|
Sha1,
|
|
Sha512,
|
|
Unknown(String),
|
|
}
|
|
|
|
impl From<String> for PackFileHash {
|
|
fn from(s: String) -> Self {
|
|
match s.as_str() {
|
|
"sha1" => PackFileHash::Sha1,
|
|
"sha512" => PackFileHash::Sha512,
|
|
_ => PackFileHash::Unknown(s),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub enum EnvType {
|
|
Client,
|
|
Server,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
|
pub enum PackDependency {
|
|
#[serde(rename = "forge")]
|
|
Forge,
|
|
|
|
#[serde(rename = "neoforge")]
|
|
#[serde(alias = "neo-forge")]
|
|
NeoForge,
|
|
|
|
#[serde(rename = "fabric-loader")]
|
|
FabricLoader,
|
|
|
|
#[serde(rename = "quilt-loader")]
|
|
QuiltLoader,
|
|
|
|
#[serde(rename = "minecraft")]
|
|
Minecraft,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
#[serde(rename_all = "camelCase", tag = "type")]
|
|
pub enum CreatePackLocation {
|
|
// Create a pack from a modrinth version ID (such as a modpack)
|
|
FromVersionId {
|
|
project_id: String,
|
|
version_id: String,
|
|
title: String,
|
|
icon_url: Option<String>,
|
|
},
|
|
// Create a pack from a file (such as an .mrpack for installing from a file, or a folder name for importing)
|
|
FromFile {
|
|
path: PathBuf,
|
|
},
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct CreatePackProfile {
|
|
pub name: String, // the name of the profile, and relative path
|
|
pub game_version: String, // the game version of the profile
|
|
pub modloader: ModLoader, // the modloader to use
|
|
pub loader_version: Option<String>, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader. defaults to latest
|
|
pub icon: Option<PathBuf>, // the icon for the profile
|
|
pub icon_url: Option<String>, // the URL icon for a profile (ONLY USED FOR TEMPORARY PROFILES)
|
|
pub linked_data: Option<LinkedData>, // the linked project ID (mainly for modpacks)- used for updating
|
|
pub skip_install_profile: Option<bool>,
|
|
pub no_watch: Option<bool>,
|
|
}
|
|
|
|
// default
|
|
impl Default for CreatePackProfile {
|
|
fn default() -> Self {
|
|
CreatePackProfile {
|
|
name: "Untitled".to_string(),
|
|
game_version: "1.19.4".to_string(),
|
|
modloader: ModLoader::Vanilla,
|
|
loader_version: None,
|
|
icon: None,
|
|
icon_url: None,
|
|
linked_data: None,
|
|
skip_install_profile: Some(true),
|
|
no_watch: Some(false),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct CreatePack {
|
|
pub file: bytes::Bytes,
|
|
pub description: CreatePackDescription,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct CreatePackDescription {
|
|
pub icon: Option<PathBuf>,
|
|
pub override_title: Option<String>,
|
|
pub project_id: Option<String>,
|
|
pub version_id: Option<String>,
|
|
pub existing_loading_bar: Option<LoadingBarId>,
|
|
pub profile_path: String,
|
|
}
|
|
|
|
pub fn get_profile_from_pack(
|
|
location: CreatePackLocation,
|
|
) -> CreatePackProfile {
|
|
match location {
|
|
CreatePackLocation::FromVersionId {
|
|
project_id,
|
|
version_id,
|
|
title,
|
|
icon_url,
|
|
} => CreatePackProfile {
|
|
name: title,
|
|
icon_url,
|
|
linked_data: Some(LinkedData {
|
|
project_id,
|
|
version_id,
|
|
locked: true,
|
|
}),
|
|
..Default::default()
|
|
},
|
|
CreatePackLocation::FromFile { path } => {
|
|
let file_name = path
|
|
.file_stem()
|
|
.unwrap_or_default()
|
|
.to_string_lossy()
|
|
.to_string();
|
|
|
|
CreatePackProfile {
|
|
name: file_name,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tracing::instrument]
|
|
|
|
pub async fn generate_pack_from_version_id(
|
|
project_id: String,
|
|
version_id: String,
|
|
title: String,
|
|
icon_url: Option<String>,
|
|
profile_path: String,
|
|
|
|
// Existing loading bar. Unlike when existing_loading_bar is used, this one is pre-initialized with PackFileDownload
|
|
// For example, you might use this if multiple packs are being downloaded at once and you want to use the same loading bar
|
|
initialized_loading_bar: Option<LoadingBarId>,
|
|
) -> crate::Result<CreatePack> {
|
|
let state = State::get().await?;
|
|
let has_icon_url = icon_url.is_some();
|
|
|
|
let loading_bar = if let Some(bar) = initialized_loading_bar {
|
|
emit_loading(&bar, 0.0, Some("Downloading pack file"))?;
|
|
bar
|
|
} else {
|
|
init_loading(
|
|
LoadingBarType::PackFileDownload {
|
|
profile_path: profile_path.clone(),
|
|
pack_name: title.clone(),
|
|
icon: icon_url,
|
|
pack_version: version_id.clone(),
|
|
},
|
|
100.0,
|
|
"Downloading pack file",
|
|
)
|
|
.await?
|
|
};
|
|
|
|
emit_loading(&loading_bar, 0.0, Some("Fetching version"))?;
|
|
let version = CachedEntry::get_version(
|
|
&version_id,
|
|
Some(CacheBehaviour::Bypass),
|
|
&state.pool,
|
|
&state.api_semaphore,
|
|
)
|
|
.await?
|
|
.ok_or_else(|| {
|
|
crate::ErrorKind::InputError(
|
|
"Invalid version ID specified!".to_string(),
|
|
)
|
|
})?;
|
|
emit_loading(&loading_bar, 10.0, None)?;
|
|
|
|
// Update profile with correct loader and game version from the API version metadata,
|
|
// so the UI shows accurate info while the pack file is still downloading.
|
|
if let Some(game_version) = version.game_versions.first() {
|
|
let loader = version
|
|
.loaders
|
|
.first()
|
|
.map(|l| ModLoader::from_string(l))
|
|
.unwrap_or(ModLoader::Vanilla);
|
|
let game_version = game_version.clone();
|
|
let profile_path_clone = profile_path.clone();
|
|
profile::edit(&profile_path_clone, |prof| {
|
|
prof.game_version.clone_from(&game_version);
|
|
prof.loader = loader;
|
|
async { Ok(()) }
|
|
})
|
|
.await?;
|
|
}
|
|
|
|
let (url, hash) =
|
|
if let Some(file) = version.files.iter().find(|x| x.primary) {
|
|
Some((file.url.clone(), file.hashes.get("sha1")))
|
|
} else {
|
|
version
|
|
.files
|
|
.first()
|
|
.map(|file| (file.url.clone(), file.hashes.get("sha1")))
|
|
}
|
|
.ok_or_else(|| {
|
|
crate::ErrorKind::InputError(
|
|
"Specified version has no files".to_string(),
|
|
)
|
|
})?;
|
|
|
|
let file = fetch_advanced(
|
|
Method::GET,
|
|
&url,
|
|
hash.map(|x| &**x),
|
|
None,
|
|
None,
|
|
Some((&loading_bar, 70.0)),
|
|
&state.fetch_semaphore,
|
|
&state.pool,
|
|
)
|
|
.await?;
|
|
emit_loading(&loading_bar, 0.0, Some("Fetching project metadata"))?;
|
|
|
|
let project = CachedEntry::get_project(
|
|
&version.project_id,
|
|
None,
|
|
&state.pool,
|
|
&state.api_semaphore,
|
|
)
|
|
.await?
|
|
.ok_or_else(|| {
|
|
crate::ErrorKind::InputError(
|
|
"Invalid project ID specified!".to_string(),
|
|
)
|
|
})?;
|
|
|
|
// Only fetch the pack icon when icon_url is provided (new profile).
|
|
// When installing to an existing profile (e.g. server projects),
|
|
// icon_url is None and we preserve the profile's existing icon.
|
|
let icon = if has_icon_url {
|
|
emit_loading(&loading_bar, 10.0, Some("Retrieving icon"))?;
|
|
let fetched = if let Some(icon_url) = project.icon_url {
|
|
let state = State::get().await?;
|
|
let icon_bytes =
|
|
fetch(&icon_url, None, &state.fetch_semaphore, &state.pool)
|
|
.await?;
|
|
|
|
let filename = icon_url.rsplit('/').next();
|
|
|
|
if let Some(filename) = filename {
|
|
Some(
|
|
write_cached_icon(
|
|
filename,
|
|
&state.directories.caches_dir(),
|
|
icon_bytes,
|
|
&state.io_semaphore,
|
|
)
|
|
.await?,
|
|
)
|
|
} else {
|
|
None
|
|
}
|
|
} else {
|
|
None
|
|
};
|
|
emit_loading(&loading_bar, 10.0, None)?;
|
|
fetched
|
|
} else {
|
|
emit_loading(&loading_bar, 20.0, None)?;
|
|
None
|
|
};
|
|
|
|
// Set the icon immediately so the UI shows it during download.
|
|
if let Some(ref icon_path) = icon {
|
|
let _ =
|
|
profile::edit_icon(&profile_path, Some(icon_path.as_path())).await;
|
|
}
|
|
|
|
Ok(CreatePack {
|
|
file,
|
|
description: CreatePackDescription {
|
|
icon,
|
|
override_title: Some(title),
|
|
project_id: Some(project_id),
|
|
version_id: Some(version_id),
|
|
existing_loading_bar: Some(loading_bar),
|
|
profile_path,
|
|
},
|
|
})
|
|
}
|
|
|
|
#[tracing::instrument]
|
|
|
|
pub async fn generate_pack_from_file(
|
|
path: PathBuf,
|
|
profile_path: String,
|
|
) -> crate::Result<CreatePack> {
|
|
let file = io::read(&path).await?;
|
|
Ok(CreatePack {
|
|
file: bytes::Bytes::from(file),
|
|
description: CreatePackDescription {
|
|
icon: None,
|
|
override_title: None,
|
|
project_id: None,
|
|
version_id: None,
|
|
existing_loading_bar: None,
|
|
profile_path,
|
|
},
|
|
})
|
|
}
|
|
|
|
/// Sets generated profile attributes to the pack ones (using profile::edit)
|
|
/// This includes the pack name, icon, game version, loader version, and loader
|
|
pub async fn set_profile_information(
|
|
profile_path: String,
|
|
description: &CreatePackDescription,
|
|
backup_name: &str,
|
|
dependencies: &HashMap<PackDependency, String>,
|
|
ignore_lock: bool, // do not change locked status
|
|
) -> crate::Result<()> {
|
|
let mut game_version: Option<&String> = None;
|
|
let mut mod_loader = None;
|
|
let mut loader_version = None;
|
|
|
|
for (key, value) in dependencies {
|
|
match key {
|
|
PackDependency::Forge => {
|
|
mod_loader = Some(ModLoader::Forge);
|
|
loader_version = Some(value);
|
|
}
|
|
PackDependency::NeoForge => {
|
|
mod_loader = Some(ModLoader::NeoForge);
|
|
loader_version = Some(value);
|
|
}
|
|
PackDependency::FabricLoader => {
|
|
mod_loader = Some(ModLoader::Fabric);
|
|
loader_version = Some(value);
|
|
}
|
|
PackDependency::QuiltLoader => {
|
|
mod_loader = Some(ModLoader::Quilt);
|
|
loader_version = Some(value);
|
|
}
|
|
PackDependency::Minecraft => game_version = Some(value),
|
|
}
|
|
}
|
|
|
|
let Some(game_version) = game_version else {
|
|
return Err(crate::ErrorKind::InputError(
|
|
"Pack did not specify Minecraft version".to_string(),
|
|
)
|
|
.into());
|
|
};
|
|
|
|
let mod_loader = mod_loader.unwrap_or(ModLoader::Vanilla);
|
|
let loader_version = if mod_loader != ModLoader::Vanilla {
|
|
crate::launcher::get_loader_version_from_profile(
|
|
game_version,
|
|
mod_loader,
|
|
loader_version.cloned().as_deref(),
|
|
)
|
|
.await?
|
|
} else {
|
|
None
|
|
};
|
|
// Sets values in profile
|
|
crate::api::profile::edit(&profile_path, |prof| {
|
|
prof.name = description
|
|
.override_title
|
|
.clone()
|
|
.unwrap_or_else(|| backup_name.to_string());
|
|
prof.install_stage = ProfileInstallStage::PackInstalling;
|
|
|
|
if let Some(ref project_id) = description.project_id
|
|
&& let Some(ref version_id) = description.version_id
|
|
{
|
|
prof.linked_data = Some(LinkedData {
|
|
project_id: project_id.clone(),
|
|
version_id: version_id.clone(),
|
|
locked: if !ignore_lock {
|
|
true
|
|
} else {
|
|
prof.linked_data.as_ref().is_none_or(|x| x.locked)
|
|
},
|
|
})
|
|
}
|
|
|
|
// Only update the icon if the pack provides one.
|
|
// When installing to an existing profile, icon is None
|
|
// and we preserve the profile's existing icon.
|
|
if let Some(ref icon) = description.icon {
|
|
prof.icon_path = Some(icon.to_string_lossy().to_string());
|
|
}
|
|
prof.game_version.clone_from(game_version);
|
|
prof.loader_version = loader_version.clone().map(|x| x.id);
|
|
prof.loader = mod_loader;
|
|
|
|
async { Ok(()) }
|
|
})
|
|
.await?;
|
|
Ok(())
|
|
}
|