You've already forked AstralRinth
forked from didirus/AstralRinth
Update Analytics req + Fix versions list (#529)
* Update Analytics req + Fix versions list * Fix sentry support * Fix lint
This commit is contained in:
@@ -498,7 +498,7 @@ impl Version {
|
||||
INNER JOIN game_versions gv on gvv.game_version_id = gv.id AND (cardinality($2::varchar[]) = 0 OR gv.version = ANY($2::varchar[]))
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = v.id
|
||||
INNER JOIN loaders l on lv.loader_id = l.id AND (cardinality($3::varchar[]) = 0 OR l.loader = ANY($3::varchar[]))
|
||||
WHERE v.mod_id = $1 AND ($4 = NULL OR v.version_type = $4)
|
||||
WHERE v.mod_id = $1 AND ($4::varchar IS NULL OR v.version_type = $4)
|
||||
ORDER BY v.date_published, v.id ASC
|
||||
LIMIT $5 OFFSET $6
|
||||
",
|
||||
|
||||
@@ -34,7 +34,7 @@ pub async fn authorize_account(
|
||||
key_id: &str,
|
||||
application_key: &str,
|
||||
) -> Result<AuthorizationData, FileHostingError> {
|
||||
let combined_key = format!("{}:{}", key_id, application_key);
|
||||
let combined_key = format!("{key_id}:{application_key}");
|
||||
let formatted_key = format!("Basic {}", base64::encode(combined_key));
|
||||
|
||||
let response = reqwest::Client::new()
|
||||
|
||||
@@ -69,7 +69,7 @@ impl FileHost for S3Host {
|
||||
|
||||
self.bucket
|
||||
.put_object_with_content_type(
|
||||
format!("/{}", file_name),
|
||||
format!("/{file_name}"),
|
||||
&file_bytes,
|
||||
content_type,
|
||||
)
|
||||
@@ -98,7 +98,7 @@ impl FileHost for S3Host {
|
||||
file_name: &str,
|
||||
) -> Result<DeleteFileData, FileHostingError> {
|
||||
self.bucket
|
||||
.delete_object(format!("/{}", file_name))
|
||||
.delete_object(format!("/{file_name}"))
|
||||
.await
|
||||
.map_err(|_| {
|
||||
FileHostingError::S3Error(
|
||||
|
||||
@@ -43,7 +43,13 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
// DSN is from SENTRY_DSN env variable.
|
||||
// Has no effect if not set.
|
||||
let sentry = sentry::init(());
|
||||
let sentry = sentry::init(sentry::ClientOptions {
|
||||
release: sentry::release_name!(),
|
||||
traces_sample_rate: 0.1,
|
||||
enable_profiling: true,
|
||||
profiles_sample_rate: 0.1,
|
||||
..Default::default()
|
||||
});
|
||||
if sentry.is_enabled() {
|
||||
info!("Enabled Sentry integration");
|
||||
std::env::set_var("RUST_BACKTRACE", "1");
|
||||
|
||||
@@ -14,8 +14,11 @@ use std::sync::Arc;
|
||||
#[derive(Deserialize)]
|
||||
pub struct DownloadBody {
|
||||
pub url: String,
|
||||
pub hash: ProjectId,
|
||||
pub project_id: ProjectId,
|
||||
pub version_name: String,
|
||||
|
||||
pub ip: String,
|
||||
pub headers: HashMap<String, String>,
|
||||
}
|
||||
|
||||
// This is an internal route, cannot be used without key
|
||||
@@ -26,7 +29,7 @@ pub async fn count_download(
|
||||
download_queue: web::Data<Arc<DownloadQueue>>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let project_id: crate::database::models::ids::ProjectId =
|
||||
download_body.hash.into();
|
||||
download_body.project_id.into();
|
||||
|
||||
let id_option = crate::models::ids::base62_impl::parse_base62(
|
||||
&download_body.version_name,
|
||||
@@ -81,8 +84,11 @@ pub async fn count_download(
|
||||
.post(format!("{}downloads", dotenvy::var("ARIADNE_URL")?))
|
||||
.header("Modrinth-Admin", dotenvy::var("ARIADNE_ADMIN_KEY")?)
|
||||
.json(&json!({
|
||||
"ip": download_body.ip,
|
||||
"url": download_body.url,
|
||||
"project_id": download_body.hash
|
||||
"project_id": download_body.project_id,
|
||||
"version_id": crate::models::projects::VersionId(version_id as u64).to_string(),
|
||||
"headers": download_body.headers
|
||||
}))
|
||||
.send()
|
||||
.await
|
||||
|
||||
@@ -115,7 +115,7 @@ pub async fn maven_metadata(
|
||||
|
||||
let respdata = Metadata {
|
||||
group_id: "maven.modrinth".to_string(),
|
||||
artifact_id: format!("{}", project_id),
|
||||
artifact_id: project_id.to_string(),
|
||||
versioning: Versioning {
|
||||
latest: new_versions
|
||||
.last()
|
||||
|
||||
@@ -163,7 +163,7 @@ pub async fn handle_stripe_webhook(
|
||||
)
|
||||
})?;
|
||||
|
||||
key.update(format!("{}.{}", timestamp, body).as_bytes());
|
||||
key.update(format!("{timestamp}.{body}").as_bytes());
|
||||
|
||||
key.verify(&signature).map_err(|_| {
|
||||
ApiError::Crypto(
|
||||
|
||||
@@ -545,8 +545,7 @@ pub async fn project_create_inner(
|
||||
})?;
|
||||
|
||||
let url = format!(
|
||||
"data/{}/images/{}.{}",
|
||||
project_id, hash, file_extension
|
||||
"data/{project_id}/images/{hash}.{file_extension}"
|
||||
);
|
||||
let upload_data = file_host
|
||||
.upload_file(content_type, &url, data.freeze())
|
||||
@@ -558,7 +557,7 @@ pub async fn project_create_inner(
|
||||
});
|
||||
|
||||
gallery_urls.push(crate::models::projects::GalleryItem {
|
||||
url: format!("{}/{}", cdn_url, url),
|
||||
url: format!("{cdn_url}/{url}"),
|
||||
featured: item.featured,
|
||||
title: item.title.clone(),
|
||||
description: item.description.clone(),
|
||||
@@ -574,8 +573,7 @@ pub async fn project_create_inner(
|
||||
*i
|
||||
} else {
|
||||
return Err(CreateError::InvalidInput(format!(
|
||||
"File `{}` (field {}) isn't specified in the versions data",
|
||||
file_name, name
|
||||
"File `{file_name}` (field {name}) isn't specified in the versions data"
|
||||
)));
|
||||
};
|
||||
|
||||
@@ -720,8 +718,7 @@ pub async fn project_create_inner(
|
||||
)
|
||||
.map_err(|err| {
|
||||
CreateError::InvalidInput(format!(
|
||||
"Invalid SPDX license identifier: {}",
|
||||
err
|
||||
"Invalid SPDX license identifier: {err}"
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -960,7 +957,7 @@ async fn process_icon_upload(
|
||||
let upload_data = file_host
|
||||
.upload_file(
|
||||
content_type,
|
||||
&format!("data/{}/{}.{}", project_id, hash, file_extension),
|
||||
&format!("data/{project_id}/{hash}.{file_extension}"),
|
||||
data.freeze(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::database;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models;
|
||||
use crate::models::ids::base62_impl::parse_base62;
|
||||
use crate::models::projects::{
|
||||
DonationLink, Project, ProjectId, ProjectStatus, SearchRequest, SideType,
|
||||
};
|
||||
@@ -873,16 +874,14 @@ pub async fn project_edit(
|
||||
));
|
||||
}
|
||||
|
||||
let slug_project_id_option: Option<ProjectId> =
|
||||
serde_json::from_str(&format!("\"{}\"", slug)).ok();
|
||||
let slug_project_id_option: Option<u64> =
|
||||
parse_base62(slug).ok();
|
||||
if let Some(slug_project_id) = slug_project_id_option {
|
||||
let slug_project_id: database::models::ids::ProjectId =
|
||||
slug_project_id.into();
|
||||
let results = sqlx::query!(
|
||||
"
|
||||
SELECT EXISTS(SELECT 1 FROM mods WHERE id=$1)
|
||||
",
|
||||
slug_project_id as database::models::ids::ProjectId
|
||||
SELECT EXISTS(SELECT 1 FROM mods WHERE id=$1)
|
||||
",
|
||||
slug_project_id as i64
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?;
|
||||
@@ -980,8 +979,7 @@ pub async fn project_edit(
|
||||
|
||||
spdx::Expression::parse(&license).map_err(|err| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Invalid SPDX license identifier: {}",
|
||||
err
|
||||
"Invalid SPDX license identifier: {err}"
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -1846,7 +1844,7 @@ pub async fn add_gallery_item(
|
||||
let id: ProjectId = project_item.inner.id.into();
|
||||
let url = format!("data/{}/images/{}.{}", id, hash, &*ext.ext);
|
||||
|
||||
let file_url = format!("{}/{}", cdn_url, url);
|
||||
let file_url = format!("{cdn_url}/{url}");
|
||||
if project_item
|
||||
.gallery_items
|
||||
.iter()
|
||||
@@ -2359,7 +2357,7 @@ pub async fn delete_from_index(
|
||||
let indexes: Vec<meilisearch_sdk::indexes::Index> =
|
||||
client.get_indexes().await?;
|
||||
for index in indexes {
|
||||
index.delete_document(format!("{}", id)).await?;
|
||||
index.delete_document(id.to_string()).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -345,16 +345,13 @@ pub async fn add_team_member(
|
||||
actions: vec![
|
||||
NotificationActionBuilder {
|
||||
title: "Accept".to_string(),
|
||||
action_route: (
|
||||
"POST".to_string(),
|
||||
format!("team/{}/join", team),
|
||||
),
|
||||
action_route: ("POST".to_string(), format!("team/{team}/join")),
|
||||
},
|
||||
NotificationActionBuilder {
|
||||
title: "Deny".to_string(),
|
||||
action_route: (
|
||||
"DELETE".to_string(),
|
||||
format!("team/{}/members/{}", team, new_member.user_id),
|
||||
format!("team/{team}/members/{}", new_member.user_id),
|
||||
),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -61,7 +61,7 @@ pub async fn user_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
let id_option: Option<UserId> =
|
||||
serde_json::from_str(&format!("\"{}\"", string)).ok();
|
||||
serde_json::from_str(&format!("\"{string}\"")).ok();
|
||||
|
||||
let mut user_data;
|
||||
|
||||
@@ -222,8 +222,7 @@ pub async fn user_edit(
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"Username {} is taken!",
|
||||
username
|
||||
"Username {username} is taken!"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ pub async fn mod_get(
|
||||
database::models::Project::get_full_from_slug_or_project_id(
|
||||
&string, &**pool,
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
let user_option = get_user_from_headers(req.headers(), &**pool).await.ok();
|
||||
|
||||
@@ -109,7 +109,9 @@ pub async fn mod_get(
|
||||
format!("[STOP USING API v1] {}", data.inner.description);
|
||||
data.inner.body =
|
||||
format!("# STOP USING API v1 - whatever application you're using right now is likely deprecated or abandoned\n{}", data.inner.body);
|
||||
return Ok(HttpResponse::Ok().json(models::projects::Project::from(data)));
|
||||
return Ok(
|
||||
HttpResponse::Ok().json(models::projects::Project::from(data))
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(HttpResponse::NotFound().body(""))
|
||||
|
||||
@@ -875,7 +875,7 @@ pub async fn upload_file(
|
||||
|
||||
version_files.push(VersionFileBuilder {
|
||||
filename: file_name.to_string(),
|
||||
url: format!("{}/{}", cdn_url, file_path_encode),
|
||||
url: format!("{cdn_url}/{file_path_encode}"),
|
||||
hashes: vec![
|
||||
models::version_item::HashBuilder {
|
||||
algorithm: "sha1".to_string(),
|
||||
|
||||
@@ -537,8 +537,7 @@ pub async fn update_files(
|
||||
version.inner.id.into();
|
||||
|
||||
return Err(ApiError::Database(DatabaseError::Other(format!(
|
||||
"Could not parse hash for version {}",
|
||||
version_id
|
||||
"Could not parse hash for version {version_id}"
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ pub async fn search_for_project(
|
||||
|
||||
let filters: Cow<_> =
|
||||
match (info.filters.as_deref(), info.version.as_deref()) {
|
||||
(Some(f), Some(v)) => format!("({}) AND ({})", f, v).into(),
|
||||
(Some(f), Some(v)) => format!("({f}) AND ({v})").into(),
|
||||
(Some(f), None) => f.into(),
|
||||
(None, Some(v)) => v.into(),
|
||||
(None, None) => "".into(),
|
||||
@@ -224,7 +224,7 @@ pub async fn search_for_project(
|
||||
filter_string.push(')');
|
||||
|
||||
if !filters.is_empty() {
|
||||
write!(filter_string, " AND ({})", filters)?;
|
||||
write!(filter_string, " AND ({filters})")?;
|
||||
}
|
||||
} else {
|
||||
filter_string.push_str(&filters);
|
||||
|
||||
@@ -40,7 +40,7 @@ pub async fn get_github_user_from_token(
|
||||
.header(reqwest::header::USER_AGENT, "Modrinth")
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
format!("token {}", access_token),
|
||||
format!("token {access_token}"),
|
||||
)
|
||||
.send()
|
||||
.await?
|
||||
|
||||
@@ -25,17 +25,14 @@ pub fn validation_errors_to_string(
|
||||
ValidationErrorsKind::Struct(errors) => {
|
||||
validation_errors_to_string(
|
||||
*errors.clone(),
|
||||
Some(format!("of item {}", field)),
|
||||
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(),
|
||||
Some(format!(
|
||||
"of list {} with index {}",
|
||||
field, index
|
||||
)),
|
||||
Some(format!("of list {field} with index {index}")),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -149,8 +149,7 @@ pub async fn validate_file(
|
||||
if visited {
|
||||
Err(ValidationError::InvalidInput(
|
||||
format!(
|
||||
"File extension {} is invalid for input file",
|
||||
file_extension
|
||||
"File extension {file_extension} is invalid for input file"
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user