refactor: align files tab with content tab design (#5621)

* 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>
This commit is contained in:
Calum H.
2026-03-26 18:55:15 +00:00
committed by GitHub
parent 706eb800cb
commit 381ea51cce
170 changed files with 8052 additions and 4571 deletions

View File

@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "\n SELECT world_type, world_id, display_status\n FROM attached_world_data\n WHERE profile_path = $1\n ",
"query": "\n SELECT world_type, world_id, display_status, project_id, content_kind\n FROM attached_world_data\n WHERE profile_path = $1\n ",
"describe": {
"columns": [
{
@@ -17,6 +17,16 @@
"name": "display_status",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "project_id",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "content_kind",
"ordinal": 4,
"type_info": "Text"
}
],
"parameters": {
@@ -25,8 +35,10 @@
"nullable": [
false,
false,
false
false,
true,
true
]
},
"hash": "fd834e256e142820f25305ccffaf07f736c5772045b973dcc10573b399111344"
"hash": "4735f82db7b281e1380ea7c08ed715d25e0ca23a6c190c4bf14332033f4583db"
}

View File

@@ -1,20 +0,0 @@
{
"db_name": "SQLite",
"query": "\n SELECT data as \"data?: sqlx::types::Json<CacheValue>\"\n FROM cache\n WHERE data_type = $1 AND id = $2\n ",
"describe": {
"columns": [
{
"name": "data?: sqlx::types::Json<CacheValue>",
"ordinal": 0,
"type_info": "Null"
}
],
"parameters": {
"Right": 2
},
"nullable": [
true
]
},
"hash": "4d66e2bfedb7a31244d24858acf9b73a6289c1a90fb0988c4f5f5f64be01c4ec"
}

View File

@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO attached_world_data (profile_path, world_type, world_id, project_id)\nVALUES ($1, $2, $3, $4)\nON CONFLICT (profile_path, world_type, world_id) DO UPDATE\n SET project_id = $4",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "53c45c036387a8dc8d978a6e4d28524a852b8dec409891cf2165876fb7ff0314"
}

View File

@@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "\n SELECT display_status, project_id, content_kind\n FROM attached_world_data\n WHERE profile_path = $1 and world_type = $2 and world_id = $3\n ",
"describe": {
"columns": [
{
"name": "display_status",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "project_id",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "content_kind",
"ordinal": 2,
"type_info": "Text"
}
],
"parameters": {
"Right": 3
},
"nullable": [
false,
true,
true
]
},
"hash": "613192379e1fb8fd1becf2f6330365bb5bc2a8f0be01f6e4eef708474f38a3d0"
}

View File

@@ -1,20 +0,0 @@
{
"db_name": "SQLite",
"query": "\n SELECT display_status\n FROM attached_world_data\n WHERE profile_path = $1 and world_type = $2 and world_id = $3\n ",
"describe": {
"columns": [
{
"name": "display_status",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 3
},
"nullable": [
false
]
},
"hash": "a2184fc5d62570aec0a15c0a8d628a597e90c2bf7ce5dc1b39edb6977e2f6da6"
}

View File

@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO attached_world_data (profile_path, world_type, world_id, content_kind)\nVALUES ($1, $2, $3, $4)\nON CONFLICT (profile_path, world_type, world_id) DO UPDATE\n SET content_kind = $4",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "dcf7340800c1d6ca82de2092b477a41a9622ce891732300f029f34545954128e"
}

View File

@@ -0,0 +1,2 @@
ALTER TABLE attached_world_data ADD COLUMN project_id TEXT;
ALTER TABLE attached_world_data ADD COLUMN content_kind TEXT;

View File

