Skip to content

Commit

Permalink
Fix deps, download URLs, remove duplicate deps (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Feb 27, 2022
1 parent b7c7c0e commit 725f857
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 124 deletions.
65 changes: 25 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ path = "src/main.rs"

[dependencies]
actix = "0.12.0"
actix-web = "4.0.0-rc.2"
actix-web = "4.0.0"
actix-rt = "2.6.0"
tokio-stream = "0.1.8"
actix-multipart = "0.4.0-beta.13"
actix-cors = "0.6.0-beta.8"
actix-multipart = "0.4.0"
actix-cors = "0.6.0"

meilisearch-sdk = "0.6.0"
reqwest = { version = "0.11.9", features = ["json"] }
Expand All @@ -36,6 +36,7 @@ sha1 = { version = "0.6.0", features = ["std"] }
sha2 = "0.9.2"
bitflags = "1.2.1"
zip = "0.5.12"
itertools = "0.10.3"

validator = { version = "0.13", features = ["derive"] }
regex = "1.5.4"
Expand All @@ -59,4 +60,4 @@ sqlx = { version = "0.5.10", features = ["runtime-actix-rustls", "postgres", "ch
bytes = "1.1.0"

dashmap = "4.0.2"
hex = "0.4.3"
hex = "0.4.3"
42 changes: 21 additions & 21 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,27 +639,6 @@
"nullable": []
}
},
"22f3f089050594199c3a3265da8ca68264a7457ae6ec4aef3644035a2022a830": {
"query": "\n SELECT version.id id FROM (\n SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v\n INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id IN (SELECT game_version_id FROM game_versions_versions WHERE joining_version_id = $2)\n INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id IN (SELECT loader_id FROM loaders_versions WHERE version_id = $2)\n WHERE v.mod_id = $1\n ) AS version\n ORDER BY version.date_published DESC\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false
]
}
},
"232d7d0319c20dd5fff29331b067d6c6373bcff761a77958a2bb5f59068a83a5": {
"query": "\n UPDATE team_members\n SET permissions = $1\n WHERE (team_id = $2 AND user_id = $3)\n ",
"describe": {
Expand Down Expand Up @@ -1941,6 +1920,27 @@
"nullable": []
}
},
"62416ea5972daa46ff2d077f631a8a30d9ec922056cf7ff1b0d74d9511010c96": {
"query": "\n SELECT version.id id FROM (\n SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v\n INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id IN (SELECT game_version_id FROM game_versions_versions WHERE joining_version_id = $2)\n INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id IN (SELECT loader_id FROM loaders_versions WHERE version_id = $2)\n WHERE v.mod_id = $1\n ) AS version\n ORDER BY version.date_published DESC\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false
]
}
},
"6326543f7cbd0ce03bbfe234ee82ca1b61d411589dc2d61753598679942cfdd8": {
"query": "\n SELECT md.url url, dp.id platform_id, dp.name dp_name, dp.short short\n FROM mods_donations md\n INNER JOIN donation_platforms dp ON md.joining_platform_id = dp.id\n WHERE md.joining_mod_id = $1\n ",
"describe": {
Expand Down
45 changes: 25 additions & 20 deletions src/database/models/version_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ impl DependencyBuilder {
version_id: VersionId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), DatabaseError> {
let version_dependency_id = if let Some(project_id) = self.project_id {
sqlx::query!(
"
SELECT version.id id FROM (
SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id IN (SELECT game_version_id FROM game_versions_versions WHERE joining_version_id = $2)
INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id IN (SELECT loader_id FROM loaders_versions WHERE version_id = $2)
WHERE v.mod_id = $1
) AS version
ORDER BY version.date_published DESC
LIMIT 1
",
project_id as ProjectId,
version_id as VersionId,
)
.fetch_optional(&mut *transaction).await?.map(|x| VersionId(x.id))
} else {
self.version_id
};
let (version_dependency_id, project_dependency_id): (Option<VersionId>, Option<ProjectId>) =
if self.version_id.is_some() {
(self.version_id, None)
} else if let Some(project_id) = self.project_id {
let version_id = sqlx::query!(
"
SELECT version.id id FROM (
SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id IN (SELECT game_version_id FROM game_versions_versions WHERE joining_version_id = $2)
INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id IN (SELECT loader_id FROM loaders_versions WHERE version_id = $2)
WHERE v.mod_id = $1
) AS version
ORDER BY version.date_published DESC
LIMIT 1
",
project_id as ProjectId,
version_id as VersionId,
)
.fetch_optional(&mut *transaction).await?.map(|x| VersionId(x.id));

(version_id, Some(project_id))
} else {
(None, None)
};

sqlx::query!(
"
Expand All @@ -57,7 +62,7 @@ impl DependencyBuilder {
version_id as VersionId,
self.dependency_type,
version_dependency_id.map(|x| x.0),
self.project_id.map(|x| x.0),
project_dependency_id.map(|x| x.0),
)
.execute(&mut *transaction)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions src/ratelimit/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ pub enum ARError {
}

impl ResponseError for ARError {
fn error_response(&self) -> actix_web::web::HttpResponse {
fn error_response(&self) -> actix_web::HttpResponse {
match self {
Self::LimitedError {
max_requests,
remaining,
reset,
} => {
let mut response = actix_web::web::HttpResponse::TooManyRequests();
let mut response = actix_web::HttpResponse::TooManyRequests();
response.insert_header(("x-ratelimit-limit", max_requests.to_string()));
response.insert_header(("x-ratelimit-remaining", remaining.to_string()));
response.insert_header(("x-ratelimit-reset", reset.to_string()));
response.body(self.to_string())
}
_ => actix_web::web::HttpResponse::build(self.status_code()).body(self.to_string()),
_ => actix_web::HttpResponse::build(self.status_code()).body(self.to_string()),
}
}
}
36 changes: 17 additions & 19 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,23 @@ impl actix_web::ResponseError for ApiError {
}
}

fn error_response(&self) -> actix_web::web::HttpResponse {
actix_web::web::HttpResponse::build(self.status_code()).json(
crate::models::error::ApiError {
error: match self {
ApiError::EnvError(..) => "environment_error",
ApiError::SqlxDatabaseError(..) => "database_error",
ApiError::DatabaseError(..) => "database_error",
ApiError::AuthenticationError(..) => "unauthorized",
ApiError::CustomAuthenticationError(..) => "unauthorized",
ApiError::XmlError(..) => "xml_error",
ApiError::JsonError(..) => "json_error",
ApiError::SearchError(..) => "search_error",
ApiError::IndexingError(..) => "indexing_error",
ApiError::FileHostingError(..) => "file_hosting_error",
ApiError::InvalidInputError(..) => "invalid_input",
ApiError::ValidationError(..) => "invalid_input",
},
description: &self.to_string(),
fn error_response(&self) -> actix_web::HttpResponse {
actix_web::HttpResponse::build(self.status_code()).json(crate::models::error::ApiError {
error: match self {
ApiError::EnvError(..) => "environment_error",
ApiError::SqlxDatabaseError(..) => "database_error",
ApiError::DatabaseError(..) => "database_error",
ApiError::AuthenticationError(..) => "unauthorized",
ApiError::CustomAuthenticationError(..) => "unauthorized",
ApiError::XmlError(..) => "xml_error",
ApiError::JsonError(..) => "json_error",
ApiError::SearchError(..) => "search_error",
ApiError::IndexingError(..) => "indexing_error",
ApiError::FileHostingError(..) => "file_hosting_error",
ApiError::InvalidInputError(..) => "invalid_input",
ApiError::ValidationError(..) => "invalid_input",
},
)
description: &self.to_string(),
})
}
}
Loading

0 comments on commit 725f857

Please sign in to comment.