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:
@@ -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}"
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user