@@ -68,10 +68,23 @@ pub async fn get_importable_instances(
.await
.unwrap_or_else(|| "instances".to_string()),
ImportLauncherType::Unknown => {
return Err(crate::ErrorKind::InputError(
"Launcher type Unknown".to_string(),
)
.into());
let types = [
ImportLauncherType::MultiMC,
ImportLauncherType::PrismLauncher,
ImportLauncherType::ATLauncher,
ImportLauncherType::GDLauncher,
ImportLauncherType::Curseforge,
];
for lt in types {
if let Ok(instances) =
Box::pin(get_importable_instances(lt, base_path.clone()))
.await
&& !instances.is_empty()
{
return Ok(instances);
}
}
return Ok(Vec::new());
}
};
@@ -144,10 +157,39 @@ pub async fn import_instance(
.await
}
ImportLauncherType::Unknown => {
return Err(crate::ErrorKind::InputError(
"Launcher type Unknown".to_string(),
)
.into());
let types = [
ImportLauncherType::MultiMC,
ImportLauncherType::PrismLauncher,
ImportLauncherType::ATLauncher,
ImportLauncherType::GDLauncher,
ImportLauncherType::Curseforge,
];
let mut matched = false;
for lt in types {
if let Ok(instances) =
Box::pin(get_importable_instances(lt, base_path.clone()))
.await
&& instances.contains(&instance_folder)
{
matched = true;
Box::pin(import_instance(
profile_path,
lt,
base_path,
instance_folder,
))
.await?;
break;
}
}
if !matched {
return Err(crate::ErrorKind::InputError(
"Could not determine launcher type for the given path"
.to_string(),
)
.into());
}
return Ok(());
}
};

View File

