Merge commit 'df1499047ccc8f39d756d5beba60651237aca1c0' into beta

This commit is contained in:
2025-08-10 19:54:24 +03:00
91 changed files with 9957 additions and 7832 deletions
+4 -3
View File
@@ -4,15 +4,16 @@ root = true
[*] [*]
charset = utf-8 charset = utf-8
indent_style = space indent_style = space
indent_size = 2 indent_size = 4
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
max_line_length = 100 max_line_length = 100
[*.md] [*.md]
indent_size = 2
max_line_length = off max_line_length = off
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.{rs,java,kts}] [*.{json,yml,yaml,ts,vue,scss,css,html,js,cjs,mjs,gltf,prettierrc}]
indent_size = 4 indent_size = 2
Generated
+182 -195
View File
File diff suppressed because it is too large Load Diff
+36 -36
View File
@@ -25,31 +25,31 @@ actix-ws = "0.3.0"
argon2 = { version = "0.5.3", features = ["std"] } argon2 = { version = "0.5.3", features = ["std"] }
ariadne = { path = "packages/ariadne" } ariadne = { path = "packages/ariadne" }
async_zip = "0.0.17" async_zip = "0.0.17"
async-compression = { version = "0.4.25", default-features = false } async-compression = { version = "0.4.27", default-features = false }
async-recursion = "1.1.1" async-recursion = "1.1.1"
async-stripe = { version = "0.41.0", default-features = false, features = [ async-stripe = { version = "0.41.0", default-features = false, features = [
"runtime-tokio-hyper-rustls", "runtime-tokio-hyper-rustls",
] } ] }
async-trait = "0.1.88" async-trait = "0.1.88"
async-tungstenite = { version = "0.29.1", default-features = false, features = [ async-tungstenite = { version = "0.30.0", default-features = false, features = [
"futures-03-sink", "futures-03-sink",
] } ] }
async-walkdir = "2.1.0" async-walkdir = "2.1.0"
base64 = "0.22.1" base64 = "0.22.1"
bitflags = "2.9.1" bitflags = "2.9.1"
bytemuck = "1.23.0" bytemuck = "1.23.1"
bytes = "1.10.1" bytes = "1.10.1"
censor = "0.3.0" censor = "0.3.0"
chardetng = "0.1.17" chardetng = "0.1.17"
chrono = "0.4.41" chrono = "0.4.41"
clap = "4.5.40" clap = "4.5.43"
clickhouse = "0.13.3" clickhouse = "0.13.3"
color-thief = "0.2.2" color-thief = "0.2.2"
console-subscriber = "0.4.1" console-subscriber = "0.4.1"
daedalus = { path = "packages/daedalus" } daedalus = { path = "packages/daedalus" }
dashmap = "6.1.0" dashmap = "6.1.0"
data-url = "0.3.1" data-url = "0.3.1"
deadpool-redis = "0.21.1" deadpool-redis = "0.22.0"
dirs = "6.0.0" dirs = "6.0.0"
discord-rich-presence = "0.2.5" discord-rich-presence = "0.2.5"
dotenv-build = "0.1.1" dotenv-build = "0.1.1"
@@ -57,7 +57,7 @@ dotenvy = "0.15.7"
dunce = "1.0.5" dunce = "1.0.5"
either = "1.15.0" either = "1.15.0"
encoding_rs = "0.8.35" encoding_rs = "0.8.35"
enumset = "1.1.6" enumset = "1.1.7"
flate2 = "1.1.2" flate2 = "1.1.2"
fs4 = { version = "0.13.1", default-features = false } fs4 = { version = "0.13.1", default-features = false }
futures = { version = "0.3.31", default-features = false } futures = { version = "0.3.31", default-features = false }
@@ -74,15 +74,15 @@ hyper-rustls = { version = "0.27.7", default-features = false, features = [
"ring", "ring",
"tls12", "tls12",
] } ] }
hyper-util = "0.1.14" hyper-util = "0.1.16"
iana-time-zone = "0.1.63" iana-time-zone = "0.1.63"
image = { version = "0.25.6", default-features = false, features = ["rayon"] } image = { version = "0.25.6", default-features = false, features = ["rayon"] }
indexmap = "2.9.0" indexmap = "2.10.0"
indicatif = "0.17.11" indicatif = "0.18.0"
itertools = "0.14.0" itertools = "0.14.0"
jemalloc_pprof = "0.7.0" jemalloc_pprof = "0.8.1"
json-patch = { version = "4.0.0", default-features = false } json-patch = { version = "4.0.0", default-features = false }
lettre = { version = "0.11.17", default-features = false, features = [ lettre = { version = "0.11.18", default-features = false, features = [
"builder", "builder",
"hostname", "hostname",
"pool", "pool",
@@ -92,24 +92,24 @@ lettre = { version = "0.11.17", default-features = false, features = [
"smtp-transport", "smtp-transport",
] } ] }
maxminddb = "0.26.0" maxminddb = "0.26.0"
meilisearch-sdk = { version = "0.28.0", default-features = false } meilisearch-sdk = { version = "0.29.1", default-features = false }
murmur2 = "0.1.0" murmur2 = "0.1.0"
native-dialog = "0.9.0" native-dialog = "0.9.0"
notify = { version = "8.0.0", default-features = false } notify = { version = "8.2.0", default-features = false }
notify-debouncer-mini = { version = "0.6.0", default-features = false } notify-debouncer-mini = { version = "0.7.0", default-features = false }
p256 = "0.13.2" p256 = "0.13.2"
paste = "1.0.15" paste = "1.0.15"
phf = { version = "0.12.1", features = ["macros"] } phf = { version = "0.12.1", features = ["macros"] }
png = "0.17.16" png = "0.17.16"
prometheus = "0.14.0" prometheus = "0.14.0"
quartz_nbt = "0.2.9" quartz_nbt = "0.2.9"
quick-xml = "0.37.5" quick-xml = "0.38.1"
rand = "=0.8.5" # Locked on 0.8 until argon2 and p256 update to 0.9 rand = "=0.8.5" # Locked on 0.8 until argon2 and p256 update to 0.9
rand_chacha = "=0.3.1" # Locked on 0.3 until we can update rand to 0.9 rand_chacha = "=0.3.1" # Locked on 0.3 until we can update rand to 0.9
redis = "=0.31.0" # Locked on 0.31 until deadpool-redis updates to 0.32 redis = "0.32.4"
regex = "1.11.1" regex = "1.11.1"
reqwest = { version = "0.12.20", default-features = false } reqwest = { version = "0.12.22", default-features = false }
rgb = "0.8.50" rgb = "0.8.52"
rust_decimal = { version = "1.37.2", features = [ rust_decimal = { version = "1.37.2", features = [
"serde-with-float", "serde-with-float",
"serde-with-str", "serde-with-str",
@@ -121,7 +121,7 @@ rust-s3 = { version = "0.35.1", default-features = false, features = [
"tokio-rustls-tls", "tokio-rustls-tls",
] } ] }
rusty-money = "0.4.1" rusty-money = "0.4.1"
sentry = { version = "0.41.0", default-features = false, features = [ sentry = { version = "0.42.0", default-features = false, features = [
"backtrace", "backtrace",
"contexts", "contexts",
"debug-images", "debug-images",
@@ -129,45 +129,45 @@ sentry = { version = "0.41.0", default-features = false, features = [
"reqwest", "reqwest",
"rustls", "rustls",
] } ] }
sentry-actix = "0.41.0" sentry-actix = "0.42.0"
serde = "1.0.219" serde = "1.0.219"
serde_bytes = "0.11.17" serde_bytes = "0.11.17"
serde_cbor = "0.11.2" serde_cbor = "0.11.2"
serde_ini = "0.2.0" serde_ini = "0.2.0"
serde_json = "1.0.140" serde_json = "1.0.142"
serde_with = "3.13.0" serde_with = "3.14.0"
serde-xml-rs = "0.8.1" # Also an XML (de)serializer, consider dropping yaserde in favor of this serde-xml-rs = "0.8.1" # Also an XML (de)serializer, consider dropping yaserde in favor of this
sha1 = "0.10.6" sha1 = "0.10.6"
sha1_smol = { version = "1.0.1", features = ["std"] } sha1_smol = { version = "1.0.1", features = ["std"] }
sha2 = "0.10.9" sha2 = "0.10.9"
spdx = "0.10.8" spdx = "0.10.9"
sqlx = { version = "0.8.6", default-features = false } sqlx = { version = "0.8.6", default-features = false }
sysinfo = { version = "0.35.2", default-features = false } sysinfo = { version = "0.36.1", default-features = false }
tar = "0.4.44" tar = "0.4.44"
tauri = "2.6.1" tauri = "2.7.0"
tauri-build = "2.3.0" tauri-build = "2.3.1"
tauri-plugin-deep-link = "2.4.0" tauri-plugin-deep-link = "2.4.1"
tauri-plugin-dialog = "2.3.0" tauri-plugin-dialog = "2.3.2"
tauri-plugin-http = "2.5.0" tauri-plugin-http = "2.5.1"
tauri-plugin-opener = "2.4.0" tauri-plugin-opener = "2.4.0"
tauri-plugin-os = "2.3.0" tauri-plugin-os = "2.3.0"
tauri-plugin-single-instance = "2.3.0" tauri-plugin-single-instance = "2.3.2"
tauri-plugin-updater = { version = "2.9.0", default-features = false, features = [ tauri-plugin-updater = { version = "2.9.0", default-features = false, features = [
"rustls-tls", "rustls-tls",
"zip", "zip",
] } ] }
tauri-plugin-window-state = "2.3.0" tauri-plugin-window-state = "2.4.0"
tempfile = "3.20.0" tempfile = "3.20.0"
theseus = { path = "packages/app-lib" } theseus = { path = "packages/app-lib" }
thiserror = "2.0.12" thiserror = "2.0.12"
tikv-jemalloc-ctl = "0.6.0" tikv-jemalloc-ctl = "0.6.0"
tikv-jemallocator = "0.6.0" tikv-jemallocator = "0.6.0"
tokio = "1.45.1" tokio = "1.47.1"
tokio-stream = "0.1.17" tokio-stream = "0.1.17"
tokio-util = "0.7.15" tokio-util = "0.7.16"
totp-rs = "5.7.0" totp-rs = "5.7.0"
tracing = "0.1.41" tracing = "0.1.41"
tracing-actix-web = "0.7.18" tracing-actix-web = "0.7.19"
tracing-error = "0.2.1" tracing-error = "0.2.1"
tracing-subscriber = "0.3.19" tracing-subscriber = "0.3.19"
url = "2.5.4" url = "2.5.4"
@@ -179,7 +179,7 @@ whoami = "1.6.0"
winreg = "0.55.0" winreg = "0.55.0"
woothee = "0.13.0" woothee = "0.13.0"
yaserde = "0.12.0" yaserde = "0.12.0"
zip = { version = "4.2.0", default-features = false, features = [ zip = { version = "4.3.0", default-features = false, features = [
"bzip2", "bzip2",
"deflate", "deflate",
"deflate64", "deflate64",
@@ -226,7 +226,7 @@ wildcard_dependencies = "warn"
warnings = "deny" warnings = "deny"
[patch.crates-io] [patch.crates-io]
wry = { git = "https://github.com/modrinth/wry", rev = "21db186" } wry = { git = "https://github.com/modrinth/wry", rev = "f2ce0b0" }
# Optimize for speed and reduce size on release builds # Optimize for speed and reduce size on release builds
[profile.release] [profile.release]
+66 -40
View File
@@ -1,41 +1,67 @@
!macro NSIS_HOOK_POSTINSTALL ; https://nsis.sourceforge.io/ShellExecWait
SetShellVarContext current !macro ShellExecWait verb app param workdir show exitoutvar ;only app and show must be != "", every thing else is optional
#define SEE_MASK_NOCLOSEPROCESS 0x40
IfFileExists "$LOCALAPPDATA${PRODUCTNAME}\theseus_gui.exe" file_found file_not_found System::Store S
file_found: !if "${NSIS_PTR_SIZE}" > 4
Delete "$LOCALAPPDATA${PRODUCTNAME}\theseus_gui.exe" !define /ReDef /math SYSSIZEOF_SHELLEXECUTEINFO 14 * ${NSIS_PTR_SIZE}
!else ifndef SYSSIZEOF_SHELLEXECUTEINFO
Delete "$LOCALAPPDATA${PRODUCTNAME}\uninstall.exe" !define SYSSIZEOF_SHELLEXECUTEINFO 60
RMDir "$LOCALAPPDATA${PRODUCTNAME}" !endif
System::Call '*(&i${SYSSIZEOF_SHELLEXECUTEINFO})i.r0'
!insertmacro DeleteAppUserModelId System::Call '*$0(i ${SYSSIZEOF_SHELLEXECUTEINFO},i 0x40,p $hwndparent,t "${verb}",t $\'${app}$\',t $\'${param}$\',t "${workdir}",i ${show})p.r0'
System::Call 'shell32::ShellExecuteEx(t)(pr0)i.r1 ?e' ; (t) to trigger A/W selection
; Remove start menu shortcut ${If} $1 <> 0
!insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder System::Call '*$0(is,i,p,p,p,p,p,p,p,p,p,p,p,p,p.r1)' ;stack value not really used, just a fancy pop ;)
!insertmacro IsShortcutTarget "$SMPROGRAMS$AppStartMenuFolder${PRODUCTNAME}.lnk" "$LOCALAPPDATA${PRODUCTNAME}\theseus_gui.exe" System::Call 'kernel32::WaitForSingleObject(pr1,i-1)'
Pop $0 System::Call 'kernel32::GetExitCodeProcess(pr1,*i.s)'
${If} $0 = 1 System::Call 'kernel32::CloseHandle(pr1)'
!insertmacro UnpinShortcut "$SMPROGRAMS$AppStartMenuFolder${PRODUCTNAME}.lnk" ${EndIf}
Delete "$SMPROGRAMS$AppStartMenuFolder${PRODUCTNAME}.lnk" System::Free $0
RMDir "$SMPROGRAMS$AppStartMenuFolder" !if "${exitoutvar}" == ""
${EndIf} pop $0
!insertmacro IsShortcutTarget "$SMPROGRAMS${PRODUCTNAME}.lnk" "$LOCALAPPDATA${PRODUCTNAME}\theseus_gui.exe" !endif
Pop $0 System::Store L
${If} $0 = 1 !if "${exitoutvar}" != ""
!insertmacro UnpinShortcut "$SMPROGRAMS${PRODUCTNAME}.lnk" pop ${exitoutvar}
Delete "$SMPROGRAMS${PRODUCTNAME}.lnk" !endif
${EndIf} !macroend
!insertmacro IsShortcutTarget "$DESKTOP${PRODUCTNAME}.lnk" "$LOCALAPPDATA${PRODUCTNAME}\theseus_gui.exe" ; --------------------------------------------------------------------------------
Pop $0
${If} $0 = 1 Var /GLOBAL OldInstallDir
!insertmacro UnpinShortcut "$DESKTOP${PRODUCTNAME}.lnk"
Delete "$DESKTOP${PRODUCTNAME}.lnk" !macro NSIS_HOOK_PREINSTALL
${EndIf} SetShellVarContext all
${If} ${FileExists} "$SMPROGRAMS\${PRODUCTNAME}.lnk"
DeleteRegKey HKCU "${UNINSTKEY}" UserInfo::GetAccountType
Pop $0
goto end_of_test ;<== important for not continuing on the else branch ${If} $0 != "Admin"
file_not_found: MessageBox MB_ICONINFORMATION|MB_OK "An old installation of the Modrinth App was detected that requires administrator permission to update from. You will be prompted with an admin prompt shortly."
end_of_test: ${EndIf}
ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString"
ReadRegStr $OldInstallDir SHCTX "${UNINSTKEY}" "InstallLocation"
StrCpy $OldInstallDir $OldInstallDir "" 1
StrCpy $OldInstallDir $OldInstallDir -1 ""
DetailPrint "Executing $R1"
!insertmacro ShellExecWait "runas" '$R1' '/P _?=$4' "" ${SW_SHOW} $3
${If} $3 <> 0
SetErrorLevel $3
MessageBox MB_ICONEXCLAMATION|MB_OK "Failed to uninstall old global installation"
Abort
${EndIf}
${EndIf}
SetShellVarContext current
!macroend
!macro NSIS_HOOK_POSTINSTALL
!insertmacro IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$OldInstallDir\${MAINBINARYNAME}.exe"
Pop $0
${If} $0 = 1
!insertmacro SetShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
Return
${EndIf}
!macroend !macroend
+5 -8
View File
@@ -122,16 +122,13 @@ pub async fn login<R: Runtime>(
.url()? .url()?
.as_str() .as_str()
.starts_with("https://login.live.com/oauth20_desktop.srf") .starts_with("https://login.live.com/oauth20_desktop.srf")
{ && let Some((_, code)) =
if let Some((_, code)) =
window.url()?.query_pairs().find(|x| x.0 == "code") window.url()?.query_pairs().find(|x| x.0 == "code")
{ {
window.close()?; window.close()?;
let val = let val = minecraft_auth::finish_login(&code.clone(), flow).await?;
minecraft_auth::finish_login(&code.clone(), flow).await?;
return Ok(Some(val)); return Ok(Some(val));
}
} }
tokio::time::sleep(std::time::Duration::from_millis(50)).await; tokio::time::sleep(std::time::Duration::from_millis(50)).await;
+4 -4
View File
@@ -103,11 +103,11 @@ pub async fn should_disable_mouseover() -> bool {
// We try to match version to 12.2 or higher. If unrecognizable to pattern or lower, we default to the css with disabled mouseover for safety // We try to match version to 12.2 or higher. If unrecognizable to pattern or lower, we default to the css with disabled mouseover for safety
if let tauri_plugin_os::Version::Semantic(major, minor, _) = if let tauri_plugin_os::Version::Semantic(major, minor, _) =
tauri_plugin_os::version() tauri_plugin_os::version()
&& major >= 12
&& minor >= 3
{ {
if major >= 12 && minor >= 3 { // Mac os version is 12.3 or higher, we allow mouseover
// Mac os version is 12.3 or higher, we allow mouseover return false;
return false;
}
} }
true true
} else { } else {
+4 -4
View File
@@ -243,10 +243,10 @@ fn main() {
}); });
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
if let Some(window) = app.get_window("main") { if let Some(window) = app.get_window("main")
if let Err(e) = window.set_shadow(true) { && let Err(e) = window.set_shadow(true)
tracing::warn!("Failed to set window shadow: {e}"); {
} tracing::warn!("Failed to set window shadow: {e}");
} }
Ok(()) Ok(())
+1 -1
View File
@@ -15,7 +15,7 @@
"icon": ["icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"], "icon": ["icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"],
"windows": { "windows": {
"nsis": { "nsis": {
"installMode": "perMachine", "installMode": "currentUser",
"installerHooks": "./nsis/hooks.nsi" "installerHooks": "./nsis/hooks.nsi"
} }
}, },
+1 -1
View File
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM rust:1.88.0 AS build FROM rust:1.89.0 AS build
WORKDIR /usr/src/daedalus WORKDIR /usr/src/daedalus
COPY . . COPY . .
+17 -19
View File
@@ -506,27 +506,25 @@ async fn fetch(
return Ok(lib); return Ok(lib);
} }
} else if let Some(url) = &lib.url { } else if let Some(url) = &lib.url
if !url.is_empty() { && !url.is_empty()
insert_mirrored_artifact( {
&lib.name, insert_mirrored_artifact(
None, &lib.name,
vec![ None,
url.clone(), vec![
"https://libraries.minecraft.net/" url.clone(),
.to_string(), "https://libraries.minecraft.net/".to_string(),
"https://maven.creeperhost.net/" "https://maven.creeperhost.net/".to_string(),
.to_string(), maven_url.to_string(),
maven_url.to_string(), ],
], false,
false, mirror_artifacts,
mirror_artifacts, )?;
)?;
lib.url = Some(format_url("maven/")); lib.url = Some(format_url("maven/"));
return Ok(lib); return Ok(lib);
}
} }
// Other libraries are generally available in the "maven" directory of the installer. If they are // Other libraries are generally available in the "maven" directory of the installer. If they are
+13 -15
View File
@@ -93,22 +93,22 @@ async fn main() -> Result<()> {
.ok() .ok()
.and_then(|x| x.parse::<bool>().ok()) .and_then(|x| x.parse::<bool>().ok())
.unwrap_or(false) .unwrap_or(false)
&& let Ok(token) = dotenvy::var("CLOUDFLARE_TOKEN")
&& let Ok(zone_id) = dotenvy::var("CLOUDFLARE_ZONE_ID")
{ {
if let Ok(token) = dotenvy::var("CLOUDFLARE_TOKEN") { let cache_clears = upload_files
if let Ok(zone_id) = dotenvy::var("CLOUDFLARE_ZONE_ID") { .into_iter()
let cache_clears = upload_files .map(|x| format_url(&x.0))
.chain(
mirror_artifacts
.into_iter() .into_iter()
.map(|x| format_url(&x.0)) .map(|x| format_url(&format!("maven/{}", x.0))),
.chain( )
mirror_artifacts .collect::<Vec<_>>();
.into_iter()
.map(|x| format_url(&format!("maven/{}", x.0))),
)
.collect::<Vec<_>>();
// Cloudflare ratelimits cache clears to 500 files per request // Cloudflare ratelimits cache clears to 500 files per request
for chunk in cache_clears.chunks(500) { for chunk in cache_clears.chunks(500) {
REQWEST_CLIENT.post(format!("https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache")) REQWEST_CLIENT.post(format!("https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache"))
.bearer_auth(&token) .bearer_auth(&token)
.json(&serde_json::json!({ .json(&serde_json::json!({
"files": chunk "files": chunk
@@ -128,8 +128,6 @@ async fn main() -> Result<()> {
item: "cloudflare clear cache".to_string(), item: "cloudflare clear cache".to_string(),
} }
})?; })?;
}
}
} }
} }
+11 -13
View File
@@ -167,20 +167,18 @@ pub async fn download_file(
let bytes = x.bytes().await; let bytes = x.bytes().await;
if let Ok(bytes) = bytes { if let Ok(bytes) = bytes {
if let Some(sha1) = sha1 { if let Some(sha1) = sha1
if &*sha1_async(bytes.clone()).await? != sha1 { && &*sha1_async(bytes.clone()).await? != sha1
if attempt <= 3 { {
continue; if attempt <= 3 {
} else { continue;
return Err( } else {
crate::ErrorKind::ChecksumFailure { return Err(crate::ErrorKind::ChecksumFailure {
hash: sha1.to_string(), hash: sha1.to_string(),
url: url.to_string(), url: url.to_string(),
tries: attempt, tries: attempt,
}
.into(),
);
} }
.into());
} }
} }
@@ -3,77 +3,61 @@ title: Labrinth (API)
description: Guide for contributing to Modrinth's backend description: Guide for contributing to Modrinth's backend
--- ---
This project is part of our [monorepo](https://github.com/modrinth/code). You can find it in the `apps/labrinth` directory. This project is part of our [monorepo](https://github.com/modrinth/code). You can find it in the `apps/labrinth` directory. The instructions below assume that you have switched your working directory to the `apps/labrinth` subdirectory.
[labrinth] is the Rust-based backend serving Modrinth's API with the help of the [Actix](https://actix.rs) framework. To get started with a labrinth instance, install docker, docker-compose (which comes with Docker), and [Rust]. The initial startup can be done simply with the command `docker-compose up`, or with `docker compose up` (Compose V2 and later). That will deploy a PostgreSQL database on port 5432 and a MeiliSearch instance on port 7700. To run the API itself, you'll need to use the `cargo run` command, this will deploy the API on port 8000. [labrinth] is the Rust-based backend serving Modrinth's API with the help of the [Actix](https://actix.rs) framework. To get started with a labrinth instance, install docker, docker-compose (which comes with Docker), and [Rust]. The initial startup can be done simply with the command `docker-compose up`, or with `docker compose up` (Compose V2 and later). That will deploy a PostgreSQL database on port 5432, a MeiliSearch instance on port 7700, and a [Mailpit](https://mailpit.axllent.org/) SMTP server on port 1025, with a web UI to inspect sent emails on port 8025. To run the API itself, you'll need to use the `cargo run` command, this will deploy the API on port 8000.
To get a basic configuration, copy the `.env.local` file to `.env`. Now, you'll have to install the sqlx CLI, which can be done with cargo: To get a basic configuration, copy the `.env.local` file to `.env`. Now, you'll have to install the sqlx CLI, which can be done with cargo:
```bash ```sh
cargo install --git https://github.com/launchbadge/sqlx sqlx-cli --no-default-features --features postgres,rustls cargo install sqlx-cli --no-default-features --features mysql,sqlite,postgres,rustls,completions
``` ```
From there, you can create the database and perform all database migrations with one simple command: From there, you can create the database and set up its schema with one simple command:
```bash ```sh
sqlx database setup cargo sqlx database setup
``` ```
To enable labrinth to create a project, you need to add two things. To enable labrinth to create projects and serve useful metadata to the frontend build scripts, you'll need to seed the database with several key entities:
1. An entry in the `loaders` table. 1. Categories, in the `categories` table.
2. An entry in the `loaders_project_types` table. 2. Loaders and their fields, in the `loaders`, `loader_fields`, `loader_field_enums`, `loader_field_enum_values`, and `loader_fields_loaders` tables.
3. Project types and their allowed loaders and games, in the `project_types`, `loaders_project_types`, and `loaders_project_types_games` tables.
4. Optionally, to moderate projects from the frontend, an admin user, in the `users` table.
A minimal setup can be done from the command line with [psql](https://www.postgresql.org/docs/current/app-psql.html): The most convenient way to do this seeding is with the [psql](https://www.postgresql.org/docs/current/app-psql.html) command line tool and the pre-existing seed data fixture. This fixture was generated by dumping the official staging environment database at a specific point in time, and defines an admin user with email `admin@modrinth.invalid` and password `admin`:
```bash ```sh
psql --host=localhost --port=5432 -U <username, default is labrinth> -W source .env
psql "$DATABASE_URL" < fixtures/labrinth-seed-data-202508052143.sql
``` ```
The default password for the database is `labrinth`. Once you've connected, run You can find more example SQL statements for seeding the database in the `tests/files/dummy_data.sql` file.
```sql
INSERT INTO loaders VALUES (0, 'placeholder_loader');
INSERT INTO loaders_project_types VALUES (0, 1); -- modloader id, supported type id
INSERT INTO categories VALUES (0, 'placeholder_category', 1); -- category id, category, project type id
```
This will initialize your database with a modloader called 'placeholder_loader', with id 0, and marked as supporting mods only. It will also create a category called 'placeholder_category' that is marked as supporting mods only
If you would like 'placeholder_loader' to be marked as supporting modpacks too, run
```sql
INSERT INTO loaders_project_types VALUES (0, 2); -- modloader id, supported type id
```
If you would like 'placeholder_category' to be marked as supporting modpacks too, run
```sql
INSERT INTO categories VALUES (0, 'placeholder_category', 2); -- modloader id, supported type id
```
You can find more example SQL statements for seeding the database in the `apps/labrinth/tests/files/dummy_data.sql` file.
The majority of configuration is done at runtime using [dotenvy](https://crates.io/crates/dotenvy) and the `.env` file. Each of the variables and what they do can be found in the dropdown below. Additionally, there are three command line options that can be used to specify to MeiliSearch what you want to do. The majority of configuration is done at runtime using [dotenvy](https://crates.io/crates/dotenvy) and the `.env` file. Each of the variables and what they do can be found in the dropdown below. Additionally, there are three command line options that can be used to specify to MeiliSearch what you want to do.
During development, you might notice that changes made directly to entities in the PostgreSQL database do not seem to take effect. This is often because the Redis cache still holds outdated data. To ensure your updates are reflected, clear the cache by e.g. running `redis-cli FLUSHALL`, which will force Labrinth to fetch the latest data from the database the next time it is needed. During development, you might notice that changes made directly to entities in the PostgreSQL database do not seem to take effect. This is often because the Redis cache still holds outdated data. To ensure your updates are reflected, clear the cache by e.g. running `redis-cli FLUSHALL`, which will force labrinth to fetch the latest data from the database the next time it is needed.
You can also start labrinth and its backing services at once using `docker compose --profile with-labrinth up`, which will build and start labrinth through its Docker image as if it was yet another service container. To have that container be automatically rebuilt during development as changes to the source code are made, add the `--watch` flag, which enables [Compose Watch](https://docs.docker.com/compose/how-tos/file-watch/). Keep in mind, however, that Compose Watch is bound to be slower than other similar solutions that work outside of a container, particularly on Windows or macOS, where Docker runs in a virtual machine.
<details> <details>
<summary>.env variables & command line options</summary> <summary>.env variables & command line options</summary>
#### Basic configuration #### Basic configuration
`DEBUG`: Whether debugging tools should be enabled `DEBUG`: Whether debugging tools should be enabled
`RUST_LOG`: Specifies what information to log, from rust's [`env-logger`](https://github.com/env-logger-rs/env_logger); a reasonable default is `info,sqlx::query=warn` `RUST_LOG`: Specifies what information to log, from rust's [`env-logger`](https://github.com/env-logger-rs/env_logger); a reasonable default is `info,sqlx::query=warn`
`SITE_URL`: The main URL to be used for CORS `SITE_URL`: The main URL to be used for CORS
`CDN_URL`: The publicly accessible base URL for files uploaded to the CDN `CDN_URL`: The publicly accessible base URL for files uploaded to the CDN
`MODERATION_DISCORD_WEBHOOK`: The URL for a Discord webhook where projects pending approval will be sent `MODERATION_DISCORD_WEBHOOK`: The URL for a Discord webhook where projects pending approval will be sent
`CLOUDFLARE_INTEGRATION`: Whether labrinth should integrate with Cloudflare's spam protection `CLOUDFLARE_INTEGRATION`: Whether labrinth should integrate with Cloudflare's spam protection
`DATABASE_URL`: The URL for the PostgreSQL database `DATABASE_URL`: The URL for the PostgreSQL database, including its username, password, host, port, and database name
`DATABASE_MIN_CONNECTIONS`: The minimum number of concurrent connections allowed to the database at the same time `DATABASE_MIN_CONNECTIONS`: The minimum number of concurrent connections allowed to the database at the same time
`DATABASE_MAX_CONNECTIONS`: The maximum number of concurrent connections allowed to the database at the same time `DATABASE_MAX_CONNECTIONS`: The maximum number of concurrent connections allowed to the database at the same time
`MEILISEARCH_ADDR`: The URL for the MeiliSearch instance used for search `MEILISEARCH_ADDR`: The URL for the MeiliSearch instance used for search
`MEILISEARCH_KEY`: The name that MeiliSearch is given `MEILISEARCH_KEY`: The name that MeiliSearch is given
`BIND_ADDR`: The bind address for the server. Supports both IPv4 and IPv6 `BIND_ADDR`: The bind address for the server. Supports both IPv4 and IPv6
`MOCK_FILE_PATH`: The path used to store uploaded files; this has no default value and will panic if unspecified `MOCK_FILE_PATH`: The path used to store uploaded files; this has no default value and will panic if unspecified
`SMTP_USERNAME`: The username used to authenticate with the SMTP server `SMTP_USERNAME`: The username used to authenticate with the SMTP server
`SMTP_PASSWORD`: The password associated with the `SMTP_USERNAME` for SMTP authentication `SMTP_PASSWORD`: The password associated with the `SMTP_USERNAME` for SMTP authentication
@@ -90,7 +74,7 @@ The S3 configuration options are fairly self-explanatory in name, so here's simp
#### Search, OAuth, and miscellaneous options #### Search, OAuth, and miscellaneous options
`LOCAL_INDEX_INTERVAL`: The interval, in seconds, at which the local database is reindexed for searching. Defaults to `3600` seconds (1 hour). `LOCAL_INDEX_INTERVAL`: The interval, in seconds, at which the local database is reindexed for searching. Defaults to `3600` seconds (1 hour).
`VERSION_INDEX_INTERVAL`: The interval, in seconds, at which versions are reindexed for searching. Defaults to `1800` seconds (30 minutes). `VERSION_INDEX_INTERVAL`: The interval, in seconds, at which versions are reindexed for searching. Defaults to `1800` seconds (30 minutes).
The OAuth configuration options are fairly self-explanatory. For help setting up authentication, please contact us on [Discord]. The OAuth configuration options are fairly self-explanatory. For help setting up authentication, please contact us on [Discord].
@@ -99,8 +83,8 @@ The OAuth configuration options are fairly self-explanatory. For help setting up
#### Command line options #### Command line options
`--skip-first-index`: Skips indexing the local database on startup. This is useful to prevent doing unnecessary work when frequently restarting. `--skip-first-index`: Skips indexing the local database on startup. This is useful to prevent doing unnecessary work when frequently restarting.
`--reconfigure-indices`: Resets the MeiliSearch settings for the search indices and exits. `--reconfigure-indices`: Resets the MeiliSearch settings for the search indices and exits.
`--reset-indices`: Resets the MeiliSearch indices and exits; this clears all previously indexed mods. `--reset-indices`: Resets the MeiliSearch indices and exits; this clears all previously indexed mods.
</details> </details>
@@ -109,14 +93,13 @@ The OAuth configuration options are fairly self-explanatory. For help setting up
If you're prepared to contribute by submitting a pull request, ensure you have met the following criteria: If you're prepared to contribute by submitting a pull request, ensure you have met the following criteria:
- `cargo fmt` has been run. - `cargo fmt --all` has been run.
- `cargo clippy` has been run. - `cargo clippy --all-targets` has been run.
- `cargo check` has been run.
- `cargo sqlx prepare` has been run. - `cargo sqlx prepare` has been run.
> Note: If you encounter issues with `sqlx` saying 'no queries found' after running `cargo sqlx prepare`, you may need to ensure the installed version of `sqlx-cli` matches the current version of `sqlx` used [in labrinth](https://github.com/modrinth/labrinth/blob/master/Cargo.toml). > Note: If you encounter issues with `sqlx` saying 'no queries found' after running `cargo sqlx prepare`, you may need to ensure the installed version of `sqlx-cli` matches the current version of `sqlx` used [in labrinth](https://github.com/modrinth/labrinth/blob/master/Cargo.toml).
[Discord]: https://discord.modrinth.com [Discord]: https://discord.modrinth.com
[GitHub]: https://github.com/modrinth [GitHub]: https://github.com/modrinth
[labrinth]: https://github.com/modrinth/labrinth [labrinth]: https://github.com/modrinth/code/tree/main/apps/labrinth
[Rust]: https://www.rust-lang.org/tools/install [Rust]: https://www.rust-lang.org/tools/install
@@ -50,13 +50,35 @@
</div> </div>
<div v-else-if="generatedMessage"> <div v-else-if="generatedMessage">
<div> <div>
<ButtonStyled>
<button class="mb-2" @click="useSimpleEditor = !useSimpleEditor">
<template v-if="!useSimpleEditor">
<ToggleLeftIcon aria-hidden="true" />
Use simple mode
</template>
<template v-else>
<ToggleRightIcon aria-hidden="true" />
Use advanced mode
</template>
</button>
</ButtonStyled>
<MarkdownEditor <MarkdownEditor
v-if="!useSimpleEditor"
v-model="message" v-model="message"
:max-height="400" :max-height="400"
placeholder="No message generated." placeholder="No message generated."
:disabled="false" :disabled="false"
:heading-buttons="false" :heading-buttons="false"
/> />
<textarea
v-else
v-model="message"
type="text"
class="bg-bg-input h-[400px] w-full rounded-lg border border-solid border-divider px-3 py-2 font-mono text-base"
placeholder="No message generated."
autocomplete="off"
@input="persistState"
/>
</div> </div>
</div> </div>
<div v-else-if="isModpackPermissionsStage"> <div v-else-if="isModpackPermissionsStage">
@@ -324,6 +346,8 @@ import {
CheckIcon, CheckIcon,
KeyboardIcon, KeyboardIcon,
EyeOffIcon, EyeOffIcon,
ToggleLeftIcon,
ToggleRightIcon,
} from "@modrinth/assets"; } from "@modrinth/assets";
import { import {
checklist, checklist,
@@ -368,7 +392,6 @@ import {
type Stage, type Stage,
finalPermissionMessages, finalPermissionMessages,
} from "@modrinth/moderation"; } from "@modrinth/moderation";
import * as prettier from "prettier";
import ModpackPermissionsFlow from "./ModpackPermissionsFlow.vue"; import ModpackPermissionsFlow from "./ModpackPermissionsFlow.vue";
import KeybindsModal from "./ChecklistKeybindsModal.vue"; import KeybindsModal from "./ChecklistKeybindsModal.vue";
import { useModerationStore } from "~/store/moderation.ts"; import { useModerationStore } from "~/store/moderation.ts";
@@ -392,6 +415,7 @@ const isModpackPermissionsStage = computed(() => {
return currentStageObj.value.id === "modpack-permissions"; return currentStageObj.value.id === "modpack-permissions";
}); });
const useSimpleEditor = ref(false);
const message = ref(""); const message = ref("");
const generatedMessage = ref(false); const generatedMessage = ref(false);
const loadingMessage = ref(false); const loadingMessage = ref(false);
@@ -1118,19 +1142,7 @@ async function generateMessage() {
} }
} }
try { message.value = fullMessage;
const formattedMessage = await prettier.format(fullMessage, {
parser: "markdown",
printWidth: 80,
proseWrap: "always",
tabWidth: 2,
useTabs: false,
});
message.value = formattedMessage;
} catch (formattingError) {
console.warn("Failed to format markdown, using original:", formattingError);
message.value = fullMessage;
}
generatedMessage.value = true; generatedMessage.value = true;
} catch (error) { } catch (error) {
+6 -5
View File
@@ -100,7 +100,6 @@ import {
ScaleIcon, ScaleIcon,
} from "@modrinth/assets"; } from "@modrinth/assets";
import { defineMessages, useVIntl } from "@vintl/vintl"; import { defineMessages, useVIntl } from "@vintl/vintl";
import { useLocalStorage } from "@vueuse/core";
import ConfettiExplosion from "vue-confetti-explosion"; import ConfettiExplosion from "vue-confetti-explosion";
import Fuse from "fuse.js"; import Fuse from "fuse.js";
import ModerationQueueCard from "~/components/ui/moderation/ModerationQueueCard.vue"; import ModerationQueueCard from "~/components/ui/moderation/ModerationQueueCard.vue";
@@ -215,7 +214,7 @@ watch(
}, },
); );
const currentFilterType = useLocalStorage("moderation-current-filter-type", () => "All projects"); const currentFilterType = ref("All projects");
const filterTypes: readonly string[] = readonly([ const filterTypes: readonly string[] = readonly([
"All projects", "All projects",
"Modpacks", "Modpacks",
@@ -226,7 +225,7 @@ const filterTypes: readonly string[] = readonly([
"Shaders", "Shaders",
]); ]);
const currentSortType = useLocalStorage("moderation-current-sort-type", () => "Oldest"); const currentSortType = ref("Oldest");
const sortTypes: readonly string[] = readonly(["Oldest", "Newest"]); const sortTypes: readonly string[] = readonly(["Oldest", "Newest"]);
const currentPage = ref(1); const currentPage = ref(1);
@@ -287,8 +286,10 @@ const typeFiltered = computed(() => {
const projectType = filterMap[currentFilterType.value]; const projectType = filterMap[currentFilterType.value];
if (!projectType) return baseFiltered.value; if (!projectType) return baseFiltered.value;
return baseFiltered.value.filter((queueItem) => return baseFiltered.value.filter(
queueItem.project.project_types.includes(projectType), (queueItem) =>
queueItem.project.project_types.length > 0 &&
queueItem.project.project_types[0] === projectType,
); );
}); });
@@ -72,7 +72,6 @@
import { DropdownSelect, Button, Pagination } from "@modrinth/ui"; import { DropdownSelect, Button, Pagination } from "@modrinth/ui";
import { XIcon, SearchIcon, SortAscIcon, SortDescIcon, FilterIcon } from "@modrinth/assets"; import { XIcon, SearchIcon, SortAscIcon, SortDescIcon, FilterIcon } from "@modrinth/assets";
import { defineMessages, useVIntl } from "@vintl/vintl"; import { defineMessages, useVIntl } from "@vintl/vintl";
import { useLocalStorage } from "@vueuse/core";
import type { Report } from "@modrinth/utils"; import type { Report } from "@modrinth/utils";
import Fuse from "fuse.js"; import Fuse from "fuse.js";
import type { ExtendedReport } from "@modrinth/moderation"; import type { ExtendedReport } from "@modrinth/moderation";
@@ -170,10 +169,10 @@ watch(
}, },
); );
const currentFilterType = useLocalStorage("moderation-reports-filter-type", () => "All"); const currentFilterType = ref("All");
const filterTypes: readonly string[] = readonly(["All", "Unread", "Read"]); const filterTypes: readonly string[] = readonly(["All", "Unread", "Read"]);
const currentSortType = useLocalStorage("moderation-reports-sort-type", () => "Oldest"); const currentSortType = ref("Oldest");
const sortTypes: readonly string[] = readonly(["Oldest", "Newest"]); const sortTypes: readonly string[] = readonly(["Oldest", "Newest"]);
const currentPage = ref(1); const currentPage = ref(1);
+129
View File
@@ -0,0 +1,129 @@
DEBUG=true
RUST_LOG=info,sqlx::query=warn
SENTRY_DSN=none
SITE_URL=http://localhost:3000
# This CDN URL matches the local storage backend set below, which uses MOCK_FILE_PATH
CDN_URL=file:///tmp/modrinth
LABRINTH_ADMIN_KEY=feedbeef
RATE_LIMIT_IGNORE_KEY=feedbeef
DATABASE_URL=postgresql://labrinth:labrinth@labrinth-postgres/labrinth
DATABASE_MIN_CONNECTIONS=0
DATABASE_MAX_CONNECTIONS=16
MEILISEARCH_ADDR=http://labrinth-meilisearch:7700
MEILISEARCH_KEY=modrinth
REDIS_URL=redis://labrinth-redis
REDIS_MAX_CONNECTIONS=10000
BIND_ADDR=0.0.0.0:8000
SELF_ADDR=http://labrinth:8000
MODERATION_SLACK_WEBHOOK=
PUBLIC_DISCORD_WEBHOOK=
CLOUDFLARE_INTEGRATION=false
STORAGE_BACKEND=local
MOCK_FILE_PATH=/tmp/modrinth
S3_PUBLIC_BUCKET_NAME=none
S3_PUBLIC_USES_PATH_STYLE_BUCKET=false
S3_PUBLIC_REGION=none
S3_PUBLIC_URL=none
S3_PUBLIC_ACCESS_TOKEN=none
S3_PUBLIC_SECRET=none
S3_PRIVATE_BUCKET_NAME=none
S3_PRIVATE_USES_PATH_STYLE_BUCKET=false
S3_PRIVATE_REGION=none
S3_PRIVATE_URL=none
S3_PRIVATE_ACCESS_TOKEN=none
S3_PRIVATE_SECRET=none
# 1 hour
LOCAL_INDEX_INTERVAL=3600
# 30 minutes
VERSION_INDEX_INTERVAL=1800
RATE_LIMIT_IGNORE_IPS='["127.0.0.1"]'
WHITELISTED_MODPACK_DOMAINS='["cdn.modrinth.com", "github.com", "raw.githubusercontent.com"]'
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1"]'
GITHUB_CLIENT_ID=none
GITHUB_CLIENT_SECRET=none
GITLAB_CLIENT_ID=none
GITLAB_CLIENT_SECRET=none
DISCORD_CLIENT_ID=none
DISCORD_CLIENT_SECRET=none
MICROSOFT_CLIENT_ID=none
MICROSOFT_CLIENT_SECRET=none
GOOGLE_CLIENT_ID=none
GOOGLE_CLIENT_SECRET=none
PAYPAL_API_URL=https://api-m.sandbox.paypal.com/v1/
PAYPAL_WEBHOOK_ID=none
PAYPAL_CLIENT_ID=none
PAYPAL_CLIENT_SECRET=none
PAYPAL_NVP_USERNAME=none
PAYPAL_NVP_PASSWORD=none
PAYPAL_NVP_SIGNATURE=none
STEAM_API_KEY=none
TREMENDOUS_API_URL=https://testflight.tremendous.com/api/v2/
TREMENDOUS_API_KEY=none
TREMENDOUS_PRIVATE_KEY=none
TREMENDOUS_CAMPAIGN_ID=none
HCAPTCHA_SECRET=none
SMTP_FROM_NAME=Modrinth
SMTP_FROM_ADDRESS=no-reply@mail.modrinth.com
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_HOST=labrinth-mail
SMTP_PORT=1025
SMTP_TLS=none
SITE_VERIFY_EMAIL_PATH=auth/verify-email
SITE_RESET_PASSWORD_PATH=auth/reset-password
SITE_BILLING_PATH=none
SENDY_URL=none
SENDY_LIST_ID=none
SENDY_API_KEY=none
ANALYTICS_ALLOWED_ORIGINS='["http://127.0.0.1:3000", "http://localhost:3000", "https://modrinth.com", "https://www.modrinth.com", "*"]'
CLICKHOUSE_REPLICATED=false
CLICKHOUSE_URL=http://labrinth-clickhouse:8123
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=default
CLICKHOUSE_DATABASE=staging_ariadne
MAXMIND_LICENSE_KEY=none
FLAME_ANVIL_URL=none
STRIPE_API_KEY=none
STRIPE_WEBHOOK_SECRET=none
ADITUDE_API_KEY=none
PYRO_API_KEY=none
BREX_API_URL=https://platform.brexapis.com/v2/
BREX_API_KEY=none
DELPHI_URL=none
DELPHI_SLACK_WEBHOOK=none
ARCHON_URL=none
+5 -5
View File
@@ -87,11 +87,11 @@ HCAPTCHA_SECRET=none
SMTP_FROM_NAME=Modrinth SMTP_FROM_NAME=Modrinth
SMTP_FROM_ADDRESS=no-reply@mail.modrinth.com SMTP_FROM_ADDRESS=no-reply@mail.modrinth.com
SMTP_USERNAME=none SMTP_USERNAME=
SMTP_PASSWORD=none SMTP_PASSWORD=
SMTP_HOST=none SMTP_HOST=localhost
SMTP_PORT=465 SMTP_PORT=1025
SMTP_TLS=tls SMTP_TLS=none
SITE_VERIFY_EMAIL_PATH=auth/verify-email SITE_VERIFY_EMAIL_PATH=auth/verify-email
SITE_RESET_PASSWORD_PATH=auth/reset-password SITE_RESET_PASSWORD_PATH=auth/reset-password
+1 -1
View File
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM rust:1.88.0 AS build FROM rust:1.89.0 AS build
WORKDIR /usr/src/labrinth WORKDIR /usr/src/labrinth
COPY . . COPY . .
+1 -1
View File
@@ -14,7 +14,7 @@ fn main() {
let git_hash = String::from_utf8(output.stdout) let git_hash = String::from_utf8(output.stdout)
.expect("valid UTF-8 output from `git` invocation"); .expect("valid UTF-8 output from `git` invocation");
println!("cargo::rerun-if-changed=.git/HEAD"); println!("cargo::rerun-if-changed=../../.git/HEAD");
println!("cargo::rustc-env=GIT_HASH={}", git_hash.trim()); println!("cargo::rustc-env=GIT_HASH={}", git_hash.trim());
let timedate_fmt = Local::now().format("%F @ %I:%M %p"); let timedate_fmt = Local::now().format("%F @ %I:%M %p");
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -5,7 +5,7 @@
"lint": "cargo fmt --check && cargo clippy --all-targets", "lint": "cargo fmt --check && cargo clippy --all-targets",
"fix": "cargo clippy --all-targets --fix --allow-dirty && cargo fmt", "fix": "cargo clippy --all-targets --fix --allow-dirty && cargo fmt",
"dev": "cargo run", "dev": "cargo run",
"//": "Labrinth integration tests require a lot of disk space, so in the standard GitHub Actions", "//": "labrinth integration tests require a lot of disk space, so in the standard GitHub Actions",
"//": "runners we must remove useless development tools from the base image, which frees up ~20 GiB.", "//": "runners we must remove useless development tools from the base image, which frees up ~20 GiB.",
"//": "The command commented out below can be used in CI to debug what is taking up space:", "//": "The command commented out below can be used in CI to debug what is taking up space:",
"//": "sudo du -xh --max-depth=4 / | sort -rh | curl -X POST --data-urlencode content@/dev/fd/0 https://api.mclo.gs/1/log", "//": "sudo du -xh --max-depth=4 / | sort -rh | curl -X POST --data-urlencode content@/dev/fd/0 https://api.mclo.gs/1/log",
+9 -10
View File
@@ -322,12 +322,11 @@ pub async fn is_visible_collection(
} else { } else {
!collection_data.status.is_hidden() !collection_data.status.is_hidden()
}) && !collection_data.projects.is_empty(); }) && !collection_data.projects.is_empty();
if let Some(user) = &user_option { if let Some(user) = &user_option
if !authorized && !authorized
&& (user.role.is_mod() || user.id == collection_data.user_id.into()) && (user.role.is_mod() || user.id == collection_data.user_id.into())
{ {
authorized = true; authorized = true;
}
} }
Ok(authorized) Ok(authorized)
} }
@@ -356,10 +355,10 @@ pub async fn filter_visible_collections(
for collection in check_collections { for collection in check_collections {
// Collections are simple- if we are the owner or a mod, we can see it // Collections are simple- if we are the owner or a mod, we can see it
if let Some(user) = user_option { if let Some(user) = user_option
if user.role.is_mod() || user.id == collection.user_id.into() { && (user.role.is_mod() || user.id == collection.user_id.into())
return_collections.push(collection.into()); {
} return_collections.push(collection.into());
} }
} }
+7 -7
View File
@@ -39,7 +39,8 @@ pub fn send_email_raw(
let password = dotenvy::var("SMTP_PASSWORD")?; let password = dotenvy::var("SMTP_PASSWORD")?;
let host = dotenvy::var("SMTP_HOST")?; let host = dotenvy::var("SMTP_HOST")?;
let port = dotenvy::var("SMTP_PORT")?.parse::<u16>().unwrap_or(465); let port = dotenvy::var("SMTP_PORT")?.parse::<u16>().unwrap_or(465);
let creds = Credentials::new(username, password); let creds =
(!username.is_empty()).then(|| Credentials::new(username, password));
let tls_setting = match dotenvy::var("SMTP_TLS")?.as_str() { let tls_setting = match dotenvy::var("SMTP_TLS")?.as_str() {
"none" => Tls::None, "none" => Tls::None,
"opportunistic_start_tls" => { "opportunistic_start_tls" => {
@@ -55,13 +56,12 @@ pub fn send_email_raw(
} }
}; };
let mailer = SmtpTransport::relay(&host)? let mut mailer = SmtpTransport::relay(&host)?.port(port).tls(tls_setting);
.port(port) if let Some(creds) = creds {
.tls(tls_setting) mailer = mailer.credentials(creds);
.credentials(creds) }
.build();
mailer.send(&email)?; mailer.build().send(&email)?;
Ok(()) Ok(())
} }
@@ -95,10 +95,10 @@ impl DBFlow {
redis: &RedisPool, redis: &RedisPool,
) -> Result<Option<DBFlow>, DatabaseError> { ) -> Result<Option<DBFlow>, DatabaseError> {
let flow = Self::get(id, redis).await?; let flow = Self::get(id, redis).await?;
if let Some(flow) = flow.as_ref() { if let Some(flow) = flow.as_ref()
if predicate(flow) { && predicate(flow)
Self::remove(id, redis).await?; {
} Self::remove(id, redis).await?;
} }
Ok(flow) Ok(flow)
} }
@@ -801,24 +801,24 @@ impl VersionField {
}; };
if let Some(count) = countable { if let Some(count) = countable {
if let Some(min) = loader_field.min_val { if let Some(min) = loader_field.min_val
if count < min { && count < min
return Err(format!( {
"Provided value '{v}' for {field_name} is less than the minimum of {min}", return Err(format!(
v = serde_json::to_string(&value).unwrap_or_default(), "Provided value '{v}' for {field_name} is less than the minimum of {min}",
field_name = loader_field.field, v = serde_json::to_string(&value).unwrap_or_default(),
)); field_name = loader_field.field,
} ));
} }
if let Some(max) = loader_field.max_val { if let Some(max) = loader_field.max_val
if count > max { && count > max
return Err(format!( {
"Provided value '{v}' for {field_name} is greater than the maximum of {max}", return Err(format!(
v = serde_json::to_string(&value).unwrap_or_default(), "Provided value '{v}' for {field_name} is greater than the maximum of {max}",
field_name = loader_field.field, v = serde_json::to_string(&value).unwrap_or_default(),
)); field_name = loader_field.field,
} ));
} }
} }
+10 -10
View File
@@ -483,20 +483,20 @@ impl DBTeamMember {
.await?; .await?;
} }
if let Some(accepted) = new_accepted { if let Some(accepted) = new_accepted
if accepted { && accepted
sqlx::query!( {
" sqlx::query!(
"
UPDATE team_members UPDATE team_members
SET accepted = TRUE SET accepted = TRUE
WHERE (team_id = $1 AND user_id = $2) WHERE (team_id = $1 AND user_id = $2)
", ",
id as DBTeamId, id as DBTeamId,
user_id as DBUserId, user_id as DBUserId,
) )
.execute(&mut **transaction) .execute(&mut **transaction)
.await?; .await?;
}
} }
if let Some(payouts_split) = new_payouts_split { if let Some(payouts_split) = new_payouts_split {
+4 -4
View File
@@ -353,10 +353,10 @@ impl RedisPool {
}; };
for (idx, key) in fetch_ids.into_iter().enumerate() { for (idx, key) in fetch_ids.into_iter().enumerate() {
if let Some(locked) = results.get(idx) { if let Some(locked) = results.get(idx)
if locked.is_none() { && locked.is_none()
continue; {
} continue;
} }
if let Some((key, raw_key)) = ids.remove(&key) { if let Some((key, raw_key)) = ids.remove(&key) {
+1 -1
View File
@@ -71,7 +71,7 @@ pub fn app_setup(
enable_background_tasks: bool, enable_background_tasks: bool,
) -> LabrinthConfig { ) -> LabrinthConfig {
info!( info!(
"Starting Labrinth on {}", "Starting labrinth on {}",
dotenvy::var("BIND_ADDR").unwrap() dotenvy::var("BIND_ADDR").unwrap()
); );
+1 -1
View File
@@ -71,7 +71,7 @@ async fn main() -> std::io::Result<()> {
if args.run_background_task.is_none() { if args.run_background_task.is_none() {
info!( info!(
"Starting Labrinth on {}", "Starting labrinth on {}",
dotenvy::var("BIND_ADDR").unwrap() dotenvy::var("BIND_ADDR").unwrap()
); );
+5 -9
View File
@@ -334,18 +334,14 @@ impl From<Version> for LegacyVersion {
// the v2 loaders are whatever the corresponding loader fields are // the v2 loaders are whatever the corresponding loader fields are
let mut loaders = let mut loaders =
data.loaders.into_iter().map(|l| l.0).collect::<Vec<_>>(); data.loaders.into_iter().map(|l| l.0).collect::<Vec<_>>();
if loaders.contains(&"mrpack".to_string()) { if loaders.contains(&"mrpack".to_string())
if let Some((_, mrpack_loaders)) = data && let Some((_, mrpack_loaders)) = data
.fields .fields
.into_iter() .into_iter()
.find(|(key, _)| key == "mrpack_loaders") .find(|(key, _)| key == "mrpack_loaders")
{ && let Ok(mrpack_loaders) = serde_json::from_value(mrpack_loaders)
if let Ok(mrpack_loaders) = {
serde_json::from_value(mrpack_loaders) loaders = mrpack_loaders;
{
loaders = mrpack_loaders;
}
}
} }
let loaders = loaders.into_iter().map(Loader).collect::<Vec<_>>(); let loaders = loaders.into_iter().map(Loader).collect::<Vec<_>>();
+20 -22
View File
@@ -43,35 +43,33 @@ impl LegacyResultSearchProject {
pub fn from(result_search_project: ResultSearchProject) -> Self { pub fn from(result_search_project: ResultSearchProject) -> Self {
let mut categories = result_search_project.categories; let mut categories = result_search_project.categories;
categories.extend(result_search_project.loaders.clone()); categories.extend(result_search_project.loaders.clone());
if categories.contains(&"mrpack".to_string()) { if categories.contains(&"mrpack".to_string())
if let Some(mrpack_loaders) = result_search_project && let Some(mrpack_loaders) = result_search_project
.project_loader_fields .project_loader_fields
.get("mrpack_loaders") .get("mrpack_loaders")
{ {
categories.extend( categories.extend(
mrpack_loaders mrpack_loaders
.iter() .iter()
.filter_map(|c| c.as_str()) .filter_map(|c| c.as_str())
.map(String::from), .map(String::from),
); );
categories.retain(|c| c != "mrpack"); categories.retain(|c| c != "mrpack");
}
} }
let mut display_categories = result_search_project.display_categories; let mut display_categories = result_search_project.display_categories;
display_categories.extend(result_search_project.loaders); display_categories.extend(result_search_project.loaders);
if display_categories.contains(&"mrpack".to_string()) { if display_categories.contains(&"mrpack".to_string())
if let Some(mrpack_loaders) = result_search_project && let Some(mrpack_loaders) = result_search_project
.project_loader_fields .project_loader_fields
.get("mrpack_loaders") .get("mrpack_loaders")
{ {
categories.extend( categories.extend(
mrpack_loaders mrpack_loaders
.iter() .iter()
.filter_map(|c| c.as_str()) .filter_map(|c| c.as_str())
.map(String::from), .map(String::from),
); );
display_categories.retain(|c| c != "mrpack"); display_categories.retain(|c| c != "mrpack");
}
} }
// Sort then remove duplicates // Sort then remove duplicates
+4 -4
View File
@@ -166,10 +166,10 @@ impl From<ProjectQueryResult> for Project {
Ok(spdx_expr) => { Ok(spdx_expr) => {
let mut vec: Vec<&str> = Vec::new(); let mut vec: Vec<&str> = Vec::new();
for node in spdx_expr.iter() { for node in spdx_expr.iter() {
if let spdx::expression::ExprNode::Req(req) = node { if let spdx::expression::ExprNode::Req(req) = node
if let Some(id) = req.req.license.id() { && let Some(id) = req.req.license.id()
vec.push(id.full_name); {
} vec.push(id.full_name);
} }
} }
// spdx crate returns AND/OR operations in postfix order // spdx crate returns AND/OR operations in postfix order
+12 -12
View File
@@ -51,16 +51,16 @@ impl ProjectPermissions {
return Some(ProjectPermissions::all()); return Some(ProjectPermissions::all());
} }
if let Some(member) = project_team_member { if let Some(member) = project_team_member
if member.accepted { && member.accepted
return Some(member.permissions); {
} return Some(member.permissions);
} }
if let Some(member) = organization_team_member { if let Some(member) = organization_team_member
if member.accepted { && member.accepted
return Some(member.permissions); {
} return Some(member.permissions);
} }
if role.is_mod() { if role.is_mod() {
@@ -107,10 +107,10 @@ impl OrganizationPermissions {
return Some(OrganizationPermissions::all()); return Some(OrganizationPermissions::all());
} }
if let Some(member) = team_member { if let Some(member) = team_member
if member.accepted { && member.accepted
return member.organization_permissions; {
} return member.organization_permissions;
} }
if role.is_mod() { if role.is_mod() {
return Some( return Some(
+7 -9
View File
@@ -45,17 +45,15 @@ impl MaxMindIndexer {
if let Ok(entries) = archive.entries() { if let Ok(entries) = archive.entries() {
for mut file in entries.flatten() { for mut file in entries.flatten() {
if let Ok(path) = file.header().path() { if let Ok(path) = file.header().path()
if path.extension().and_then(|x| x.to_str()) == Some("mmdb") && path.extension().and_then(|x| x.to_str()) == Some("mmdb")
{ {
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap(); file.read_to_end(&mut buf).unwrap();
let reader = let reader = maxminddb::Reader::from_source(buf).unwrap();
maxminddb::Reader::from_source(buf).unwrap();
return Ok(Some(reader)); return Ok(Some(reader));
}
} }
} }
} }
+8 -12
View File
@@ -371,8 +371,8 @@ impl AutomatedModerationQueue {
for file in for file in
files.iter().filter(|x| x.version_id == version.id.into()) files.iter().filter(|x| x.version_id == version.id.into())
{ {
if let Some(hash) = file.hashes.get("sha1") { if let Some(hash) = file.hashes.get("sha1")
if let Some((index, (sha1, _, file_name, _))) = hashes && let Some((index, (sha1, _, file_name, _))) = hashes
.iter() .iter()
.enumerate() .enumerate()
.find(|(_, (value, _, _, _))| value == hash) .find(|(_, (value, _, _, _))| value == hash)
@@ -382,7 +382,6 @@ impl AutomatedModerationQueue {
hashes.remove(index); hashes.remove(index);
} }
}
} }
} }
@@ -420,12 +419,11 @@ impl AutomatedModerationQueue {
.await?; .await?;
for row in rows { for row in rows {
if let Some(sha1) = row.sha1 { if let Some(sha1) = row.sha1
if let Some((index, (sha1, _, file_name, _))) = hashes.iter().enumerate().find(|(_, (value, _, _, _))| value == &sha1) { && let Some((index, (sha1, _, file_name, _))) = hashes.iter().enumerate().find(|(_, (value, _, _, _))| value == &sha1) {
final_hashes.insert(sha1.clone(), IdentifiedFile { file_name: file_name.clone(), status: ApprovalType::from_string(&row.status).unwrap_or(ApprovalType::Unidentified) }); final_hashes.insert(sha1.clone(), IdentifiedFile { file_name: file_name.clone(), status: ApprovalType::from_string(&row.status).unwrap_or(ApprovalType::Unidentified) });
hashes.remove(index); hashes.remove(index);
} }
}
} }
if hashes.is_empty() { if hashes.is_empty() {
@@ -499,8 +497,8 @@ impl AutomatedModerationQueue {
let mut insert_ids = Vec::new(); let mut insert_ids = Vec::new();
for row in rows { for row in rows {
if let Some((curse_index, (hash, _flame_id))) = flame_files.iter().enumerate().find(|(_, x)| Some(x.1 as i32) == row.flame_project_id) { if let Some((curse_index, (hash, _flame_id))) = flame_files.iter().enumerate().find(|(_, x)| Some(x.1 as i32) == row.flame_project_id)
if let Some((index, (sha1, _, file_name, _))) = hashes.iter().enumerate().find(|(_, (value, _, _, _))| value == hash) { && let Some((index, (sha1, _, file_name, _))) = hashes.iter().enumerate().find(|(_, (value, _, _, _))| value == hash) {
final_hashes.insert(sha1.clone(), IdentifiedFile { final_hashes.insert(sha1.clone(), IdentifiedFile {
file_name: file_name.clone(), file_name: file_name.clone(),
status: ApprovalType::from_string(&row.status).unwrap_or(ApprovalType::Unidentified), status: ApprovalType::from_string(&row.status).unwrap_or(ApprovalType::Unidentified),
@@ -512,7 +510,6 @@ impl AutomatedModerationQueue {
hashes.remove(index); hashes.remove(index);
flame_files.remove(curse_index); flame_files.remove(curse_index);
} }
}
} }
if !insert_ids.is_empty() && !insert_hashes.is_empty() { if !insert_ids.is_empty() && !insert_hashes.is_empty() {
@@ -581,8 +578,8 @@ impl AutomatedModerationQueue {
for (sha1, _pack_file, file_name, _mumur2) in hashes { for (sha1, _pack_file, file_name, _mumur2) in hashes {
let flame_file = flame_files.iter().find(|x| x.0 == sha1); let flame_file = flame_files.iter().find(|x| x.0 == sha1);
if let Some((_, flame_project_id)) = flame_file { if let Some((_, flame_project_id)) = flame_file
if let Some(project) = flame_projects.iter().find(|x| &x.id == flame_project_id) { && let Some(project) = flame_projects.iter().find(|x| &x.id == flame_project_id) {
missing_metadata.flame_files.insert(sha1, MissingMetadataFlame { missing_metadata.flame_files.insert(sha1, MissingMetadataFlame {
title: project.name.clone(), title: project.name.clone(),
file_name, file_name,
@@ -592,7 +589,6 @@ impl AutomatedModerationQueue {
continue; continue;
} }
}
missing_metadata.unknown_files.insert(sha1, file_name); missing_metadata.unknown_files.insert(sha1, file_name);
} }
+25 -26
View File
@@ -257,31 +257,30 @@ impl PayoutsQueue {
) )
})?; })?;
if !status.is_success() { if !status.is_success()
if let Some(obj) = value.as_object() { && let Some(obj) = value.as_object()
if let Some(array) = obj.get("errors") { {
#[derive(Deserialize)] if let Some(array) = obj.get("errors") {
struct TremendousError { #[derive(Deserialize)]
message: String, struct TremendousError {
} message: String,
let err = serde_json::from_value::<TremendousError>(
array.clone(),
)
.map_err(|_| {
ApiError::Payments(
"could not retrieve Tremendous error json body"
.to_string(),
)
})?;
return Err(ApiError::Payments(err.message));
} }
return Err(ApiError::Payments( let err =
"could not retrieve Tremendous error body".to_string(), serde_json::from_value::<TremendousError>(array.clone())
)); .map_err(|_| {
ApiError::Payments(
"could not retrieve Tremendous error json body"
.to_string(),
)
})?;
return Err(ApiError::Payments(err.message));
} }
return Err(ApiError::Payments(
"could not retrieve Tremendous error body".to_string(),
));
} }
Ok(serde_json::from_value(value)?) Ok(serde_json::from_value(value)?)
@@ -449,10 +448,10 @@ impl PayoutsQueue {
}; };
// we do not support interval gift cards with non US based currencies since we cannot do currency conversions properly // we do not support interval gift cards with non US based currencies since we cannot do currency conversions properly
if let PayoutInterval::Fixed { .. } = method.interval { if let PayoutInterval::Fixed { .. } = method.interval
if !product.currency_codes.contains(&"USD".to_string()) { && !product.currency_codes.contains(&"USD".to_string())
continue; {
} continue;
} }
methods.push(method); methods.push(method);
+2 -2
View File
@@ -55,10 +55,10 @@ pub fn jemalloc_memory_stats(
) -> Result<(), prometheus::Error> { ) -> Result<(), prometheus::Error> {
let allocated_mem = IntGauge::new( let allocated_mem = IntGauge::new(
"labrinth_memory_allocated", "labrinth_memory_allocated",
"Labrinth allocated memory", "labrinth allocated memory",
)?; )?;
let resident_mem = let resident_mem =
IntGauge::new("labrinth_resident_memory", "Labrinth resident memory")?; IntGauge::new("labrinth_resident_memory", "labrinth resident memory")?;
registry.register(Box::new(allocated_mem.clone()))?; registry.register(Box::new(allocated_mem.clone()))?;
registry.register(Box::new(resident_mem.clone()))?; registry.register(Box::new(resident_mem.clone()))?;
+67 -72
View File
@@ -286,17 +286,17 @@ pub async fn refund_charge(
.upsert(&mut transaction) .upsert(&mut transaction)
.await?; .await?;
if body.0.unprovision.unwrap_or(false) { if body.0.unprovision.unwrap_or(false)
if let Some(subscription_id) = charge.subscription_id { && let Some(subscription_id) = charge.subscription_id
let open_charge = {
DBCharge::get_open_subscription(subscription_id, &**pool) let open_charge =
.await?; DBCharge::get_open_subscription(subscription_id, &**pool)
if let Some(mut open_charge) = open_charge { .await?;
open_charge.status = ChargeStatus::Cancelled; if let Some(mut open_charge) = open_charge {
open_charge.due = Utc::now(); open_charge.status = ChargeStatus::Cancelled;
open_charge.due = Utc::now();
open_charge.upsert(&mut transaction).await?; open_charge.upsert(&mut transaction).await?;
}
} }
} }
@@ -392,17 +392,16 @@ pub async fn edit_subscription(
} }
} }
if let Some(interval) = &edit_subscription.interval { if let Some(interval) = &edit_subscription.interval
if let Price::Recurring { intervals } = &current_price.prices { && let Price::Recurring { intervals } = &current_price.prices
if let Some(price) = intervals.get(interval) { {
open_charge.subscription_interval = Some(*interval); if let Some(price) = intervals.get(interval) {
open_charge.amount = *price as i64; open_charge.subscription_interval = Some(*interval);
} else { open_charge.amount = *price as i64;
return Err(ApiError::InvalidInput( } else {
"Interval is not valid for this subscription!" return Err(ApiError::InvalidInput(
.to_string(), "Interval is not valid for this subscription!".to_string(),
)); ));
}
} }
} }
@@ -1225,38 +1224,36 @@ pub async fn initiate_payment(
} }
}; };
if let Price::Recurring { .. } = price_item.prices { if let Price::Recurring { .. } = price_item.prices
if product.unitary { && product.unitary
let user_subscriptions = {
let user_subscriptions =
user_subscription_item::DBUserSubscription::get_all_user( user_subscription_item::DBUserSubscription::get_all_user(
user.id.into(), user.id.into(),
&**pool, &**pool,
) )
.await?; .await?;
let user_products = let user_products = product_item::DBProductPrice::get_many(
product_item::DBProductPrice::get_many( &user_subscriptions
&user_subscriptions .iter()
.iter() .filter(|x| {
.filter(|x| { x.status == SubscriptionStatus::Provisioned
x.status })
== SubscriptionStatus::Provisioned .map(|x| x.price_id)
}) .collect::<Vec<_>>(),
.map(|x| x.price_id) &**pool,
.collect::<Vec<_>>(), )
&**pool, .await?;
)
.await?;
if user_products if user_products
.into_iter() .into_iter()
.any(|x| x.product_id == product.id) .any(|x| x.product_id == product.id)
{ {
return Err(ApiError::InvalidInput( return Err(ApiError::InvalidInput(
"You are already subscribed to this product!" "You are already subscribed to this product!"
.to_string(), .to_string(),
)); ));
}
} }
} }
@@ -2004,38 +2001,36 @@ pub async fn stripe_webhook(
EventType::PaymentMethodAttached => { EventType::PaymentMethodAttached => {
if let EventObject::PaymentMethod(payment_method) = if let EventObject::PaymentMethod(payment_method) =
event.data.object event.data.object
{ && let Some(customer_id) =
if let Some(customer_id) =
payment_method.customer.map(|x| x.id()) payment_method.customer.map(|x| x.id())
{
let customer = stripe::Customer::retrieve(
&stripe_client,
&customer_id,
&[],
)
.await?;
if customer
.invoice_settings
.is_none_or(|x| x.default_payment_method.is_none())
{ {
let customer = stripe::Customer::retrieve( stripe::Customer::update(
&stripe_client, &stripe_client,
&customer_id, &customer_id,
&[], UpdateCustomer {
invoice_settings: Some(
CustomerInvoiceSettings {
default_payment_method: Some(
payment_method.id.to_string(),
),
..Default::default()
},
),
..Default::default()
},
) )
.await?; .await?;
if customer
.invoice_settings
.is_none_or(|x| x.default_payment_method.is_none())
{
stripe::Customer::update(
&stripe_client,
&customer_id,
UpdateCustomer {
invoice_settings: Some(
CustomerInvoiceSettings {
default_payment_method: Some(
payment_method.id.to_string(),
),
..Default::default()
},
),
..Default::default()
},
)
.await?;
}
} }
} }
} }
+17 -18
View File
@@ -79,13 +79,12 @@ impl TempUser {
file_host: &Arc<dyn FileHost + Send + Sync>, file_host: &Arc<dyn FileHost + Send + Sync>,
redis: &RedisPool, redis: &RedisPool,
) -> Result<crate::database::models::DBUserId, AuthenticationError> { ) -> Result<crate::database::models::DBUserId, AuthenticationError> {
if let Some(email) = &self.email { if let Some(email) = &self.email
if crate::database::models::DBUser::get_by_email(email, client) && crate::database::models::DBUser::get_by_email(email, client)
.await? .await?
.is_some() .is_some()
{ {
return Err(AuthenticationError::DuplicateUser); return Err(AuthenticationError::DuplicateUser);
}
} }
let user_id = let user_id =
@@ -1269,19 +1268,19 @@ pub async fn delete_auth_provider(
.update_user_id(user.id.into(), None, &mut transaction) .update_user_id(user.id.into(), None, &mut transaction)
.await?; .await?;
if delete_provider.provider != AuthProvider::PayPal { if delete_provider.provider != AuthProvider::PayPal
if let Some(email) = user.email { && let Some(email) = user.email
send_email( {
email, send_email(
"Authentication method removed", email,
&format!( "Authentication method removed",
"When logging into Modrinth, you can no longer log in using the {} authentication provider.", &format!(
delete_provider.provider.as_str() "When logging into Modrinth, you can no longer log in using the {} authentication provider.",
), delete_provider.provider.as_str()
"If you did not make this change, please contact us immediately through our support channels on Discord or via email (support@modrinth.com).", ),
None, "If you did not make this change, please contact us immediately through our support channels on Discord or via email (support@modrinth.com).",
)?; None,
} )?;
} }
transaction.commit().await?; transaction.commit().await?;
@@ -189,17 +189,16 @@ pub async fn get_project_meta(
.iter() .iter()
.find(|x| Some(x.1.id as i32) == row.flame_project_id) .find(|x| Some(x.1.id as i32) == row.flame_project_id)
.map(|x| x.0.clone()) .map(|x| x.0.clone())
&& let Some(val) = merged.flame_files.remove(&sha1)
{ {
if let Some(val) = merged.flame_files.remove(&sha1) { merged.identified.insert(
merged.identified.insert( sha1,
sha1, IdentifiedFile {
IdentifiedFile { file_name: val.file_name.clone(),
file_name: val.file_name.clone(), status: ApprovalType::from_string(&row.status)
status: ApprovalType::from_string(&row.status) .unwrap_or(ApprovalType::Unidentified),
.unwrap_or(ApprovalType::Unidentified), },
}, );
);
}
} }
} }
+59 -59
View File
@@ -185,69 +185,69 @@ pub async fn edit_pat(
) )
.await?; .await?;
if let Some(pat) = pat { if let Some(pat) = pat
if pat.user_id == user.id.into() { && pat.user_id == user.id.into()
let mut transaction = pool.begin().await?; {
let mut transaction = pool.begin().await?;
if let Some(scopes) = &info.scopes { if let Some(scopes) = &info.scopes {
if scopes.is_restricted() { if scopes.is_restricted() {
return Err(ApiError::InvalidInput( return Err(ApiError::InvalidInput(
"Invalid scopes requested!".to_string(), "Invalid scopes requested!".to_string(),
)); ));
} }
sqlx::query!( sqlx::query!(
" "
UPDATE pats UPDATE pats
SET scopes = $1 SET scopes = $1
WHERE id = $2 WHERE id = $2
", ",
scopes.bits() as i64, scopes.bits() as i64,
pat.id.0 pat.id.0
) )
.execute(&mut *transaction) .execute(&mut *transaction)
.await?; .await?;
} }
if let Some(name) = &info.name { if let Some(name) = &info.name {
sqlx::query!( sqlx::query!(
" "
UPDATE pats UPDATE pats
SET name = $1 SET name = $1
WHERE id = $2 WHERE id = $2
", ",
name, name,
pat.id.0 pat.id.0
) )
.execute(&mut *transaction) .execute(&mut *transaction)
.await?; .await?;
}
if let Some(expires) = &info.expires {
if expires < &Utc::now() {
return Err(ApiError::InvalidInput(
"Expire date must be in the future!".to_string(),
));
} }
if let Some(expires) = &info.expires {
if expires < &Utc::now() {
return Err(ApiError::InvalidInput(
"Expire date must be in the future!".to_string(),
));
}
sqlx::query!( sqlx::query!(
" "
UPDATE pats UPDATE pats
SET expires = $1 SET expires = $1
WHERE id = $2 WHERE id = $2
", ",
expires, expires,
pat.id.0 pat.id.0
)
.execute(&mut *transaction)
.await?;
}
transaction.commit().await?;
database::models::pat_item::DBPersonalAccessToken::clear_cache(
vec![(Some(pat.id), Some(pat.access_token), Some(pat.user_id))],
&redis,
) )
.execute(&mut *transaction)
.await?; .await?;
} }
transaction.commit().await?;
database::models::pat_item::DBPersonalAccessToken::clear_cache(
vec![(Some(pat.id), Some(pat.access_token), Some(pat.user_id))],
&redis,
)
.await?;
} }
Ok(HttpResponse::NoContent().finish()) Ok(HttpResponse::NoContent().finish())
@@ -276,21 +276,21 @@ pub async fn delete_pat(
) )
.await?; .await?;
if let Some(pat) = pat { if let Some(pat) = pat
if pat.user_id == user.id.into() { && pat.user_id == user.id.into()
let mut transaction = pool.begin().await?; {
database::models::pat_item::DBPersonalAccessToken::remove( let mut transaction = pool.begin().await?;
pat.id, database::models::pat_item::DBPersonalAccessToken::remove(
&mut transaction, pat.id,
) &mut transaction,
.await?; )
transaction.commit().await?; .await?;
database::models::pat_item::DBPersonalAccessToken::clear_cache( transaction.commit().await?;
vec![(Some(pat.id), Some(pat.access_token), Some(pat.user_id))], database::models::pat_item::DBPersonalAccessToken::clear_cache(
&redis, vec![(Some(pat.id), Some(pat.access_token), Some(pat.user_id))],
) &redis,
.await?; )
} .await?;
} }
Ok(HttpResponse::NoContent().finish()) Ok(HttpResponse::NoContent().finish())
+15 -15
View File
@@ -185,21 +185,21 @@ pub async fn delete(
let session = DBSession::get(info.into_inner().0, &**pool, &redis).await?; let session = DBSession::get(info.into_inner().0, &**pool, &redis).await?;
if let Some(session) = session { if let Some(session) = session
if session.user_id == current_user.id.into() { && session.user_id == current_user.id.into()
let mut transaction = pool.begin().await?; {
DBSession::remove(session.id, &mut transaction).await?; let mut transaction = pool.begin().await?;
transaction.commit().await?; DBSession::remove(session.id, &mut transaction).await?;
DBSession::clear_cache( transaction.commit().await?;
vec![( DBSession::clear_cache(
Some(session.id), vec![(
Some(session.session), Some(session.id),
Some(session.user_id), Some(session.session),
)], Some(session.user_id),
&redis, )],
) &redis,
.await?; )
} .await?;
} }
Ok(HttpResponse::NoContent().body("")) Ok(HttpResponse::NoContent().body(""))
@@ -401,14 +401,13 @@ async fn broadcast_to_known_local_friends(
friend.user_id friend.user_id
}; };
if friend.accepted { if friend.accepted
if let Some(socket_ids) = && let Some(socket_ids) =
sockets.sockets_by_user_id.get(&friend_id.into()) sockets.sockets_by_user_id.get(&friend_id.into())
{ {
for socket_id in socket_ids.iter() { for socket_id in socket_ids.iter() {
if let Some(socket) = sockets.sockets.get(&socket_id) { if let Some(socket) = sockets.sockets.get(&socket_id) {
let _ = send_message(socket.value(), &message).await; let _ = send_message(socket.value(), &message).await;
}
} }
} }
} }
+1
View File
@@ -512,6 +512,7 @@ pub async fn project_edit(
moderation_message_body: v2_new_project.moderation_message_body, moderation_message_body: v2_new_project.moderation_message_body,
monetization_status: v2_new_project.monetization_status, monetization_status: v2_new_project.monetization_status,
side_types_migration_review_status: None, // Not to be exposed in v2 side_types_migration_review_status: None, // Not to be exposed in v2
loader_fields: HashMap::new(), // Loader fields are not a thing in v2
}; };
// This returns 204 or failure so we don't need to do anything with it // This returns 204 or failure so we don't need to do anything with it
+10 -11
View File
@@ -387,17 +387,16 @@ pub async fn revenue_get(
.map(|x| (x.to_string(), HashMap::new())) .map(|x| (x.to_string(), HashMap::new()))
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
for value in payouts_values { for value in payouts_values {
if let Some(mod_id) = value.mod_id { if let Some(mod_id) = value.mod_id
if let Some(amount) = value.amount_sum { && let Some(amount) = value.amount_sum
if let Some(interval_start) = value.interval_start { && let Some(interval_start) = value.interval_start
let id_string = to_base62(mod_id as u64); {
if !hm.contains_key(&id_string) { let id_string = to_base62(mod_id as u64);
hm.insert(id_string.clone(), HashMap::new()); if !hm.contains_key(&id_string) {
} hm.insert(id_string.clone(), HashMap::new());
if let Some(hm) = hm.get_mut(&id_string) { }
hm.insert(interval_start.timestamp(), amount); if let Some(hm) = hm.get_mut(&id_string) {
} hm.insert(interval_start.timestamp(), amount);
}
} }
} }
} }
+4 -4
View File
@@ -192,10 +192,10 @@ pub async fn collection_get(
.map(|x| x.1) .map(|x| x.1)
.ok(); .ok();
if let Some(data) = collection_data { if let Some(data) = collection_data
if is_visible_collection(&data, &user_option, false).await? { && is_visible_collection(&data, &user_option, false).await?
return Ok(HttpResponse::Ok().json(Collection::from(data))); {
} return Ok(HttpResponse::Ok().json(Collection::from(data)));
} }
Err(ApiError::NotFound) Err(ApiError::NotFound)
} }
+2 -4
View File
@@ -536,11 +536,9 @@ pub async fn create_payout(
Some(true), Some(true),
) )
.await .await
&& let Some(data) = res.items.first()
{ {
if let Some(data) = res.items.first() { payout_item.platform_id = Some(data.payout_item_id.clone());
payout_item.platform_id =
Some(data.payout_item_id.clone());
}
} }
} }
+83 -58
View File
@@ -11,7 +11,7 @@ use crate::database::redis::RedisPool;
use crate::database::{self, models as db_models}; use crate::database::{self, models as db_models};
use crate::file_hosting::{FileHost, FileHostPublicity}; use crate::file_hosting::{FileHost, FileHostPublicity};
use crate::models; use crate::models;
use crate::models::ids::ProjectId; use crate::models::ids::{ProjectId, VersionId};
use crate::models::images::ImageContext; use crate::models::images::ImageContext;
use crate::models::notifications::NotificationBody; use crate::models::notifications::NotificationBody;
use crate::models::pats::Scopes; use crate::models::pats::Scopes;
@@ -182,10 +182,10 @@ pub async fn project_get(
.map(|x| x.1) .map(|x| x.1)
.ok(); .ok();
if let Some(data) = project_data { if let Some(data) = project_data
if is_visible_project(&data.inner, &user_option, &pool, false).await? { && is_visible_project(&data.inner, &user_option, &pool, false).await?
return Ok(HttpResponse::Ok().json(Project::from(data))); {
} return Ok(HttpResponse::Ok().json(Project::from(data)));
} }
Err(ApiError::NotFound) Err(ApiError::NotFound)
} }
@@ -250,6 +250,8 @@ pub struct EditProject {
pub monetization_status: Option<MonetizationStatus>, pub monetization_status: Option<MonetizationStatus>,
pub side_types_migration_review_status: pub side_types_migration_review_status:
Option<SideTypesMigrationReviewStatus>, Option<SideTypesMigrationReviewStatus>,
#[serde(flatten)]
pub loader_fields: HashMap<String, serde_json::Value>,
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@@ -403,34 +405,36 @@ pub async fn project_edit(
.await?; .await?;
} }
if status.is_searchable() && !project_item.inner.webhook_sent { if status.is_searchable()
if let Ok(webhook_url) = dotenvy::var("PUBLIC_DISCORD_WEBHOOK") { && !project_item.inner.webhook_sent
crate::util::webhook::send_discord_webhook( && let Ok(webhook_url) = dotenvy::var("PUBLIC_DISCORD_WEBHOOK")
project_item.inner.id.into(), {
&pool, crate::util::webhook::send_discord_webhook(
&redis, project_item.inner.id.into(),
webhook_url, &pool,
None, &redis,
) webhook_url,
.await None,
.ok(); )
.await
.ok();
sqlx::query!( sqlx::query!(
" "
UPDATE mods UPDATE mods
SET webhook_sent = TRUE SET webhook_sent = TRUE
WHERE id = $1 WHERE id = $1
", ",
id as db_ids::DBProjectId, id as db_ids::DBProjectId,
) )
.execute(&mut *transaction) .execute(&mut *transaction)
.await?; .await?;
}
} }
if user.role.is_mod() { if user.role.is_mod()
if let Ok(webhook_url) = dotenvy::var("MODERATION_SLACK_WEBHOOK") { && let Ok(webhook_url) = dotenvy::var("MODERATION_SLACK_WEBHOOK")
crate::util::webhook::send_slack_webhook( {
crate::util::webhook::send_slack_webhook(
project_item.inner.id.into(), project_item.inner.id.into(),
&pool, &pool,
&redis, &redis,
@@ -449,7 +453,6 @@ pub async fn project_edit(
) )
.await .await
.ok(); .ok();
}
} }
if team_member.is_none_or(|x| !x.accepted) { if team_member.is_none_or(|x| !x.accepted) {
@@ -692,45 +695,45 @@ pub async fn project_edit(
.await?; .await?;
} }
if let Some(links) = &new_project.link_urls { if let Some(links) = &new_project.link_urls
if !links.is_empty() { && !links.is_empty()
if !perms.contains(ProjectPermissions::EDIT_DETAILS) { {
return Err(ApiError::CustomAuthentication( if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
return Err(ApiError::CustomAuthentication(
"You do not have the permissions to edit the links of this project!" "You do not have the permissions to edit the links of this project!"
.to_string(), .to_string(),
)); ));
} }
let ids_to_delete = links.keys().cloned().collect::<Vec<String>>(); let ids_to_delete = links.keys().cloned().collect::<Vec<String>>();
// Deletes all links from hashmap- either will be deleted or be replaced // Deletes all links from hashmap- either will be deleted or be replaced
sqlx::query!( sqlx::query!(
" "
DELETE FROM mods_links DELETE FROM mods_links
WHERE joining_mod_id = $1 AND joining_platform_id IN ( WHERE joining_mod_id = $1 AND joining_platform_id IN (
SELECT id FROM link_platforms WHERE name = ANY($2) SELECT id FROM link_platforms WHERE name = ANY($2)
) )
", ",
id as db_ids::DBProjectId, id as db_ids::DBProjectId,
&ids_to_delete &ids_to_delete
) )
.execute(&mut *transaction) .execute(&mut *transaction)
.await?; .await?;
for (platform, url) in links { for (platform, url) in links {
if let Some(url) = url { if let Some(url) = url {
let platform_id = let platform_id = db_models::categories::LinkPlatform::get_id(
db_models::categories::LinkPlatform::get_id( platform,
platform, &mut *transaction,
&mut *transaction, )
) .await?
.await? .ok_or_else(|| {
.ok_or_else(|| { ApiError::InvalidInput(format!(
ApiError::InvalidInput(format!( "Platform {} does not exist.",
"Platform {} does not exist.", platform.clone()
platform.clone() ))
)) })?;
})?; sqlx::query!(
sqlx::query!(
" "
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url) INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
VALUES ($1, $2, $3) VALUES ($1, $2, $3)
@@ -741,7 +744,6 @@ pub async fn project_edit(
) )
.execute(&mut *transaction) .execute(&mut *transaction)
.await?; .await?;
}
} }
} }
} }
@@ -870,6 +872,29 @@ pub async fn project_edit(
.await?; .await?;
} }
if !new_project.loader_fields.is_empty() {
for version in db_models::DBVersion::get_many(
&project_item.versions,
&**pool,
&redis,
)
.await?
{
super::versions::version_edit_helper(
req.clone(),
(VersionId::from(version.inner.id),),
pool.clone(),
redis.clone(),
super::versions::EditVersion {
fields: new_project.loader_fields.clone(),
..Default::default()
},
session_queue.clone(),
)
.await?;
}
}
// check new description and body for links to associated images // check new description and body for links to associated images
// if they no longer exist in the description or body, delete them // if they no longer exist in the description or body, delete them
let checkable_strings: Vec<&str> = let checkable_strings: Vec<&str> =
@@ -2430,7 +2455,7 @@ pub async fn project_get_organization(
organization, organization,
team_members, team_members,
); );
return Ok(HttpResponse::Ok().json(organization)); Ok(HttpResponse::Ok().json(organization))
} else { } else {
Err(ApiError::NotFound) Err(ApiError::NotFound)
} }
+20 -20
View File
@@ -767,12 +767,13 @@ pub async fn edit_team_member(
)); ));
} }
if let Some(new_permissions) = edit_member.permissions { if let Some(new_permissions) = edit_member.permissions
if !permissions.contains(new_permissions) { && !permissions.contains(new_permissions)
return Err(ApiError::InvalidInput( {
"The new permissions have permissions that you don't have".to_string(), return Err(ApiError::InvalidInput(
)); "The new permissions have permissions that you don't have"
} .to_string(),
));
} }
if edit_member.organization_permissions.is_some() { if edit_member.organization_permissions.is_some() {
@@ -800,13 +801,12 @@ pub async fn edit_team_member(
} }
if let Some(new_permissions) = edit_member.organization_permissions if let Some(new_permissions) = edit_member.organization_permissions
&& !organization_permissions.contains(new_permissions)
{ {
if !organization_permissions.contains(new_permissions) { return Err(ApiError::InvalidInput(
return Err(ApiError::InvalidInput(
"The new organization permissions have permissions that you don't have" "The new organization permissions have permissions that you don't have"
.to_string(), .to_string(),
)); ));
}
} }
if edit_member.permissions.is_some() if edit_member.permissions.is_some()
@@ -822,13 +822,13 @@ pub async fn edit_team_member(
} }
} }
if let Some(payouts_split) = edit_member.payouts_split { if let Some(payouts_split) = edit_member.payouts_split
if payouts_split < Decimal::ZERO || payouts_split > Decimal::from(5000) && (payouts_split < Decimal::ZERO
{ || payouts_split > Decimal::from(5000))
return Err(ApiError::InvalidInput( {
"Payouts split must be between 0 and 5000!".to_string(), return Err(ApiError::InvalidInput(
)); "Payouts split must be between 0 and 5000!".to_string(),
} ));
} }
DBTeamMember::edit_team_member( DBTeamMember::edit_team_member(
@@ -883,13 +883,13 @@ pub async fn transfer_ownership(
DBTeam::get_association(id.into(), &**pool).await?; DBTeam::get_association(id.into(), &**pool).await?;
if let Some(TeamAssociationId::Project(pid)) = team_association_id { if let Some(TeamAssociationId::Project(pid)) = team_association_id {
let result = DBProject::get_id(pid, &**pool, &redis).await?; let result = DBProject::get_id(pid, &**pool, &redis).await?;
if let Some(project_item) = result { if let Some(project_item) = result
if project_item.inner.organization_id.is_some() { && project_item.inner.organization_id.is_some()
return Err(ApiError::InvalidInput( {
return Err(ApiError::InvalidInput(
"You cannot transfer ownership of a project team that is owend by an organization" "You cannot transfer ownership of a project team that is owend by an organization"
.to_string(), .to_string(),
)); ));
}
} }
} }
+46 -50
View File
@@ -289,36 +289,33 @@ pub async fn thread_get(
.await? .await?
.1; .1;
if let Some(mut data) = thread_data { if let Some(mut data) = thread_data
if is_authorized_thread(&data, &user, &pool).await? { && is_authorized_thread(&data, &user, &pool).await?
let authors = &mut data.members; {
let authors = &mut data.members;
authors.append( authors.append(
&mut data &mut data
.messages .messages
.iter() .iter()
.filter_map(|x| { .filter_map(|x| {
if x.hide_identity && !user.role.is_mod() { if x.hide_identity && !user.role.is_mod() {
None None
} else { } else {
x.author_id x.author_id
} }
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
); );
let users: Vec<User> = database::models::DBUser::get_many_ids( let users: Vec<User> =
authors, &**pool, &redis, database::models::DBUser::get_many_ids(authors, &**pool, &redis)
) .await?
.await? .into_iter()
.into_iter() .map(From::from)
.map(From::from) .collect();
.collect();
return Ok( return Ok(HttpResponse::Ok().json(Thread::from(data, users, &user)));
HttpResponse::Ok().json(Thread::from(data, users, &user))
);
}
} }
Err(ApiError::NotFound) Err(ApiError::NotFound)
} }
@@ -454,33 +451,32 @@ pub async fn thread_send_message(
) )
.await?; .await?;
if let Some(project) = project { if let Some(project) = project
if project.inner.status != ProjectStatus::Processing && project.inner.status != ProjectStatus::Processing
&& user.role.is_mod() && user.role.is_mod()
{ {
let members = let members =
database::models::DBTeamMember::get_from_team_full( database::models::DBTeamMember::get_from_team_full(
project.inner.team_id, project.inner.team_id,
&**pool, &**pool,
&redis,
)
.await?;
NotificationBuilder {
body: NotificationBody::ModeratorMessage {
thread_id: thread.id.into(),
message_id: id.into(),
project_id: Some(project.inner.id.into()),
report_id: None,
},
}
.insert_many(
members.into_iter().map(|x| x.user_id).collect(),
&mut transaction,
&redis, &redis,
) )
.await?; .await?;
NotificationBuilder {
body: NotificationBody::ModeratorMessage {
thread_id: thread.id.into(),
message_id: id.into(),
project_id: Some(project.inner.id.into()),
report_id: None,
},
} }
.insert_many(
members.into_iter().map(|x| x.user_id).collect(),
&mut transaction,
&redis,
)
.await?;
} }
} else if let Some(report_id) = thread.report_id { } else if let Some(report_id) = thread.report_id {
let report = database::models::report_item::DBReport::get( let report = database::models::report_item::DBReport::get(
+52 -53
View File
@@ -522,10 +522,10 @@ async fn version_create_inner(
.fetch_optional(pool) .fetch_optional(pool)
.await?; .await?;
if let Some(project_status) = project_status { if let Some(project_status) = project_status
if project_status.status == ProjectStatus::Processing.as_str() { && project_status.status == ProjectStatus::Processing.as_str()
moderation_queue.projects.insert(project_id.into()); {
} moderation_queue.projects.insert(project_id.into());
} }
Ok(HttpResponse::Ok().json(response)) Ok(HttpResponse::Ok().json(response))
@@ -871,16 +871,16 @@ pub async fn upload_file(
ref format, ref format,
ref files, ref files,
} = validation_result } = validation_result
&& dependencies.is_empty()
{ {
if dependencies.is_empty() { let hashes: Vec<Vec<u8>> = format
let hashes: Vec<Vec<u8>> = format .files
.files .iter()
.iter() .filter_map(|x| x.hashes.get(&PackFileHash::Sha1))
.filter_map(|x| x.hashes.get(&PackFileHash::Sha1)) .map(|x| x.as_bytes().to_vec())
.map(|x| x.as_bytes().to_vec()) .collect();
.collect();
let res = sqlx::query!( let res = sqlx::query!(
" "
SELECT v.id version_id, v.mod_id project_id, h.hash hash FROM hashes h SELECT v.id version_id, v.mod_id project_id, h.hash hash FROM hashes h
INNER JOIN files f on h.file_id = f.id INNER JOIN files f on h.file_id = f.id
@@ -892,45 +892,44 @@ pub async fn upload_file(
.fetch_all(&mut **transaction) .fetch_all(&mut **transaction)
.await?; .await?;
for file in &format.files { for file in &format.files {
if let Some(dep) = res.iter().find(|x| { if let Some(dep) = res.iter().find(|x| {
Some(&*x.hash) Some(&*x.hash)
== file == file
.hashes .hashes
.get(&PackFileHash::Sha1) .get(&PackFileHash::Sha1)
.map(|x| x.as_bytes()) .map(|x| x.as_bytes())
}) { }) {
dependencies.push(DependencyBuilder { dependencies.push(DependencyBuilder {
project_id: Some(models::DBProjectId(dep.project_id)), project_id: Some(models::DBProjectId(dep.project_id)),
version_id: Some(models::DBVersionId(dep.version_id)), version_id: Some(models::DBVersionId(dep.version_id)),
file_name: None, file_name: None,
dependency_type: DependencyType::Embedded.to_string(), dependency_type: DependencyType::Embedded.to_string(),
}); });
} else if let Some(first_download) = file.downloads.first() { } else if let Some(first_download) = file.downloads.first() {
dependencies.push(DependencyBuilder { dependencies.push(DependencyBuilder {
project_id: None, project_id: None,
version_id: None, version_id: None,
file_name: Some( file_name: Some(
first_download first_download
.rsplit('/') .rsplit('/')
.next() .next()
.unwrap_or(first_download) .unwrap_or(first_download)
.to_string(), .to_string(),
), ),
dependency_type: DependencyType::Embedded.to_string(), dependency_type: DependencyType::Embedded.to_string(),
}); });
}
} }
}
for file in files { for file in files {
if !file.is_empty() { if !file.is_empty() {
dependencies.push(DependencyBuilder { dependencies.push(DependencyBuilder {
project_id: None, project_id: None,
version_id: None, version_id: None,
file_name: Some(file.to_string()), file_name: Some(file.to_string()),
dependency_type: DependencyType::Embedded.to_string(), dependency_type: DependencyType::Embedded.to_string(),
}); });
}
} }
} }
} }
@@ -974,10 +973,10 @@ pub async fn upload_file(
)); ));
} }
if let ValidationResult::Warning(msg) = validation_result { if let ValidationResult::Warning(msg) = validation_result
if primary { && primary
return Err(CreateError::InvalidInput(msg.to_string())); {
} return Err(CreateError::InvalidInput(msg.to_string()));
} }
let url = format!("{cdn_url}/{file_path_encode}"); let url = format!("{cdn_url}/{file_path_encode}");
+98 -119
View File
@@ -148,65 +148,55 @@ pub async fn get_update_from_hash(
&redis, &redis,
) )
.await? .await?
{ && let Some(project) = database::models::DBProject::get_id(
if let Some(project) = database::models::DBProject::get_id(
file.project_id, file.project_id,
&**pool, &**pool,
&redis, &redis,
) )
.await? .await?
{ {
let mut versions = database::models::DBVersion::get_many( let mut versions = database::models::DBVersion::get_many(
&project.versions, &project.versions,
&**pool, &**pool,
&redis, &redis,
) )
.await? .await?
.into_iter() .into_iter()
.filter(|x| { .filter(|x| {
let mut bool = true; let mut bool = true;
if let Some(version_types) = &update_data.version_types { if let Some(version_types) = &update_data.version_types {
bool &= version_types bool &= version_types
.iter() .iter()
.any(|y| y.as_str() == x.inner.version_type); .any(|y| y.as_str() == x.inner.version_type);
}
if let Some(loaders) = &update_data.loaders {
bool &= x.loaders.iter().any(|y| loaders.contains(y));
}
if let Some(loader_fields) = &update_data.loader_fields {
for (key, values) in loader_fields {
bool &= if let Some(x_vf) = x
.version_fields
.iter()
.find(|y| y.field_name == *key)
{
values
.iter()
.any(|v| x_vf.value.contains_json_value(v))
} else {
true
};
}
}
bool
})
.sorted();
if let Some(first) = versions.next_back() {
if !is_visible_version(
&first.inner,
&user_option,
&pool,
&redis,
)
.await?
{
return Err(ApiError::NotFound);
}
return Ok(HttpResponse::Ok()
.json(models::projects::Version::from(first)));
} }
if let Some(loaders) = &update_data.loaders {
bool &= x.loaders.iter().any(|y| loaders.contains(y));
}
if let Some(loader_fields) = &update_data.loader_fields {
for (key, values) in loader_fields {
bool &= if let Some(x_vf) =
x.version_fields.iter().find(|y| y.field_name == *key)
{
values.iter().any(|v| x_vf.value.contains_json_value(v))
} else {
true
};
}
}
bool
})
.sorted();
if let Some(first) = versions.next_back() {
if !is_visible_version(&first.inner, &user_option, &pool, &redis)
.await?
{
return Err(ApiError::NotFound);
}
return Ok(
HttpResponse::Ok().json(models::projects::Version::from(first))
);
} }
} }
Err(ApiError::NotFound) Err(ApiError::NotFound)
@@ -398,13 +388,12 @@ pub async fn update_files(
if let Some(version) = versions if let Some(version) = versions
.iter() .iter()
.find(|x| x.inner.project_id == file.project_id) .find(|x| x.inner.project_id == file.project_id)
&& let Some(hash) = file.hashes.get(&algorithm)
{ {
if let Some(hash) = file.hashes.get(&algorithm) { response.insert(
response.insert( hash.clone(),
hash.clone(), models::projects::Version::from(version.clone()),
models::projects::Version::from(version.clone()), );
);
}
} }
} }
@@ -484,69 +473,59 @@ pub async fn update_individual_files(
for project in projects { for project in projects {
for file in files.iter().filter(|x| x.project_id == project.inner.id) { for file in files.iter().filter(|x| x.project_id == project.inner.id) {
if let Some(hash) = file.hashes.get(&algorithm) { if let Some(hash) = file.hashes.get(&algorithm)
if let Some(query_file) = && let Some(query_file) =
update_data.hashes.iter().find(|x| &x.hash == hash) update_data.hashes.iter().find(|x| &x.hash == hash)
{ {
let version = all_versions let version = all_versions
.iter() .iter()
.filter(|x| x.inner.project_id == file.project_id) .filter(|x| x.inner.project_id == file.project_id)
.filter(|x| { .filter(|x| {
let mut bool = true; let mut bool = true;
if let Some(version_types) = if let Some(version_types) = &query_file.version_types {
&query_file.version_types bool &= version_types
{ .iter()
bool &= version_types.iter().any(|y| { .any(|y| y.as_str() == x.inner.version_type);
y.as_str() == x.inner.version_type
});
}
if let Some(loaders) = &query_file.loaders {
bool &= x
.loaders
.iter()
.any(|y| loaders.contains(y));
}
if let Some(loader_fields) =
&query_file.loader_fields
{
for (key, values) in loader_fields {
bool &= if let Some(x_vf) = x
.version_fields
.iter()
.find(|y| y.field_name == *key)
{
values.iter().any(|v| {
x_vf.value.contains_json_value(v)
})
} else {
true
};
}
}
bool
})
.sorted()
.next_back();
if let Some(version) = version {
if is_visible_version(
&version.inner,
&user_option,
&pool,
&redis,
)
.await?
{
response.insert(
hash.clone(),
models::projects::Version::from(
version.clone(),
),
);
} }
} if let Some(loaders) = &query_file.loaders {
bool &=
x.loaders.iter().any(|y| loaders.contains(y));
}
if let Some(loader_fields) = &query_file.loader_fields {
for (key, values) in loader_fields {
bool &= if let Some(x_vf) = x
.version_fields
.iter()
.find(|y| y.field_name == *key)
{
values.iter().any(|v| {
x_vf.value.contains_json_value(v)
})
} else {
true
};
}
}
bool
})
.sorted()
.next_back();
if let Some(version) = version
&& is_visible_version(
&version.inner,
&user_option,
&pool,
&redis,
)
.await?
{
response.insert(
hash.clone(),
models::projects::Version::from(version.clone()),
);
} }
} }
} }
+11 -12
View File
@@ -106,13 +106,12 @@ pub async fn version_project_get_helper(
|| x.inner.version_number == id.1 || x.inner.version_number == id.1
}); });
if let Some(version) = version { if let Some(version) = version
if is_visible_version(&version.inner, &user_option, &pool, &redis) && is_visible_version(&version.inner, &user_option, &pool, &redis)
.await? .await?
{ {
return Ok(HttpResponse::Ok() return Ok(HttpResponse::Ok()
.json(models::projects::Version::from(version))); .json(models::projects::Version::from(version)));
}
} }
} }
@@ -190,12 +189,12 @@ pub async fn version_get_helper(
.map(|x| x.1) .map(|x| x.1)
.ok(); .ok();
if let Some(data) = version_data { if let Some(data) = version_data
if is_visible_version(&data.inner, &user_option, &pool, &redis).await? { && is_visible_version(&data.inner, &user_option, &pool, &redis).await?
return Ok( {
HttpResponse::Ok().json(models::projects::Version::from(data)) return Ok(
); HttpResponse::Ok().json(models::projects::Version::from(data))
} );
} }
Err(ApiError::NotFound) Err(ApiError::NotFound)
+5 -7
View File
@@ -15,14 +15,12 @@ pub async fn get_user_status(
return Some(friend_status); return Some(friend_status);
} }
if let Ok(mut conn) = redis.pool.get().await { if let Ok(mut conn) = redis.pool.get().await
if let Ok(mut statuses) = && let Ok(mut statuses) =
conn.sscan::<_, String>(get_field_name(user)).await conn.sscan::<_, String>(get_field_name(user)).await
{ && let Some(status_json) = statuses.next_item().await
if let Some(status_json) = statuses.next_item().await { {
return serde_json::from_str::<UserStatus>(&status_json).ok(); return serde_json::from_str::<UserStatus>(&status_json).ok();
}
}
} }
None None
+5 -6
View File
@@ -138,12 +138,11 @@ fn process_image(
let (orig_width, orig_height) = img.dimensions(); let (orig_width, orig_height) = img.dimensions();
let aspect_ratio = orig_width as f32 / orig_height as f32; let aspect_ratio = orig_width as f32 / orig_height as f32;
if let Some(target_width) = target_width { if let Some(target_width) = target_width
if img.width() > target_width { && img.width() > target_width
let new_height = {
(target_width as f32 / aspect_ratio).round() as u32; let new_height = (target_width as f32 / aspect_ratio).round() as u32;
img = img.resize(target_width, new_height, FilterType::Lanczos3); img = img.resize(target_width, new_height, FilterType::Lanczos3);
}
} }
if let Some(min_aspect_ratio) = min_aspect_ratio { if let Some(min_aspect_ratio) = min_aspect_ratio {
+4 -5
View File
@@ -133,12 +133,11 @@ pub async fn rate_limit_middleware(
.expect("Rate limiter not configured properly") .expect("Rate limiter not configured properly")
.clone(); .clone();
if let Some(key) = req.headers().get("x-ratelimit-key") { if let Some(key) = req.headers().get("x-ratelimit-key")
if key.to_str().ok() && key.to_str().ok()
== dotenvy::var("RATE_LIMIT_IGNORE_KEY").ok().as_deref() == dotenvy::var("RATE_LIMIT_IGNORE_KEY").ok().as_deref()
{ {
return Ok(next.call(req).await?.map_into_left_body()); return Ok(next.call(req).await?.map_into_left_body());
}
} }
let conn_info = req.connection_info().clone(); let conn_info = req.connection_info().clone();
+32 -31
View File
@@ -22,46 +22,47 @@ pub fn validation_errors_to_string(
let key_option = map.keys().next(); let key_option = map.keys().next();
if let Some(field) = key_option { if let Some(field) = key_option
if let Some(error) = map.get(field) { && let Some(error) = map.get(field)
return match error { {
ValidationErrorsKind::Struct(errors) => { return match error {
validation_errors_to_string( ValidationErrorsKind::Struct(errors) => {
validation_errors_to_string(
*errors.clone(),
Some(format!("of item {field}")),
)
}
ValidationErrorsKind::List(list) => {
if let Some((index, errors)) = list.iter().next() {
output.push_str(&validation_errors_to_string(
*errors.clone(), *errors.clone(),
Some(format!("of item {field}")), Some(format!("of list {field} with index {index}")),
) ));
} }
ValidationErrorsKind::List(list) => {
if let Some((index, errors)) = list.iter().next() {
output.push_str(&validation_errors_to_string(
*errors.clone(),
Some(format!("of list {field} with index {index}")),
));
}
output output
} }
ValidationErrorsKind::Field(errors) => { ValidationErrorsKind::Field(errors) => {
if let Some(error) = errors.first() { if let Some(error) = errors.first() {
if let Some(adder) = adder { if let Some(adder) = adder {
write!( write!(
&mut output, &mut output,
"Field {field} {adder} failed validation with error: {}", "Field {field} {adder} failed validation with error: {}",
error.code error.code
).unwrap(); ).unwrap();
} else { } else {
write!( write!(
&mut output, &mut output,
"Field {field} failed validation with error: {}", "Field {field} failed validation with error: {}",
error.code error.code
).unwrap(); )
} .unwrap();
} }
output
} }
};
} output
}
};
} }
String::new() String::new()
+11 -11
View File
@@ -238,17 +238,17 @@ pub async fn send_slack_webhook(
} }
}); });
if let Some(icon_url) = metadata.project_icon_url { if let Some(icon_url) = metadata.project_icon_url
if let Some(project_block) = project_block.as_object_mut() { && let Some(project_block) = project_block.as_object_mut()
project_block.insert( {
"accessory".to_string(), project_block.insert(
serde_json::json!({ "accessory".to_string(),
"type": "image", serde_json::json!({
"image_url": icon_url, "type": "image",
"alt_text": metadata.project_title "image_url": icon_url,
}), "alt_text": metadata.project_title
); }),
} );
} }
blocks.push(project_block); blocks.push(project_block);
+1 -1
View File
@@ -292,7 +292,7 @@ pub async fn add_dummy_data(api: &ApiV3, db: TemporaryDatabase) -> DummyData {
let pool = &db.pool.clone(); let pool = &db.pool.clone();
pool.execute( pool.execute(
include_str!("../files/dummy_data.sql") include_str!("../fixtures/dummy_data.sql")
.replace("$1", &Scopes::all().bits().to_string()) .replace("$1", &Scopes::all().bits().to_string())
.as_str(), .as_str(),
) )
+16 -16
View File
@@ -222,10 +222,10 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
resp.status().as_u16() resp.status().as_u16()
)); ));
} }
if resp.status() == StatusCode::OK { if resp.status() == StatusCode::OK
if let Some(failure_json_check) = &self.failure_json_check { && let Some(failure_json_check) = &self.failure_json_check
failure_json_check(&test::read_body_json(resp).await); {
} failure_json_check(&test::read_body_json(resp).await);
} }
// Failure test- logged in on a non-team user // Failure test- logged in on a non-team user
@@ -246,10 +246,10 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
resp.status().as_u16() resp.status().as_u16()
)); ));
} }
if resp.status() == StatusCode::OK { if resp.status() == StatusCode::OK
if let Some(failure_json_check) = &self.failure_json_check { && let Some(failure_json_check) = &self.failure_json_check
failure_json_check(&test::read_body_json(resp).await); {
} failure_json_check(&test::read_body_json(resp).await);
} }
// Failure test- logged in with EVERY non-relevant permission // Failure test- logged in with EVERY non-relevant permission
@@ -270,10 +270,10 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
resp.status().as_u16() resp.status().as_u16()
)); ));
} }
if resp.status() == StatusCode::OK { if resp.status() == StatusCode::OK
if let Some(failure_json_check) = &self.failure_json_check { && let Some(failure_json_check) = &self.failure_json_check
failure_json_check(&test::read_body_json(resp).await); {
} failure_json_check(&test::read_body_json(resp).await);
} }
// Patch user's permissions to success permissions // Patch user's permissions to success permissions
@@ -300,10 +300,10 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
resp.status().as_u16() resp.status().as_u16()
)); ));
} }
if resp.status() == StatusCode::OK { if resp.status() == StatusCode::OK
if let Some(success_json_check) = &self.success_json_check { && let Some(success_json_check) = &self.success_json_check
success_json_check(&test::read_body_json(resp).await); {
} success_json_check(&test::read_body_json(resp).await);
} }
// If the remove_user flag is set, remove the user from the project // If the remove_user flag is set, remove the user from the project
+1 -1
View File
@@ -1,2 +1,2 @@
allow-dbg-in-tests = true allow-dbg-in-tests = true
msrv = "1.88.0" msrv = "1.89.0"
+47 -1
View File
@@ -1,6 +1,8 @@
name: labrinth
services: services:
postgres_db: postgres_db:
image: postgres:alpine image: postgres:alpine
container_name: labrinth-postgres
volumes: volumes:
- db-data:/var/lib/postgresql/data - db-data:/var/lib/postgresql/data
ports: ports:
@@ -16,6 +18,7 @@ services:
retries: 3 retries: 3
meilisearch: meilisearch:
image: getmeili/meilisearch:v1.12.0 image: getmeili/meilisearch:v1.12.0
container_name: labrinth-meilisearch
restart: on-failure restart: on-failure
ports: ports:
- '7700:7700' - '7700:7700'
@@ -31,6 +34,7 @@ services:
retries: 3 retries: 3
redis: redis:
image: redis:alpine image: redis:alpine
container_name: labrinth-redis
restart: on-failure restart: on-failure
ports: ports:
- '6379:6379' - '6379:6379'
@@ -43,17 +47,59 @@ services:
retries: 3 retries: 3
clickhouse: clickhouse:
image: clickhouse/clickhouse-server image: clickhouse/clickhouse-server
container_name: labrinth-clickhouse
ports: ports:
- '8123:8123' - '8123:8123'
environment: environment:
CLICKHOUSE_USER: default CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: default CLICKHOUSE_PASSWORD: default
healthcheck: healthcheck:
test: ['CMD', 'clickhouse-client', '--query', 'SELECT 1'] test: ['CMD-SHELL', 'clickhouse-client --query "SELECT 1"']
interval: 3s interval: 3s
timeout: 5s timeout: 5s
retries: 3 retries: 3
mail:
image: axllent/mailpit:v1.27
container_name: labrinth-mail
ports:
- '1025:1025'
- '8025:8025'
environment:
MP_ENABLE_SPAMASSASSIN: postmark
healthcheck:
test: ['CMD', 'wget', '-q', '-O/dev/null', 'http://localhost:8025/api/v1/info']
interval: 3s
timeout: 5s
retries: 3
labrinth:
profiles:
- with-labrinth
build:
context: .
dockerfile: ./apps/labrinth/Dockerfile
container_name: labrinth
ports:
- '8000:8000'
env_file: ./apps/labrinth/.env.docker-compose
volumes:
- labrinth-cdn-data:/tmp/modrinth
depends_on:
postgres_db:
condition: service_healthy
meilisearch:
condition: service_healthy
redis:
condition: service_healthy
clickhouse:
condition: service_healthy
mail:
condition: service_healthy
develop:
watch:
- path: ./apps/labrinth
action: rebuild
volumes: volumes:
meilisearch-data: meilisearch-data:
db-data: db-data:
redis-data: redis-data:
labrinth-cdn-data:
+4 -4
View File
@@ -50,10 +50,10 @@ pub async fn parse_command(
// We assume anything else is a filepath to an .mrpack file // We assume anything else is a filepath to an .mrpack file
let path = PathBuf::from(command_string); let path = PathBuf::from(command_string);
let path = io::canonicalize(path)?; let path = io::canonicalize(path)?;
if let Some(ext) = path.extension() { if let Some(ext) = path.extension()
if ext == "mrpack" { && ext == "mrpack"
return Ok(CommandPayload::RunMRPack { path }); {
} return Ok(CommandPayload::RunMRPack { path });
} }
emit_warning(&format!( emit_warning(&format!(
"Invalid command, unrecognized filetype: {}", "Invalid command, unrecognized filetype: {}",
+6 -6
View File
@@ -106,13 +106,13 @@ pub async fn auto_install_java(java_version: u32) -> crate::Result<PathBuf> {
})?; })?;
// removes the old installation of java // removes the old installation of java
if let Some(file) = archive.file_names().next() { if let Some(file) = archive.file_names().next()
if let Some(dir) = file.split('/').next() { && let Some(dir) = file.split('/').next()
let path = path.join(dir); {
let path = path.join(dir);
if path.exists() { if path.exists() {
io::remove_dir_all(path).await?; io::remove_dir_all(path).await?;
}
} }
} }
+5 -5
View File
@@ -72,11 +72,11 @@ pub async fn remove_user(uuid: uuid::Uuid) -> crate::Result<()> {
if let Some((uuid, user)) = users.remove(&uuid) { if let Some((uuid, user)) = users.remove(&uuid) {
Credentials::remove(uuid, &state.pool).await?; Credentials::remove(uuid, &state.pool).await?;
if user.active { if user.active
if let Some((_, mut user)) = users.into_iter().next() { && let Some((_, mut user)) = users.into_iter().next()
user.active = true; {
user.upsert(&state.pool).await?; user.active = true;
} user.upsert(&state.pool).await?;
} }
} }
@@ -221,14 +221,14 @@ async fn import_atlauncher_unmanaged(
.unwrap_or_else(|| backup_name.to_string()); .unwrap_or_else(|| backup_name.to_string());
prof.install_stage = ProfileInstallStage::PackInstalling; prof.install_stage = ProfileInstallStage::PackInstalling;
if let Some(ref project_id) = description.project_id { if let Some(ref project_id) = description.project_id
if let Some(ref version_id) = description.version_id { && let Some(ref version_id) = description.version_id
prof.linked_data = Some(LinkedData { {
project_id: project_id.clone(), prof.linked_data = Some(LinkedData {
version_id: version_id.clone(), project_id: project_id.clone(),
locked: true, version_id: version_id.clone(),
}) locked: true,
} })
} }
prof.icon_path = description prof.icon_path = description
+12 -12
View File
@@ -383,18 +383,18 @@ pub async fn set_profile_information(
.unwrap_or_else(|| backup_name.to_string()); .unwrap_or_else(|| backup_name.to_string());
prof.install_stage = ProfileInstallStage::PackInstalling; prof.install_stage = ProfileInstallStage::PackInstalling;
if let Some(ref project_id) = description.project_id { if let Some(ref project_id) = description.project_id
if let Some(ref version_id) = description.version_id { && let Some(ref version_id) = description.version_id
prof.linked_data = Some(LinkedData { {
project_id: project_id.clone(), prof.linked_data = Some(LinkedData {
version_id: version_id.clone(), project_id: project_id.clone(),
locked: if !ignore_lock { version_id: version_id.clone(),
true locked: if !ignore_lock {
} else { true
prof.linked_data.as_ref().is_none_or(|x| x.locked) } else {
}, prof.linked_data.as_ref().is_none_or(|x| x.locked)
}) },
} })
} }
prof.icon_path = description prof.icon_path = description
+10 -11
View File
@@ -149,13 +149,12 @@ pub async fn install_zipped_mrpack_files(
let profile_path = profile_path.clone(); let profile_path = profile_path.clone();
async move { async move {
//TODO: Future update: prompt user for optional files in a modpack //TODO: Future update: prompt user for optional files in a modpack
if let Some(env) = project.env { if let Some(env) = project.env
if env && env
.get(&EnvType::Client) .get(&EnvType::Client)
.is_some_and(|x| x == &SideType::Unsupported) .is_some_and(|x| x == &SideType::Unsupported)
{ {
return Ok(()); return Ok(());
}
} }
let file = fetch_mirrors( let file = fetch_mirrors(
@@ -375,12 +374,12 @@ pub async fn remove_all_related_files(
) )
.await? .await?
{ {
if let Some(metadata) = &project.metadata { if let Some(metadata) = &project.metadata
if to_remove.contains(&metadata.project_id) { && to_remove.contains(&metadata.project_id)
let path = profile_full_path.join(file_path); {
if path.exists() { let path = profile_full_path.join(file_path);
io::remove_file(&path).await?; if path.exists() {
} io::remove_file(&path).await?;
} }
} }
} }
+22 -24
View File
@@ -337,28 +337,26 @@ pub async fn update_project(
) )
.await? .await?
.remove(project_path) .remove(project_path)
&& let Some(update_version) = &file.update_version_id
{ {
if let Some(update_version) = &file.update_version_id { let path = Profile::add_project_version(
let path = Profile::add_project_version( profile_path,
profile_path, update_version,
update_version, &state.pool,
&state.pool, &state.fetch_semaphore,
&state.fetch_semaphore, &state.io_semaphore,
&state.io_semaphore, )
) .await?;
.await?;
if path != project_path { if path != project_path {
Profile::remove_project(profile_path, project_path).await?; Profile::remove_project(profile_path, project_path).await?;
}
if !skip_send_event.unwrap_or(false) {
emit_profile(profile_path, ProfilePayloadType::Edited)
.await?;
}
return Ok(path);
} }
if !skip_send_event.unwrap_or(false) {
emit_profile(profile_path, ProfilePayloadType::Edited).await?;
}
return Ok(path);
} }
Err(crate::ErrorKind::InputError( Err(crate::ErrorKind::InputError(
@@ -479,10 +477,10 @@ pub async fn export_mrpack(
let included_export_candidates = included_export_candidates let included_export_candidates = included_export_candidates
.into_iter() .into_iter()
.filter(|x| { .filter(|x| {
if let Some(f) = PathBuf::from(x).file_name() { if let Some(f) = PathBuf::from(x).file_name()
if f.to_string_lossy().starts_with(".DS_Store") { && f.to_string_lossy().starts_with(".DS_Store")
return false; {
} return false;
} }
true true
}) })
@@ -765,7 +763,7 @@ pub async fn try_update_playtime(path: &str) -> crate::Result<()> {
let updated_recent_playtime = profile.recent_time_played; let updated_recent_playtime = profile.recent_time_played;
let res = if updated_recent_playtime > 0 { let res = if updated_recent_playtime > 0 {
// Create update struct to send to Labrinth // Create update struct to send to labrinth
let modrinth_pack_version_id = let modrinth_pack_version_id =
profile.linked_data.as_ref().map(|l| l.version_id.clone()); profile.linked_data.as_ref().map(|l| l.version_id.clone());
let playtime_update_json = json!({ let playtime_update_json = json!({
+16 -15
View File
@@ -187,6 +187,7 @@ pub enum LoadingBarType {
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
#[cfg(feature = "tauri")]
pub struct LoadingPayload { pub struct LoadingPayload {
pub event: LoadingBarType, pub event: LoadingBarType,
pub loader_uuid: Uuid, pub loader_uuid: Uuid,
@@ -195,11 +196,7 @@ pub struct LoadingPayload {
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
pub struct OfflinePayload { #[cfg(feature = "tauri")]
pub offline: bool,
}
#[derive(Serialize, Clone)]
pub struct WarningPayload { pub struct WarningPayload {
pub message: String, pub message: String,
} }
@@ -223,12 +220,14 @@ pub enum CommandPayload {
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
#[cfg(feature = "tauri")]
pub struct ProcessPayload { pub struct ProcessPayload {
pub profile_path_id: String, pub profile_path_id: String,
pub uuid: Uuid, pub uuid: Uuid,
pub event: ProcessPayloadType, pub event: ProcessPayloadType,
pub message: String, pub message: String,
} }
#[derive(Serialize, Clone, Debug)] #[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum ProcessPayloadType { pub enum ProcessPayloadType {
@@ -237,11 +236,13 @@ pub enum ProcessPayloadType {
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
#[cfg(feature = "tauri")]
pub struct ProfilePayload { pub struct ProfilePayload {
pub profile_path_id: String, pub profile_path_id: String,
#[serde(flatten)] #[serde(flatten)]
pub event: ProfilePayloadType, pub event: ProfilePayloadType,
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
#[serde(tag = "event", rename_all = "snake_case")] #[serde(tag = "event", rename_all = "snake_case")]
pub enum ProfilePayloadType { pub enum ProfilePayloadType {
@@ -260,6 +261,16 @@ pub enum ProfilePayloadType {
Removed, Removed,
} }
#[derive(Serialize, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "event")]
pub enum FriendPayload {
FriendRequest { from: UserId },
UserOffline { id: UserId },
StatusUpdate { user_status: UserStatus },
StatusSync,
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum EventError { pub enum EventError {
#[error("Event state was not properly initialized")] #[error("Event state was not properly initialized")]
@@ -272,13 +283,3 @@ pub enum EventError {
#[error("Tauri error: {0}")] #[error("Tauri error: {0}")]
TauriError(#[from] tauri::Error), TauriError(#[from] tauri::Error),
} }
#[derive(Serialize, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "event")]
pub enum FriendPayload {
FriendRequest { from: UserId },
UserOffline { id: UserId },
StatusUpdate { user_status: UserStatus },
StatusSync,
}
+9 -9
View File
@@ -32,15 +32,15 @@ pub fn get_class_paths(
let mut cps = libraries let mut cps = libraries
.iter() .iter()
.filter_map(|library| { .filter_map(|library| {
if let Some(rules) = &library.rules { if let Some(rules) = &library.rules
if !parse_rules( && !parse_rules(
rules, rules,
java_arch, java_arch,
&QuickPlayType::None, &QuickPlayType::None,
minecraft_updated, minecraft_updated,
) { )
return None; {
} return None;
} }
if !library.include_in_classpath { if !library.include_in_classpath {
@@ -504,10 +504,10 @@ pub async fn get_processor_main_class(
let mut line = line.map_err(IOError::from)?; let mut line = line.map_err(IOError::from)?;
line.retain(|c| !c.is_whitespace()); line.retain(|c| !c.is_whitespace());
if line.starts_with("Main-Class:") { if line.starts_with("Main-Class:")
if let Some(class) = line.split(':').nth(1) { && let Some(class) = line.split(':').nth(1)
return Ok(Some(class.to_string())); {
} return Ok(Some(class.to_string()));
} }
} }
+4 -6
View File
@@ -290,12 +290,11 @@ pub async fn download_libraries(
loading_try_for_each_concurrent( loading_try_for_each_concurrent(
stream::iter(libraries.iter()) stream::iter(libraries.iter())
.map(Ok::<&Library, crate::Error>), None, loading_bar,loading_amount,num_files, None,|library| async move { .map(Ok::<&Library, crate::Error>), None, loading_bar,loading_amount,num_files, None,|library| async move {
if let Some(rules) = &library.rules { if let Some(rules) = &library.rules
if !parse_rules(rules, java_arch, &QuickPlayType::None, minecraft_updated) { && !parse_rules(rules, java_arch, &QuickPlayType::None, minecraft_updated) {
tracing::trace!("Skipped library {}", &library.name); tracing::trace!("Skipped library {}", &library.name);
return Ok(()); return Ok(());
} }
}
if !library.downloadable { if !library.downloadable {
tracing::trace!("Skipped non-downloadable library {}", &library.name); tracing::trace!("Skipped non-downloadable library {}", &library.name);
@@ -311,15 +310,14 @@ pub async fn download_libraries(
return Ok(()); return Ok(());
} }
if let Some(d::minecraft::LibraryDownloads { artifact: Some(ref artifact), ..}) = library.downloads { if let Some(d::minecraft::LibraryDownloads { artifact: Some(ref artifact), ..}) = library.downloads
if !artifact.url.is_empty(){ && !artifact.url.is_empty(){
let bytes = fetch(&artifact.url, Some(&artifact.sha1), &st.fetch_semaphore, &st.pool) let bytes = fetch(&artifact.url, Some(&artifact.sha1), &st.fetch_semaphore, &st.pool)
.await?; .await?;
write(&path, &bytes, &st.io_semaphore).await?; write(&path, &bytes, &st.io_semaphore).await?;
tracing::trace!("Fetched library {} to path {:?}", &library.name, &path); tracing::trace!("Fetched library {} to path {:?}", &library.name, &path);
return Ok::<_, crate::Error>(()); return Ok::<_, crate::Error>(());
} }
}
let url = [ let url = [
library library
+4 -4
View File
@@ -344,10 +344,10 @@ pub async fn install_minecraft(
// Forge processors (90-100) // Forge processors (90-100)
for (index, processor) in processors.iter().enumerate() { for (index, processor) in processors.iter().enumerate() {
if let Some(sides) = &processor.sides { if let Some(sides) = &processor.sides
if !sides.contains(&String::from("client")) { && !sides.contains(&String::from("client"))
continue; {
} continue;
} }
let cp = { let cp = {
+4 -4
View File
@@ -391,10 +391,10 @@ impl DirectoryInfo {
return Err(e); return Err(e);
} }
} else { } else {
if let Some(disk_usage) = get_disk_usage(&move_dir)? { if let Some(disk_usage) = get_disk_usage(&move_dir)?
if total_size > disk_usage { && total_size > disk_usage
return Err(crate::ErrorKind::DirectoryMoveError(format!("Not enough space to move directory to {}: only {} bytes available", app_dir.display(), disk_usage)).into()); {
} return Err(crate::ErrorKind::DirectoryMoveError(format!("Not enough space to move directory to {}: only {} bytes available", app_dir.display(), disk_usage)).into());
} }
let loader_bar_id = Arc::new(&loader_bar_id); let loader_bar_id = Arc::new(&loader_bar_id);
+7 -11
View File
@@ -9,7 +9,7 @@ use ariadne::networking::message::{
ClientToServerMessage, ServerToClientMessage, ClientToServerMessage, ServerToClientMessage,
}; };
use ariadne::users::UserStatus; use ariadne::users::UserStatus;
use async_tungstenite::WebSocketStream; use async_tungstenite::WebSocketSender;
use async_tungstenite::tokio::{ConnectStream, connect_async}; use async_tungstenite::tokio::{ConnectStream, connect_async};
use async_tungstenite::tungstenite::Message; use async_tungstenite::tungstenite::Message;
use async_tungstenite::tungstenite::client::IntoClientRequest; use async_tungstenite::tungstenite::client::IntoClientRequest;
@@ -17,7 +17,6 @@ use bytes::Bytes;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use dashmap::DashMap; use dashmap::DashMap;
use either::Either; use either::Either;
use futures::stream::SplitSink;
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
use reqwest::Method; use reqwest::Method;
use reqwest::header::HeaderValue; use reqwest::header::HeaderValue;
@@ -32,7 +31,7 @@ use tokio::sync::{Mutex, RwLock};
use uuid::Uuid; use uuid::Uuid;
pub(super) type WriteSocket = pub(super) type WriteSocket =
Arc<RwLock<Option<SplitSink<WebSocketStream<ConnectStream>, Message>>>>; Arc<RwLock<Option<WebSocketSender<ConnectStream>>>>;
pub(super) type TunnelSockets = Arc<DashMap<Uuid, Arc<InternalTunnelSocket>>>; pub(super) type TunnelSockets = Arc<DashMap<Uuid, Arc<InternalTunnelSocket>>>;
pub struct FriendsSocket { pub struct FriendsSocket {
@@ -180,27 +179,24 @@ impl FriendsSocket {
ServerToClientMessage::FriendSocketStoppedListening { .. } => {}, // TODO ServerToClientMessage::FriendSocketStoppedListening { .. } => {}, // TODO
ServerToClientMessage::SocketConnected { to_socket, new_socket } => { ServerToClientMessage::SocketConnected { to_socket, new_socket } => {
if let Some(connected_to) = sockets.get(&to_socket) { if let Some(connected_to) = sockets.get(&to_socket)
if let InternalTunnelSocket::Listening(local_addr) = *connected_to.value().clone() { && let InternalTunnelSocket::Listening(local_addr) = *connected_to.value().clone()
if let Ok(new_stream) = TcpStream::connect(local_addr).await { && let Ok(new_stream) = TcpStream::connect(local_addr).await {
let (read, write) = new_stream.into_split(); let (read, write) = new_stream.into_split();
sockets.insert(new_socket, Arc::new(InternalTunnelSocket::Connected(Mutex::new(write)))); sockets.insert(new_socket, Arc::new(InternalTunnelSocket::Connected(Mutex::new(write))));
Self::socket_read_loop(write_handle.clone(), read, new_socket); Self::socket_read_loop(write_handle.clone(), read, new_socket);
continue; continue;
} }
}
}
let _ = Self::send_message(&write_handle, ClientToServerMessage::SocketClose { socket: new_socket }).await; let _ = Self::send_message(&write_handle, ClientToServerMessage::SocketClose { socket: new_socket }).await;
}, },
ServerToClientMessage::SocketClosed { socket } => { ServerToClientMessage::SocketClosed { socket } => {
sockets.remove_if(&socket, |_, x| matches!(*x.clone(), InternalTunnelSocket::Connected(_))); sockets.remove_if(&socket, |_, x| matches!(*x.clone(), InternalTunnelSocket::Connected(_)));
}, },
ServerToClientMessage::SocketData { socket, data } => { ServerToClientMessage::SocketData { socket, data } => {
if let Some(mut socket) = sockets.get_mut(&socket) { if let Some(mut socket) = sockets.get_mut(&socket)
if let InternalTunnelSocket::Connected(ref stream) = *socket.value_mut().clone() { && let InternalTunnelSocket::Connected(ref stream) = *socket.value_mut().clone() {
let _ = stream.lock().await.write_all(&data).await; let _ = stream.lock().await.write_all(&data).await;
} }
}
}, },
} }
} }
+9 -10
View File
@@ -100,8 +100,8 @@ pub async fn init_watcher() -> crate::Result<FileWatcher> {
let profile_path_str = profile_path_str.clone(); let profile_path_str = profile_path_str.clone();
let world = world.clone(); let world = world.clone();
tokio::spawn(async move { tokio::spawn(async move {
if let Ok(state) = State::get().await { if let Ok(state) = State::get().await
if let Err(e) = attached_world_data::AttachedWorldData::remove_for_world( && let Err(e) = attached_world_data::AttachedWorldData::remove_for_world(
&profile_path_str, &profile_path_str,
WorldType::Singleplayer, WorldType::Singleplayer,
&world, &world,
@@ -109,7 +109,6 @@ pub async fn init_watcher() -> crate::Result<FileWatcher> {
).await { ).await {
tracing::warn!("Failed to remove AttachedWorldData for '{world}': {e}") tracing::warn!("Failed to remove AttachedWorldData for '{world}': {e}")
} }
}
}); });
} }
Some(ProfilePayloadType::WorldUpdated { world }) Some(ProfilePayloadType::WorldUpdated { world })
@@ -150,14 +149,14 @@ pub(crate) async fn watch_profiles_init(
) { ) {
if let Ok(profiles_dir) = std::fs::read_dir(dirs.profiles_dir()) { if let Ok(profiles_dir) = std::fs::read_dir(dirs.profiles_dir()) {
for profile_dir in profiles_dir { for profile_dir in profiles_dir {
if let Ok(file_name) = profile_dir.map(|x| x.file_name()) { if let Ok(file_name) = profile_dir.map(|x| x.file_name())
if let Some(file_name) = file_name.to_str() { && let Some(file_name) = file_name.to_str()
if file_name.starts_with(".DS_Store") { {
continue; if file_name.starts_with(".DS_Store") {
}; continue;
};
watch_profile(file_name, watcher, dirs).await; watch_profile(file_name, watcher, dirs).await;
}
} }
} }
} }
+111 -124
View File
@@ -76,10 +76,9 @@ where
.loaded_config_dir .loaded_config_dir
.clone() .clone()
.and_then(|x| x.to_str().map(|x| x.to_string())) .and_then(|x| x.to_str().map(|x| x.to_string()))
&& path != old_launcher_root_str
{ {
if path != old_launcher_root_str { settings.custom_dir = Some(path);
settings.custom_dir = Some(path);
}
} }
settings.prev_custom_dir = Some(old_launcher_root_str.clone()); settings.prev_custom_dir = Some(old_launcher_root_str.clone());
@@ -137,31 +136,27 @@ where
.await?; .await?;
} }
if let Some(device_token) = minecraft_auth.token { if let Some(device_token) = minecraft_auth.token
if let Ok(private_key) = && let Ok(private_key) =
SigningKey::from_pkcs8_pem(&device_token.private_key) SigningKey::from_pkcs8_pem(&device_token.private_key)
{ && let Ok(uuid) = Uuid::parse_str(&device_token.id)
if let Ok(uuid) = Uuid::parse_str(&device_token.id) { {
DeviceTokenPair { DeviceTokenPair {
token: DeviceToken { token: DeviceToken {
issue_instant: device_token.token.issue_instant, issue_instant: device_token.token.issue_instant,
not_after: device_token.token.not_after, not_after: device_token.token.not_after,
token: device_token.token.token, token: device_token.token.token,
display_claims: device_token display_claims: device_token.token.display_claims,
.token },
.display_claims, key: DeviceTokenKey {
}, id: uuid,
key: DeviceTokenKey { key: private_key,
id: uuid, x: device_token.x,
key: private_key, y: device_token.y,
x: device_token.x, },
y: device_token.y,
},
}
.upsert(exec)
.await?;
}
} }
.upsert(exec)
.await?;
} }
} }
@@ -208,100 +203,93 @@ where
update_version, update_version,
.. ..
} = project.metadata } = project.metadata
{ && let Some(file) = version
if let Some(file) = version
.files .files
.iter() .iter()
.find(|x| x.hashes.get("sha512") == Some(&sha512)) .find(|x| x.hashes.get("sha512") == Some(&sha512))
{ && let Some(sha1) = file.hashes.get("sha1")
if let Some(sha1) = file.hashes.get("sha1") { {
if let Ok(metadata) = full_path.metadata() { if let Ok(metadata) = full_path.metadata() {
let file_name = format!( let file_name = format!(
"{}/{}", "{}/{}",
profile.path, profile.path,
path.replace('\\', "/") path.replace('\\', "/")
.replace(".disabled", "") .replace(".disabled", "")
); );
cached_entries.push(CacheValue::FileHash( cached_entries.push(CacheValue::FileHash(
CachedFileHash { CachedFileHash {
path: file_name, path: file_name,
size: metadata.len(), size: metadata.len(),
hash: sha1.clone(), hash: sha1.clone(),
project_type: ProjectType::get_from_parent_folder(&full_path), project_type:
}, ProjectType::get_from_parent_folder(
)); &full_path,
}
cached_entries.push(CacheValue::File(
CachedFile {
hash: sha1.clone(),
project_id: version.project_id.clone(),
version_id: version.id.clone(),
},
));
if let Some(update_version) = update_version {
let mod_loader: ModLoader =
profile.metadata.loader.into();
cached_entries.push(
CacheValue::FileUpdate(
CachedFileUpdate {
hash: sha1.clone(),
game_version: profile
.metadata
.game_version
.clone(),
loaders: vec![
mod_loader
.as_str()
.to_string(),
],
update_version_id:
update_version.id.clone(),
},
), ),
); },
));
cached_entries.push(CacheValue::Version(
(*update_version).into(),
));
}
let members = members
.into_iter()
.map(|x| {
let user = User {
id: x.user.id,
username: x.user.username,
avatar_url: x.user.avatar_url,
bio: x.user.bio,
created: x.user.created,
role: x.user.role,
badges: 0,
};
cached_entries.push(CacheValue::User(
user.clone(),
));
TeamMember {
team_id: x.team_id,
user,
is_owner: x.role == "Owner",
role: x.role,
ordering: x.ordering,
}
})
.collect::<Vec<_>>();
cached_entries.push(CacheValue::Team(members));
cached_entries.push(CacheValue::Version(
(*version).into(),
));
}
} }
cached_entries.push(CacheValue::File(CachedFile {
hash: sha1.clone(),
project_id: version.project_id.clone(),
version_id: version.id.clone(),
}));
if let Some(update_version) = update_version {
let mod_loader: ModLoader =
profile.metadata.loader.into();
cached_entries.push(CacheValue::FileUpdate(
CachedFileUpdate {
hash: sha1.clone(),
game_version: profile
.metadata
.game_version
.clone(),
loaders: vec![
mod_loader.as_str().to_string(),
],
update_version_id: update_version
.id
.clone(),
},
));
cached_entries.push(CacheValue::Version(
(*update_version).into(),
));
}
let members = members
.into_iter()
.map(|x| {
let user = User {
id: x.user.id,
username: x.user.username,
avatar_url: x.user.avatar_url,
bio: x.user.bio,
created: x.user.created,
role: x.user.role,
badges: 0,
};
cached_entries
.push(CacheValue::User(user.clone()));
TeamMember {
team_id: x.team_id,
user,
is_owner: x.role == "Owner",
role: x.role,
ordering: x.ordering,
}
})
.collect::<Vec<_>>();
cached_entries.push(CacheValue::Team(members));
cached_entries
.push(CacheValue::Version((*version).into()));
} }
} }
@@ -333,16 +321,15 @@ where
.map(|x| x.id), .map(|x| x.id),
groups: profile.metadata.groups, groups: profile.metadata.groups,
linked_data: profile.metadata.linked_data.and_then(|x| { linked_data: profile.metadata.linked_data.and_then(|x| {
if let Some(project_id) = x.project_id { if let Some(project_id) = x.project_id
if let Some(version_id) = x.version_id { && let Some(version_id) = x.version_id
if let Some(locked) = x.locked { && let Some(locked) = x.locked
return Some(LinkedData { {
project_id, return Some(LinkedData {
version_id, project_id,
locked, version_id,
}); locked,
} });
}
} }
None None
+28 -38
View File
@@ -477,10 +477,9 @@ impl Credentials {
.. ..
}, },
) = *err.raw ) = *err.raw
&& (source.is_connect() || source.is_timeout())
{ {
if source.is_connect() || source.is_timeout() { return Ok(Some(creds));
return Ok(Some(creds));
}
} }
Err(err) Err(err)
@@ -729,36 +728,31 @@ impl DeviceTokenPair {
.fetch_optional(exec) .fetch_optional(exec)
.await?; .await?;
if let Some(x) = res { if let Some(x) = res
if let Ok(uuid) = Uuid::parse_str(&x.uuid) { && let Ok(uuid) = Uuid::parse_str(&x.uuid)
if let Ok(private_key) = && let Ok(private_key) = SigningKey::from_pkcs8_pem(&x.private_key)
SigningKey::from_pkcs8_pem(&x.private_key) {
{ return Ok(Some(Self {
return Ok(Some(Self { token: DeviceToken {
token: DeviceToken { issue_instant: Utc
issue_instant: Utc .timestamp_opt(x.issue_instant, 0)
.timestamp_opt(x.issue_instant, 0) .single()
.single() .unwrap_or_else(Utc::now),
.unwrap_or_else(Utc::now), not_after: Utc
not_after: Utc .timestamp_opt(x.not_after, 0)
.timestamp_opt(x.not_after, 0) .single()
.single() .unwrap_or_else(Utc::now),
.unwrap_or_else(Utc::now), token: x.token,
token: x.token, display_claims: serde_json::from_value(x.display_claims)
display_claims: serde_json::from_value( .unwrap_or_default(),
x.display_claims, },
) key: DeviceTokenKey {
.unwrap_or_default(), id: uuid,
}, key: private_key,
key: DeviceTokenKey { x: x.x,
id: uuid, y: x.y,
key: private_key, },
x: x.x, }));
y: x.y,
},
}));
}
}
} }
Ok(None) Ok(None)
@@ -813,11 +807,7 @@ const MICROSOFT_CLIENT_ID: &str = "00000000402b5328";
const AUTH_REPLY_URL: &str = "https://login.live.com/oauth20_desktop.srf"; const AUTH_REPLY_URL: &str = "https://login.live.com/oauth20_desktop.srf";
const REQUESTED_SCOPE: &str = "service::user.auth.xboxlive.com::MBI_SSL"; const REQUESTED_SCOPE: &str = "service::user.auth.xboxlive.com::MBI_SSL";
/* [AR] Fix pub struct RequestWithDate<T> {
* Weird visibility issue that didn't reproduce before
* Had to make DeviceToken and RequestWithDate pub(crate) to fix compilation error
*/
pub(crate) struct RequestWithDate<T> {
pub date: DateTime<Utc>, pub date: DateTime<Utc>,
pub value: T, pub value: T,
} }
+1 -1
View File
@@ -198,7 +198,7 @@ pub async fn finish_login_flow(
semaphore: &FetchSemaphore, semaphore: &FetchSemaphore,
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>, exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
) -> crate::Result<ModrinthCredentials> { ) -> crate::Result<ModrinthCredentials> {
// The authorization code actually is the access token, since Labrinth doesn't // The authorization code actually is the access token, since labrinth doesn't
// issue separate authorization codes. Therefore, this is equivalent to an // issue separate authorization codes. Therefore, this is equivalent to an
// implicit OAuth grant flow, and no additional exchanging or finalization is // implicit OAuth grant flow, and no additional exchanging or finalization is
// needed. TODO not do this for the reasons outlined at // needed. TODO not do this for the reasons outlined at
+27 -39
View File
@@ -360,18 +360,17 @@ impl Process {
} }
// Write the throwable if present // Write the throwable if present
if !current_content.is_empty() { if !current_content.is_empty()
if let Err(e) = && let Err(e) =
Process::append_to_log_file( Process::append_to_log_file(
&log_path, &log_path,
&current_content, &current_content,
) )
{ {
tracing::error!( tracing::error!(
"Failed to write throwable to log file: {}", "Failed to write throwable to log file: {}",
e e
); );
}
} }
} }
} }
@@ -429,15 +428,13 @@ impl Process {
if let Some(timestamp) = if let Some(timestamp) =
current_event.timestamp.as_deref() current_event.timestamp.as_deref()
{ && let Err(e) = Self::maybe_handle_server_join_logging(
if let Err(e) = Self::maybe_handle_server_join_logging(
profile_path, profile_path,
timestamp, timestamp,
message message
).await { ).await {
tracing::error!("Failed to handle server join logging: {e}"); tracing::error!("Failed to handle server join logging: {e}");
} }
}
} }
} }
_ => {} _ => {}
@@ -445,35 +442,29 @@ impl Process {
} }
Ok(Event::Text(mut e)) => { Ok(Event::Text(mut e)) => {
if in_message || in_throwable { if in_message || in_throwable {
if let Ok(text) = e.unescape() { if let Ok(text) = e.xml_content() {
current_content.push_str(&text); current_content.push_str(&text);
} }
} else if !in_event } else if !in_event
&& !e.inplace_trim_end() && !e.inplace_trim_end()
&& !e.inplace_trim_start() && !e.inplace_trim_start()
&& let Ok(text) = e.xml_content()
&& let Err(e) = Process::append_to_log_file(
&log_path,
&format!("{text}\n"),
)
{ {
if let Ok(text) = e.unescape() { tracing::error!(
if let Err(e) = Process::append_to_log_file( "Failed to write to log file: {}",
&log_path, e
&format!("{text}\n"), );
) {
tracing::error!(
"Failed to write to log file: {}",
e
);
}
}
} }
} }
Ok(Event::CData(e)) => { Ok(Event::CData(e)) => {
if in_message || in_throwable { if (in_message || in_throwable)
if let Ok(text) = e && let Ok(text) = e.xml_content()
.escape() {
.map_err(|x| x.into()) current_content.push_str(&text);
.and_then(|x| x.unescape())
{
current_content.push_str(&text);
}
} }
} }
_ => (), _ => (),
@@ -720,16 +711,13 @@ impl Process {
let logs_folder = state.directories.profile_logs_dir(&profile_path); let logs_folder = state.directories.profile_logs_dir(&profile_path);
let log_path = logs_folder.join(LAUNCHER_LOG_PATH); let log_path = logs_folder.join(LAUNCHER_LOG_PATH);
if log_path.exists() { if log_path.exists()
if let Err(e) = Process::append_to_log_file( && let Err(e) = Process::append_to_log_file(
&log_path, &log_path,
&format!("\n# Process exited with status: {mc_exit_status}\n"), &format!("\n# Process exited with status: {mc_exit_status}\n"),
) { )
tracing::warn!( {
"Failed to write exit status to log file: {}", tracing::warn!("Failed to write exit status to log file: {}", e);
e
);
}
} }
let _ = state.discord_rpc.clear_to_default(true).await; let _ = state.discord_rpc.clear_to_default(true).await;
+34 -36
View File
@@ -595,8 +595,8 @@ impl Profile {
} }
#[tracing::instrument(skip(self, semaphore, icon))] #[tracing::instrument(skip(self, semaphore, icon))]
pub async fn set_icon<'a>( pub async fn set_icon(
&'a mut self, &mut self,
cache_dir: &Path, cache_dir: &Path,
semaphore: &IoSemaphore, semaphore: &IoSemaphore,
icon: bytes::Bytes, icon: bytes::Bytes,
@@ -629,21 +629,20 @@ impl Profile {
{ {
let subdirectory = let subdirectory =
subdirectory.map_err(io::IOError::from)?.path(); subdirectory.map_err(io::IOError::from)?.path();
if subdirectory.is_file() { if subdirectory.is_file()
if let Some(file_name) = subdirectory && let Some(file_name) = subdirectory
.file_name() .file_name()
.and_then(|x| x.to_str()) .and_then(|x| x.to_str())
{ {
let file_size = subdirectory let file_size = subdirectory
.metadata() .metadata()
.map_err(io::IOError::from)? .map_err(io::IOError::from)?
.len(); .len();
keys.push(format!( keys.push(format!(
"{file_size}-{}/{folder}/{file_name}", "{file_size}-{}/{folder}/{file_name}",
profile.path profile.path
)); ));
}
} }
} }
} }
@@ -901,30 +900,29 @@ impl Profile {
{ {
let subdirectory = let subdirectory =
subdirectory.map_err(io::IOError::from)?.path(); subdirectory.map_err(io::IOError::from)?.path();
if subdirectory.is_file() { if subdirectory.is_file()
if let Some(file_name) = && let Some(file_name) =
subdirectory.file_name().and_then(|x| x.to_str()) subdirectory.file_name().and_then(|x| x.to_str())
{ {
let file_size = subdirectory let file_size = subdirectory
.metadata() .metadata()
.map_err(io::IOError::from)? .map_err(io::IOError::from)?
.len(); .len();
keys.push(InitialScanFile { keys.push(InitialScanFile {
path: format!( path: format!(
"{}/{folder}/{}", "{}/{folder}/{}",
self.path, self.path,
file_name.trim_end_matches(".disabled") file_name.trim_end_matches(".disabled")
), ),
file_name: file_name.to_string(), file_name: file_name.to_string(),
project_type, project_type,
size: file_size, size: file_size,
cache_key: format!( cache_key: format!(
"{file_size}-{}/{folder}/{file_name}", "{file_size}-{}/{folder}/{file_name}",
self.path self.path
), ),
}); });
}
} }
} }
} }
+1 -1
View File
@@ -254,7 +254,7 @@ where
} }
#[tracing::instrument(skip(bytes, semaphore))] #[tracing::instrument(skip(bytes, semaphore))]
pub async fn write<'a>( pub async fn write(
path: &Path, path: &Path,
bytes: &[u8], bytes: &[u8],
semaphore: &IoSemaphore, semaphore: &IoSemaphore,
+26 -27
View File
@@ -191,22 +191,21 @@ async fn get_all_autoinstalled_jre_path() -> Result<HashSet<PathBuf>, JREError>
let mut jre_paths = HashSet::new(); let mut jre_paths = HashSet::new();
let base_path = state.directories.java_versions_dir(); let base_path = state.directories.java_versions_dir();
if base_path.is_dir() { if base_path.is_dir()
if let Ok(dir) = std::fs::read_dir(base_path) { && let Ok(dir) = std::fs::read_dir(base_path)
for entry in dir.flatten() { {
let file_path = entry.path().join("bin"); for entry in dir.flatten() {
let file_path = entry.path().join("bin");
if let Ok(contents) = if let Ok(contents) = std::fs::read_to_string(file_path.clone())
std::fs::read_to_string(file_path.clone()) {
let entry = entry.path().join(contents);
jre_paths.insert(entry);
} else {
#[cfg(not(target_os = "macos"))]
{ {
let entry = entry.path().join(contents); let file_path = file_path.join(JAVA_BIN);
jre_paths.insert(entry); jre_paths.insert(file_path);
} else {
#[cfg(not(target_os = "macos"))]
{
let file_path = file_path.join(JAVA_BIN);
jre_paths.insert(file_path);
}
} }
} }
} }
@@ -300,20 +299,20 @@ pub async fn check_java_at_filepath(path: &Path) -> crate::Result<JavaVersion> {
} }
// Extract version info from it // Extract version info from it
if let Some(arch) = java_arch { if let Some(arch) = java_arch
if let Some(version) = java_version { && let Some(version) = java_version
if let Ok(version) = extract_java_version(version) { {
let path = java.to_string_lossy().to_string(); if let Ok(version) = extract_java_version(version) {
return Ok(JavaVersion { let path = java.to_string_lossy().to_string();
parsed_version: version, return Ok(JavaVersion {
path, parsed_version: version,
version: version.to_string(), path,
architecture: arch.to_string(), version: version.to_string(),
}); architecture: arch.to_string(),
} });
return Err(JREError::InvalidJREVersion(version.to_owned()).into());
} }
return Err(JREError::InvalidJREVersion(version.to_owned()).into());
} }
Err(JREError::FailedJavaCheck(java).into()) Err(JREError::FailedJavaCheck(java).into())
+5 -6
View File
@@ -33,12 +33,11 @@ pub fn is_feature_supported_in(
if part_version == part_first_release { if part_version == part_first_release {
continue; continue;
} }
if let Ok(part_version) = part_version.parse::<u32>() { if let Ok(part_version) = part_version.parse::<u32>()
if let Ok(part_first_release) = part_first_release.parse::<u32>() { && let Ok(part_first_release) = part_first_release.parse::<u32>()
if part_version > part_first_release { && part_version > part_first_release
return true; {
} return true;
}
} }
} }
false false
+4
View File
@@ -169,6 +169,8 @@ import _TerminalSquareIcon from './icons/terminal-square.svg?component'
import _TestIcon from './icons/test.svg?component' import _TestIcon from './icons/test.svg?component'
import _TextQuoteIcon from './icons/text-quote.svg?component' import _TextQuoteIcon from './icons/text-quote.svg?component'
import _TimerIcon from './icons/timer.svg?component' import _TimerIcon from './icons/timer.svg?component'
import _ToggleLeftIcon from './icons/toggle-left.svg?component'
import _ToggleRightIcon from './icons/toggle-right.svg?component'
import _TransferIcon from './icons/transfer.svg?component' import _TransferIcon from './icons/transfer.svg?component'
import _TrashIcon from './icons/trash.svg?component' import _TrashIcon from './icons/trash.svg?component'
import _TriangleAlertIcon from './icons/triangle-alert.svg?component' import _TriangleAlertIcon from './icons/triangle-alert.svg?component'
@@ -362,6 +364,8 @@ export const TerminalSquareIcon = _TerminalSquareIcon
export const TestIcon = _TestIcon export const TestIcon = _TestIcon
export const TextQuoteIcon = _TextQuoteIcon export const TextQuoteIcon = _TextQuoteIcon
export const TimerIcon = _TimerIcon export const TimerIcon = _TimerIcon
export const ToggleLeftIcon = _ToggleLeftIcon
export const ToggleRightIcon = _ToggleRightIcon
export const TransferIcon = _TransferIcon export const TransferIcon = _TransferIcon
export const TrashIcon = _TrashIcon export const TrashIcon = _TrashIcon
export const TriangleAlertIcon = _TriangleAlertIcon export const TriangleAlertIcon = _TriangleAlertIcon
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-left-icon lucide-toggle-left"><circle cx="9" cy="12" r="3"/><rect width="20" height="14" x="2" y="5" rx="7"/></svg>

After

Width:  |  Height:  |  Size: 324 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right-icon lucide-toggle-right"><circle cx="15" cy="12" r="3"/><rect width="20" height="14" x="2" y="5" rx="7"/></svg>

After

Width:  |  Height:  |  Size: 327 B

+7179 -6266
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "1.88.0" channel = "1.89.0"