diff --git a/sqlx-data.json b/sqlx-data.json index 4eacd559..19de3559 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -731,6 +731,38 @@ "nullable": [] } }, + "298dd4ca44f2f154897ac7e1dca5a4c8f0528805fb10aae991e20b7daf6b3093": { + "query": "\n SELECT d.dependency_id, vd.mod_id, d.mod_dependency_id\n FROM versions v\n INNER JOIN dependencies d ON d.dependent_id = v.id\n INNER JOIN versions vd ON d.dependency_id = vd.id\n WHERE v.mod_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "dependency_id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "mod_id", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "mod_dependency_id", + "type_info": "Int8" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + true, + false, + true + ] + } + }, "29e657d26f0fb24a766f5b5eb6a94d01d1616884d8ca10e91536e974d5b585a6": { "query": "\n INSERT INTO loaders_versions (loader_id, version_id)\n VALUES ($1, $2)\n ", "describe": { @@ -2392,32 +2424,6 @@ ] } }, - "7eab623af88469235cad7cdf0b37bdf51eade3f5e1de25c63a8e08e55722003f": { - "query": "\n SELECT d.dependency_id, vd.mod_id\n FROM versions v\n INNER JOIN dependencies d ON d.dependent_id = v.id\n INNER JOIN versions vd ON d.dependency_id = vd.id\n WHERE v.mod_id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "dependency_id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "mod_id", - "type_info": "Int8" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - true, - false - ] - } - }, "8129255d25bf0624d83f50558b668ed7b7f9c264e380d276522fc82bc871939b": { "query": "\n INSERT INTO notifications_actions (\n notification_id, title, action_route, action_route_method\n )\n VALUES (\n $1, $2, $3, $4\n )\n ", "describe": { diff --git a/src/routes/projects.rs b/src/routes/projects.rs index 69db51e1..24d867b4 100644 --- a/src/routes/projects.rs +++ b/src/routes/projects.rs @@ -112,7 +112,7 @@ pub async fn dependency_list( let dependencies = sqlx::query!( " - SELECT d.dependency_id, vd.mod_id + SELECT d.dependency_id, vd.mod_id, d.mod_dependency_id FROM versions v INNER JOIN dependencies d ON d.dependent_id = v.id INNER JOIN versions vd ON d.dependency_id = vd.id @@ -126,18 +126,31 @@ pub async fn dependency_list( ( x.dependency_id.map(database::models::VersionId), database::models::ProjectId(x.mod_id), + x.mod_dependency_id.map(database::models::ProjectId), ) })) }) .try_collect::, database::models::ProjectId, + Option, )>>() .await?; let (projects_result, versions_result) = futures::join!( database::Project::get_many_full( - dependencies.iter().map(|x| x.1).collect(), + dependencies + .iter() + .map(|x| if x.0.is_none() { + if let Some(mod_dependency_id) = x.2 { + mod_dependency_id + } else { + x.1 + } + } else { + x.1 + }) + .collect(), &**pool, ), database::Version::get_many_full( @@ -146,15 +159,21 @@ pub async fn dependency_list( ) ); - let projects = projects_result? + let mut projects = projects_result? .into_iter() .map(models::projects::Project::from) .collect::>(); - let versions = versions_result? + let mut versions = versions_result? .into_iter() .map(models::projects::Version::from) .collect::>(); + projects.sort_by(|a, b| b.published.cmp(&a.published)); + projects.dedup_by(|a, b| a.id == b.id); + + versions.sort_by(|a, b| b.date_published.cmp(&a.date_published)); + versions.dedup_by(|a, b| a.id == b.id); + Ok(HttpResponse::Ok().json(DependencyInfo { projects, versions })) } else { Ok(HttpResponse::NotFound().body("")) diff --git a/src/routes/version_creation.rs b/src/routes/version_creation.rs index b9a29ecd..6d30b3c0 100644 --- a/src/routes/version_creation.rs +++ b/src/routes/version_creation.rs @@ -675,30 +675,29 @@ pub async fn upload_file( ) .await?; - let file_name_encode = format!( + let file_path_encode = format!( "data/{}/versions/{}/{}", project_id, version_number, urlencoding::encode(file_name) ); - let file_name = format!( + let file_path = format!( "data/{}/versions/{}/{}", project_id, version_number, &file_name ); let upload_data = file_host - .upload_file(content_type, &file_name, data.freeze()) + .upload_file(content_type, &file_path, data.freeze()) .await?; uploaded_files.push(UploadedFile { file_id: upload_data.file_id, - file_name: file_name_encode, + file_name: file_path, }); - // TODO: Malware scan + file validation version_files.push(models::version_item::VersionFileBuilder { filename: file_name.to_string(), - url: format!("{}/{}", cdn_url, upload_data.file_name), + url: format!("{}/{}", cdn_url, file_path_encode), hashes: vec![ models::version_item::HashBuilder { algorithm: "sha1".to_string(), diff --git a/src/util/webhook.rs b/src/util/webhook.rs index f85e311e..343f6c3c 100644 --- a/src/util/webhook.rs +++ b/src/util/webhook.rs @@ -72,8 +72,9 @@ pub async fn send_discord_webhook( let embed = DiscordEmbed { url: format!( - "{}/mod/{}", + "{}/{}/{}", dotenv::var("SITE_URL").unwrap_or_default(), + project.project_type, project .clone() .slug @@ -82,7 +83,7 @@ pub async fn send_discord_webhook( title: project.title, description: project.description, timestamp: project.published, - color: 0x5DA545, + color: 0x1bd96a, fields, image: DiscordEmbedImage { url: project.icon_url,