@@ -149,13 +149,33 @@ pub async fn install_zipped_mrpack_files(
file_hashes.push(hash);
}
let project_ids: Vec<String> = pack
.files
.iter()
.filter_map(|f| {
f.downloads.iter().find_map(|url| {
let parts: Vec<&str> = url.split('/').collect();
let data_idx = parts.iter().position(|&p| p == "data")?;
parts.get(data_idx + 1).map(|s| s.to_string())
})
})
.collect::<std::collections::HashSet<_>>()
.into_iter()
.collect();
tracing::info!(
"Caching {} modpack file hashes for version {}",
"Caching {} modpack file hashes and {} project IDs for version {}",
file_hashes.len(),
project_ids.len(),
version_id
);
CachedEntry::cache_modpack_files(version_id, file_hashes, &state.pool)
.await?;
CachedEntry::cache_modpack_files(
version_id,
file_hashes,
project_ids,
&state.pool,
)
.await?;
} else {
tracing::warn!(
"No version_id available, skipping modpack file hash caching"

View File

@@ -142,6 +142,10 @@ pub enum WorldDetails {
index: usize,
address: String,
pack_status: ServerPackStatus,
#[serde(skip_serializing_if = "Option::is_none")]
project_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
content_kind: Option<String>,
},
}
@@ -426,6 +430,8 @@ async fn get_server_worlds_in_profile(
index,
address: server.ip,
pack_status: server.accept_textures.into(),
project_id: None,
content_kind: None,
},
};
worlds.push(world);
@@ -460,6 +466,15 @@ async fn get_server_worlds_in_profile(
fn attach_world_data_to_world(world: &mut World, data: &AttachedWorldData) {
world.display_status = data.display_status;
if let WorldDetails::Server {
project_id,
content_kind,
..
} = &mut world.details
{
*project_id = data.project_id.clone();
*content_kind = data.content_kind.clone();
}
}
pub async fn set_world_display_status(
@@ -712,9 +727,12 @@ async fn try_get_world_session_lock(
pub async fn add_server_to_profile(
profile_path: &Path,
profile_path_id: &str,
name: String,
address: String,
pack_status: ServerPackStatus,
project_id: Option<String>,
content_kind: Option<String>,
) -> Result<usize> {
let mut servers = servers_data::read(profile_path).await?;
let insert_index = servers
@@ -725,13 +743,38 @@ pub async fn add_server_to_profile(
insert_index,
servers_data::ServerData {
name,
ip: address,
ip: address.clone(),
accept_textures: pack_status.into(),
hidden: false,
icon: None,
},
);
servers_data::write(profile_path, &servers).await?;
if project_id.is_some() || content_kind.is_some() {
let state = State::get().await?;
if let Some(project_id) = &project_id {
attached_world_data::set_project_id(
profile_path_id,
WorldType::Server,
&address,
project_id,
&state.pool,
)
.await?;
}
if let Some(content_kind) = &content_kind {
attached_world_data::set_content_kind(
profile_path_id,
WorldType::Server,
&address,
content_kind,
&state.pool,
)
.await?;
}
}
Ok(insert_index)
}

View File

@@ -5,6 +5,8 @@ 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 {
@@ -18,7 +20,7 @@ impl AttachedWorldData {
let attached_data = sqlx::query!(
"
SELECT display_status
SELECT display_status, project_id, content_kind
FROM attached_world_data
WHERE profile_path = $1 and world_type = $2 and world_id = $3
",
@@ -31,6 +33,8 @@ impl AttachedWorldData {
Ok(attached_data.map(|x| AttachedWorldData {
display_status: DisplayStatus::from_string(&x.display_status),
project_id: x.project_id,
content_kind: x.content_kind,
}))
}
@@ -40,7 +44,7 @@ impl AttachedWorldData {
) -> crate::Result<HashMap<(WorldType, String), Self>> {
let attached_data = sqlx::query!(
"
SELECT world_type, world_id, display_status
SELECT world_type, world_id, display_status, project_id, content_kind
FROM attached_world_data
WHERE profile_path = $1
",
@@ -57,7 +61,11 @@ impl AttachedWorldData {
DisplayStatus::from_string(&x.display_status);
(
(world_type, x.world_id),
AttachedWorldData { display_status },
AttachedWorldData {
display_status,
project_id: x.project_id,
content_kind: x.content_kind,
},
)
})
.collect())
@@ -120,3 +128,5 @@ macro_rules! attached_data_setter {
}
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");

View File

@@ -148,6 +148,8 @@ impl CacheValueType {
pub struct CachedModpackFiles {
pub version_id: String,
pub file_hashes: Vec<String>,
#[serde(default)]
pub project_ids: Vec<String>,
}
/// Cached list of versions for a project (without changelogs for fast loading)
@@ -1831,11 +1833,13 @@ impl CachedEntry {
pub async fn cache_modpack_files(
version_id: &str,
file_hashes: Vec<String>,
project_ids: Vec<String>,
pool: &SqlitePool,
) -> crate::Result<()> {
let data = CachedModpackFiles {
version_id: version_id.to_string(),
file_hashes,
project_ids,
};
let entry = CachedEntry {

View File

@@ -308,49 +308,52 @@ pub async fn get_content_items(
.get_projects(cache_behaviour, pool, fetch_semaphore)
.await?;
let modpack_hashes: HashSet<String> = if let Some(ref linked_data) =
profile.linked_data
{
let modpack_ids = if let Some(ref linked_data) = profile.linked_data {
if linked_data.version_id.is_empty() {
HashSet::new()
None
} else {
tracing::info!(
"Fetching modpack file hashes for version_id={}, project_id={}",
"Fetching modpack identifiers for version_id={}, project_id={}",
linked_data.version_id,
linked_data.project_id
);
match get_modpack_file_hashes(
match get_modpack_identifiers(
&linked_data.version_id,
pool,
fetch_semaphore,
)
.await
{
Ok(hashes) => {
Ok(ids) => {
tracing::info!(
"Got {} modpack file hashes for version {}",
hashes.len(),
"Got {} modpack file hashes, {} project IDs for version {}",
ids.hashes.len(),
ids.project_ids.len(),
linked_data.version_id
);
hashes
Some(ids)
}
Err(e) => {
tracing::error!(
"Failed to fetch modpack file hashes for version {}: {}",
"Failed to fetch modpack identifiers for version {}: {}",
linked_data.version_id,
e
);
HashSet::new()
None
}
}
}
} else {
HashSet::new()
None
};
let user_files: Vec<(String, ProfileFile)> = all_files
.into_iter()
.filter(|(_, file)| !modpack_hashes.contains(&file.hash))
.filter(|(_, file)| {
modpack_ids
.as_ref()
.is_none_or(|ids| !ids.is_modpack_file(file))
})
.collect();
profile_files_to_content_items(
@@ -633,16 +636,16 @@ pub async fn get_linked_modpack_content(
.get_projects(cache_behaviour, pool, fetch_semaphore)
.await?;
let modpack_hashes: HashSet<String> = match get_modpack_file_hashes(
let modpack_ids = match get_modpack_identifiers(
&linked_data.version_id,
pool,
fetch_semaphore,
)
.await
{
Ok(hashes) => hashes,
Ok(ids) => ids,
Err(e) => {
tracing::warn!("Failed to fetch modpack file hashes: {}", e);
tracing::warn!("Failed to fetch modpack identifiers: {}", e);
return Ok(Vec::new());
}
};
@@ -650,7 +653,7 @@ pub async fn get_linked_modpack_content(
// Inverse of get_content_items: keep only modpack-bundled files
let modpack_files: Vec<(String, ProfileFile)> = all_files
.into_iter()
.filter(|(_, file)| modpack_hashes.contains(&file.hash))
.filter(|(_, file)| modpack_ids.is_modpack_file(file))
.collect();
profile_files_to_content_items(
@@ -778,23 +781,78 @@ pub async fn dependencies_to_content_items(
Ok(items)
}
/// Gets SHA1 hashes of all files in a modpack version.
/// Modpack file identifiers: hashes for exact matching and project IDs for
/// matching files whose version was switched by the user.
struct ModpackIdentifiers {
hashes: HashSet<String>,
project_ids: HashSet<String>,
}
impl ModpackIdentifiers {
fn is_modpack_file(&self, file: &ProfileFile) -> bool {
self.hashes.contains(&file.hash)
|| file
.metadata
.as_ref()
.is_some_and(|m| self.project_ids.contains(&m.project_id))
}
}
/// Gets SHA1 hashes and project IDs of all files in a modpack version.
/// Checks cache first, falls back to downloading mrpack if not cached.
async fn get_modpack_file_hashes(
async fn get_modpack_identifiers(
version_id: &str,
pool: &SqlitePool,
fetch_semaphore: &FetchSemaphore,
) -> crate::Result<HashSet<String>> {
) -> crate::Result<ModpackIdentifiers> {
if let Some(cached) =
CachedEntry::get_modpack_files(version_id, pool, fetch_semaphore)
.await?
{
if !cached.project_ids.is_empty() {
tracing::info!(
"Cache hit: {} modpack file hashes, {} project IDs for version {}",
cached.file_hashes.len(),
cached.project_ids.len(),
version_id
);
return Ok(ModpackIdentifiers {
hashes: cached.file_hashes.into_iter().collect(),
project_ids: cached.project_ids.into_iter().collect(),
});
}
// Legacy cache entry without project_ids — resolve via hash lookup API
tracing::info!(
"Cache hit: {} modpack file hashes for version {}",
cached.file_hashes.len(),
"Legacy cache entry without project IDs, resolving via API for version {}",
version_id
);
return Ok(cached.file_hashes.into_iter().collect());
let hash_refs: Vec<&str> =
cached.file_hashes.iter().map(|s| s.as_str()).collect();
let files =
CachedEntry::get_file_many(&hash_refs, None, pool, fetch_semaphore)
.await?;
let project_ids: Vec<String> = files
.iter()
.map(|f| f.project_id.clone())
.collect::<HashSet<_>>()
.into_iter()
.collect();
// Update cache with project_ids for next time
CachedEntry::cache_modpack_files(
version_id,
cached.file_hashes.clone(),
project_ids.clone(),
pool,
)
.await?;
return Ok(ModpackIdentifiers {
hashes: cached.file_hashes.into_iter().collect(),
project_ids: project_ids.into_iter().collect(),
});
}
tracing::warn!(
@@ -863,6 +921,20 @@ async fn get_modpack_file_hashes(
.filter_map(|f| f.hashes.get(&PackFileHash::Sha1).cloned())
.collect();
let project_ids: Vec<String> = pack
.files
.iter()
.filter_map(|f| {
f.downloads.iter().find_map(|url| {
let parts: Vec<&str> = url.split('/').collect();
let data_idx = parts.iter().position(|&p| p == "data")?;
parts.get(data_idx + 1).map(|s| s.to_string())
})
})
.collect::<HashSet<_>>()
.into_iter()
.collect();
// Also hash files from overrides folders (these aren't in modrinth.index.json)
let override_entries: Vec<usize> = zip_reader
.file()
@@ -888,7 +960,16 @@ async fn get_modpack_file_hashes(
hashes.push(hash);
}
CachedEntry::cache_modpack_files(version_id, hashes.clone(), pool).await?;
CachedEntry::cache_modpack_files(
version_id,
hashes.clone(),
project_ids.clone(),
pool,
)
.await?;
Ok(hashes.into_iter().collect())
Ok(ModpackIdentifiers {
hashes: hashes.into_iter().collect(),
project_ids: project_ids.into_iter().collect(),
})
}