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:
@@ -326,6 +326,7 @@ impl FriendsSocket {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
semaphore,
|
||||
exec,
|
||||
)
|
||||
@@ -358,6 +359,7 @@ impl FriendsSocket {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
semaphore,
|
||||
exec,
|
||||
)
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
use crate::pack::install_from::{PackFileHash, PackFormat};
|
||||
use crate::state::profiles::{Profile, ProfileFile, ProjectType};
|
||||
use crate::state::{CacheBehaviour, CachedEntry};
|
||||
use crate::util::fetch::{FetchSemaphore, fetch_mirrors, sha1_async};
|
||||
use crate::util::fetch::{
|
||||
DownloadMeta, DownloadReason, FetchSemaphore, fetch_mirrors, sha1_async,
|
||||
};
|
||||
use async_zip::base::read::seek::ZipFileReader;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::SqlitePool;
|
||||
@@ -319,6 +321,7 @@ pub async fn get_content_items(
|
||||
);
|
||||
match get_modpack_identifiers(
|
||||
&linked_data.version_id,
|
||||
profile,
|
||||
pool,
|
||||
fetch_semaphore,
|
||||
)
|
||||
@@ -638,6 +641,7 @@ pub async fn get_linked_modpack_content(
|
||||
|
||||
let modpack_ids = match get_modpack_identifiers(
|
||||
&linked_data.version_id,
|
||||
profile,
|
||||
pool,
|
||||
fetch_semaphore,
|
||||
)
|
||||
@@ -802,6 +806,7 @@ impl ModpackIdentifiers {
|
||||
/// Checks cache first, falls back to downloading mrpack if not cached.
|
||||
async fn get_modpack_identifiers(
|
||||
version_id: &str,
|
||||
profile: &crate::state::Profile,
|
||||
pool: &SqlitePool,
|
||||
fetch_semaphore: &FetchSemaphore,
|
||||
) -> crate::Result<ModpackIdentifiers> {
|
||||
@@ -880,9 +885,16 @@ async fn get_modpack_identifiers(
|
||||
))
|
||||
})?;
|
||||
|
||||
let download_meta = DownloadMeta {
|
||||
reason: DownloadReason::Modpack,
|
||||
game_version: profile.game_version.clone(),
|
||||
loader: profile.loader.as_str().to_string(),
|
||||
};
|
||||
|
||||
let mrpack_bytes = fetch_mirrors(
|
||||
&[&primary_file.url],
|
||||
primary_file.hashes.get("sha1").map(|s| s.as_str()),
|
||||
Some(&download_meta),
|
||||
fetch_semaphore,
|
||||
pool,
|
||||
)
|
||||
|
||||
@@ -35,6 +35,7 @@ impl ModrinthCredentials {
|
||||
None,
|
||||
Some(("Authorization", &*creds.session)),
|
||||
None,
|
||||
None,
|
||||
semaphore,
|
||||
exec,
|
||||
)
|
||||
@@ -226,6 +227,7 @@ async fn fetch_info(
|
||||
None,
|
||||
Some(("Authorization", token)),
|
||||
None,
|
||||
None,
|
||||
semaphore,
|
||||
exec,
|
||||
)
|
||||
|
||||
@@ -1110,10 +1110,25 @@ impl Profile {
|
||||
pub async fn add_project_version(
|
||||
profile_path: &str,
|
||||
version_id: &str,
|
||||
reason: util::fetch::DownloadReason,
|
||||
pool: &SqlitePool,
|
||||
fetch_semaphore: &FetchSemaphore,
|
||||
io_semaphore: &IoSemaphore,
|
||||
) -> crate::Result<String> {
|
||||
let profile =
|
||||
Self::get(profile_path, pool).await?.ok_or_else(|| {
|
||||
crate::ErrorKind::UnmanagedProfileError(
|
||||
profile_path.to_string(),
|
||||
)
|
||||
.as_error()
|
||||
})?;
|
||||
|
||||
let download_meta = util::fetch::DownloadMeta {
|
||||
reason,
|
||||
game_version: profile.game_version.clone(),
|
||||
loader: profile.loader.as_str().to_string(),
|
||||
};
|
||||
|
||||
let version =
|
||||
CachedEntry::get_version(version_id, None, pool, fetch_semaphore)
|
||||
.await?
|
||||
@@ -1139,6 +1154,7 @@ impl Profile {
|
||||
let bytes = util::fetch::fetch(
|
||||
&file.url,
|
||||
file.hashes.get("sha1").map(|x| &**x),
|
||||
Some(&download_meta),
|
||||
fetch_semaphore,
|
||||
pool,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user