You've already forked AstralRinth
forked from didirus/AstralRinth
Finalize 0.8.1 release (#2182)
* Finalize 0.8.1 release * Remove console.logs * Fix build * add default to users * update release conf * fix again? * fix build (again) * actually fix build * Update config dir * Update config dir * Fix dir again
This commit is contained in:
@@ -369,6 +369,8 @@ pub struct User {
|
||||
pub bio: Option<String>,
|
||||
pub created: DateTime<Utc>,
|
||||
pub role: String,
|
||||
#[serde(default)]
|
||||
pub badges: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
|
||||
@@ -273,6 +273,7 @@ where
|
||||
bio: x.user.bio,
|
||||
created: x.user.created,
|
||||
role: x.user.role,
|
||||
badges: 0,
|
||||
};
|
||||
|
||||
cached_entries.push(CacheValue::User(
|
||||
|
||||
@@ -72,7 +72,11 @@ impl State {
|
||||
.await?;
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
let res = state.discord_rpc.clear_to_default(true).await;
|
||||
let res = tokio::try_join!(
|
||||
state.discord_rpc.clear_to_default(true),
|
||||
Profile::refresh_all(),
|
||||
ModrinthCredentials::refresh_all(),
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
tracing::error!("Error running discord RPC: {e}");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::config::MODRINTH_API_URL;
|
||||
use crate::state::{CacheBehaviour, CachedEntry};
|
||||
use crate::util::fetch::{fetch_advanced, FetchSemaphore};
|
||||
use chrono::{DateTime, Duration, TimeZone, Utc};
|
||||
use dashmap::DashMap;
|
||||
@@ -172,6 +173,23 @@ impl ModrinthCredentials {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn refresh_all() -> crate::Result<()> {
|
||||
let state = crate::State::get().await?;
|
||||
let all = Self::get_all(&state.pool).await?;
|
||||
|
||||
let user_ids = all.into_iter().map(|x| x.0).collect::<Vec<_>>();
|
||||
|
||||
CachedEntry::get_user_many(
|
||||
&user_ids.iter().map(|x| &**x).collect::<Vec<_>>(),
|
||||
Some(CacheBehaviour::Bypass),
|
||||
&state.pool,
|
||||
&state.fetch_semaphore,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
|
||||
@@ -536,6 +536,93 @@ impl Profile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn refresh_all() -> crate::Result<()> {
|
||||
let state = crate::State::get().await?;
|
||||
let all = Self::get_all(&state.pool).await?;
|
||||
|
||||
let mut keys = vec![];
|
||||
|
||||
for profile in &all {
|
||||
let path =
|
||||
crate::api::profile::get_full_path(&profile.path).await?;
|
||||
|
||||
for project_type in ProjectType::iterator() {
|
||||
let folder = project_type.get_folder();
|
||||
let path = path.join(folder);
|
||||
|
||||
if path.exists() {
|
||||
for subdirectory in std::fs::read_dir(&path)
|
||||
.map_err(|e| io::IOError::with_path(e, &path))?
|
||||
{
|
||||
let subdirectory =
|
||||
subdirectory.map_err(io::IOError::from)?.path();
|
||||
if subdirectory.is_file() {
|
||||
if let Some(file_name) = subdirectory
|
||||
.file_name()
|
||||
.and_then(|x| x.to_str())
|
||||
{
|
||||
let file_size = subdirectory
|
||||
.metadata()
|
||||
.map_err(io::IOError::from)?
|
||||
.len();
|
||||
|
||||
keys.push(format!(
|
||||
"{file_size}-{}/{folder}/{file_name}",
|
||||
profile.path
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let file_hashes = CachedEntry::get_file_hash_many(
|
||||
&keys.iter().map(|s| &**s).collect::<Vec<_>>(),
|
||||
None,
|
||||
&state.pool,
|
||||
&state.fetch_semaphore,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let file_updates = file_hashes
|
||||
.iter()
|
||||
.filter_map(|x| {
|
||||
all.iter().find(|prof| x.path.contains(&prof.path)).map(
|
||||
|profile| {
|
||||
format!(
|
||||
"{}-{}-{}",
|
||||
x.hash,
|
||||
profile.loader.as_str(),
|
||||
profile.game_version
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let file_hashes_ref =
|
||||
file_hashes.iter().map(|x| &*x.hash).collect::<Vec<_>>();
|
||||
let file_updates_ref =
|
||||
file_updates.iter().map(|x| &**x).collect::<Vec<_>>();
|
||||
tokio::try_join!(
|
||||
CachedEntry::get_file_many(
|
||||
&file_hashes_ref,
|
||||
Some(CacheBehaviour::MustRevalidate),
|
||||
&state.pool,
|
||||
&state.fetch_semaphore,
|
||||
),
|
||||
CachedEntry::get_file_update_many(
|
||||
&file_updates_ref,
|
||||
Some(CacheBehaviour::MustRevalidate),
|
||||
&state.pool,
|
||||
&state.fetch_semaphore,
|
||||
)
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_projects(
|
||||
&self,
|
||||
cache_behaviour: Option<CacheBehaviour>,
|
||||
|
||||
Reference in New Issue
Block a user