Have app send download analytics meta (#5954)

* wip: add download reasons to app

* update how download meta is gathered

* cargo fmt

* prepr frontend
This commit is contained in:
aecsocket
2026-04-30 20:55:47 +01:00
committed by GitHub
parent 38a39feef1
commit 1875b89556
20 changed files with 195 additions and 32 deletions

View File

@@ -90,6 +90,7 @@ pub async fn auto_install_java(java_version: u32) -> crate::Result<PathBuf> {
None,
None,
None,
None,
Some((&loading_bar, 80.0)),
&state.fetch_semaphore,
&state.pool,

View File

@@ -78,9 +78,14 @@ pub async fn import_curseforge(
thumbnail_url: Some(thumbnail_url),
}) = minecraft_instance.installed_modpack.clone()
{
let icon_bytes =
fetch(&thumbnail_url, None, &state.fetch_semaphore, &state.pool)
.await?;
let icon_bytes = fetch(
&thumbnail_url,
None,
None,
&state.fetch_semaphore,
&state.pool,
)
.await?;
let filename = thumbnail_url.rsplit('/').next_back();
if let Some(filename) = filename {
icon = Some(

View File

@@ -4,9 +4,12 @@ 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,
CacheBehaviour, CachedEntry, LinkedData, Profile, ProfileInstallStage,
SideType,
};
use crate::util::fetch::{
DownloadMeta, DownloadReason, fetch, fetch_advanced, write_cached_icon,
};
use crate::util::fetch::{fetch, fetch_advanced, write_cached_icon};
use crate::util::io;
use path_util::SafeRelativeUtf8UnixPathBuf;
@@ -287,12 +290,29 @@ pub async fn generate_pack_from_version_id(
)
})?;
let profile =
Profile::get(&profile_path, &state.pool)
.await?
.ok_or_else(|| {
crate::ErrorKind::UnmanagedProfileError(
profile_path.to_string(),
)
.as_error()
})?;
let download_meta = DownloadMeta {
reason: DownloadReason::Modpack,
game_version: profile.game_version.clone(),
loader: profile.loader.as_str().to_string(),
};
let file = fetch_advanced(
Method::GET,
&url,
hash.map(|x| &**x),
None,
None,
Some(&download_meta),
Some((&loading_bar, 70.0)),
&state.fetch_semaphore,
&state.pool,
@@ -320,9 +340,14 @@ pub async fn generate_pack_from_version_id(
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 icon_bytes = fetch(
&icon_url,
None,
None,
&state.fetch_semaphore,
&state.pool,
)
.await?;
let filename = icon_url.rsplit('/').next();

View File

@@ -6,9 +6,12 @@ use crate::pack::install_from::{
EnvType, PackFile, PackFileHash, set_profile_information,
};
use crate::state::{
CacheBehaviour, CachedEntry, ProfileInstallStage, SideType, cache_file_hash,
CacheBehaviour, CachedEntry, Profile, ProfileInstallStage, SideType,
cache_file_hash,
};
use crate::util::fetch::{
DownloadMeta, DownloadReason, fetch_mirrors, sha1_async, write,
};
use crate::util::fetch::{fetch_mirrors, sha1_async, write};
use crate::util::io;
use crate::{State, profile};
use async_zip::base::read::seek::ZipFileReader;
@@ -207,6 +210,22 @@ pub async fn install_zipped_mrpack_files(
)
.await?;
let profile =
Profile::get(&profile_path, &state.pool)
.await?
.ok_or_else(|| {
crate::ErrorKind::UnmanagedProfileError(
profile_path.to_string(),
)
.as_error()
})?;
let download_meta = DownloadMeta {
reason: DownloadReason::Modpack,
game_version: profile.game_version.clone(),
loader: profile.loader.as_str().to_string(),
};
let num_files = pack.files.len();
loading_try_for_each_concurrent(
futures::stream::iter(pack.files.into_iter())
@@ -218,6 +237,7 @@ pub async fn install_zipped_mrpack_files(
None,
|project| {
let profile_path = profile_path.clone();
let download_meta = download_meta.clone();
async move {
//TODO: Future update: prompt user for optional files in a modpack
if let Some(env) = project.env
@@ -235,6 +255,7 @@ pub async fn install_zipped_mrpack_files(
.map(|x| &**x)
.collect::<Vec<&str>>(),
project.hashes.get(&PackFileHash::Sha1).map(|x| &**x),
Some(&download_meta),
&state.fetch_semaphore,
&state.pool,
)

View File

@@ -109,6 +109,7 @@ pub async fn profile_create(
let fetched = crate::util::fetch::fetch(
icon,
None,
None,
&state.fetch_semaphore,
&state.pool,
)

View File

@@ -461,6 +461,7 @@ pub async fn update_project(
let mut path = Profile::add_project_version(
profile_path,
update_version,
fetch::DownloadReason::Standalone,
&state.pool,
&state.fetch_semaphore,
&state.io_semaphore,
@@ -501,11 +502,14 @@ pub async fn update_project(
pub async fn add_project_from_version(
profile_path: &str,
version_id: &str,
reason: fetch::DownloadReason,
) -> crate::Result<String> {
let state = State::get().await?;
let project_path = Profile::add_project_version(
profile_path,
version_id,
reason,
&state.pool,
&state.fetch_semaphore,
&state.io_semaphore,