You've already forked AstralRinth
forked from didirus/AstralRinth
Upgrade to Actix V2, bump SQLX version, code cleanup, intergrate ratelimiter (#288)
* Upgrade to Actix V2, bump SQLX version, code cleanup, intergrate ratelimiter * Add pack file path validation * Fix compilation error caused by incorrect merge
This commit is contained in:
@@ -117,7 +117,7 @@ pub async fn init(
|
||||
);
|
||||
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
.header("Location", &*url)
|
||||
.append_header(("Location", &*url))
|
||||
.json(AuthorizationInit { url }))
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ pub async fn auth_callback(
|
||||
};
|
||||
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
.header("Location", &*redirect_url)
|
||||
.append_header(("Location", &*redirect_url))
|
||||
.json(AuthorizationInit { url: redirect_url }))
|
||||
} else {
|
||||
Err(AuthorizationError::InvalidCredentialsError)
|
||||
|
||||
@@ -53,11 +53,12 @@ pub struct MavenPom {
|
||||
#[get("maven/modrinth/{id}/maven-metadata.xml")]
|
||||
pub async fn maven_metadata(
|
||||
req: HttpRequest,
|
||||
web::Path((project_id,)): web::Path<(String,)>,
|
||||
params: web::Path<(String,)>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let project_id = params.into_inner().0;
|
||||
let project_data =
|
||||
database::models::Project::get_full_from_slug_or_project_id(&project_id, &**pool).await?;
|
||||
database::models::Project::get_full_from_slug_or_project_id(&*project_id, &**pool).await?;
|
||||
|
||||
let data = if let Some(data) = project_data {
|
||||
data
|
||||
@@ -142,9 +143,10 @@ fn find_file<'a>(
|
||||
#[get("maven/modrinth/{id}/{versionnum}/{file}")]
|
||||
pub async fn version_file(
|
||||
req: HttpRequest,
|
||||
web::Path((project_id, vnum, file)): web::Path<(String, String, String)>,
|
||||
params: web::Path<(String, String, String)>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let (project_id, vnum, file) = params.into_inner();
|
||||
let project_data =
|
||||
database::models::Project::get_full_from_slug_or_project_id(&project_id, &**pool).await?;
|
||||
|
||||
@@ -200,7 +202,7 @@ pub async fn version_file(
|
||||
.body(yaserde::ser::to_string(&respdata).map_err(ApiError::XmlError)?));
|
||||
} else if let Some(selected_file) = find_file(&project_id, &project, &version, &file) {
|
||||
return Ok(HttpResponse::TemporaryRedirect()
|
||||
.header("location", &*selected_file.url)
|
||||
.append_header(("location", &*selected_file.url))
|
||||
.body(""));
|
||||
}
|
||||
|
||||
@@ -210,9 +212,10 @@ pub async fn version_file(
|
||||
#[get("maven/modrinth/{id}/{versionnum}/{file}.sha1")]
|
||||
pub async fn version_file_sha1(
|
||||
req: HttpRequest,
|
||||
web::Path((project_id, vnum, file)): web::Path<(String, String, String)>,
|
||||
params: web::Path<(String, String, String)>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let (project_id, vnum, file) = params.into_inner();
|
||||
let project_data =
|
||||
database::models::Project::get_full_from_slug_or_project_id(&project_id, &**pool).await?;
|
||||
|
||||
@@ -260,9 +263,10 @@ pub async fn version_file_sha1(
|
||||
#[get("maven/modrinth/{id}/{versionnum}/{file}.sha512")]
|
||||
pub async fn version_file_sha512(
|
||||
req: HttpRequest,
|
||||
web::Path((project_id, vnum, file)): web::Path<(String, String, String)>,
|
||||
params: web::Path<(String, String, String)>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let (project_id, vnum, file) = params.into_inner();
|
||||
let project_data =
|
||||
database::models::Project::get_full_from_slug_or_project_id(&project_id, &**pool).await?;
|
||||
|
||||
|
||||
@@ -323,9 +323,7 @@ pub async fn project_create_inner(
|
||||
)))
|
||||
})?;
|
||||
|
||||
let content_disposition = field.content_disposition().ok_or_else(|| {
|
||||
CreateError::MissingValueError(String::from("Missing content disposition"))
|
||||
})?;
|
||||
let content_disposition = field.content_disposition();
|
||||
let name = content_disposition
|
||||
.get_name()
|
||||
.ok_or_else(|| CreateError::MissingValueError(String::from("Missing content name")))?;
|
||||
@@ -409,9 +407,7 @@ pub async fn project_create_inner(
|
||||
|
||||
while let Some(item) = payload.next().await {
|
||||
let mut field: Field = item.map_err(CreateError::MultipartError)?;
|
||||
let content_disposition = field.content_disposition().ok_or_else(|| {
|
||||
CreateError::MissingValueError("Missing content disposition".to_string())
|
||||
})?;
|
||||
let content_disposition = field.content_disposition().clone();
|
||||
|
||||
let name = content_disposition
|
||||
.get_name()
|
||||
|
||||
@@ -254,7 +254,7 @@ pub async fn download_version(
|
||||
|
||||
if let Some(id) = result {
|
||||
let real_ip = req.connection_info();
|
||||
let ip_option = real_ip.borrow().remote_addr();
|
||||
let ip_option = real_ip.borrow().peer_addr();
|
||||
|
||||
if let Some(ip) = ip_option {
|
||||
let hash = sha1::Sha1::from(format!("{}{}", ip, pepper.pepper)).hexdigest();
|
||||
@@ -312,7 +312,7 @@ pub async fn download_version(
|
||||
}
|
||||
}
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
.header("Location", &*id.url)
|
||||
.append_header(("Location", &*id.url))
|
||||
.json(DownloadRedirect { url: id.url }))
|
||||
} else {
|
||||
Ok(HttpResponse::NotFound().body(""))
|
||||
|
||||
@@ -106,9 +106,7 @@ async fn version_create_inner(
|
||||
|
||||
while let Some(item) = payload.next().await {
|
||||
let mut field: Field = item.map_err(CreateError::MultipartError)?;
|
||||
let content_disposition = field.content_disposition().ok_or_else(|| {
|
||||
CreateError::MissingValueError("Missing content disposition".to_string())
|
||||
})?;
|
||||
let content_disposition = field.content_disposition().clone();
|
||||
let name = content_disposition
|
||||
.get_name()
|
||||
.ok_or_else(|| CreateError::MissingValueError("Missing content name".to_string()))?;
|
||||
@@ -511,9 +509,7 @@ async fn upload_file_to_version_inner(
|
||||
|
||||
while let Some(item) = payload.next().await {
|
||||
let mut field: Field = item.map_err(CreateError::MultipartError)?;
|
||||
let content_disposition = field.content_disposition().ok_or_else(|| {
|
||||
CreateError::MissingValueError("Missing content disposition".to_string())
|
||||
})?;
|
||||
let content_disposition = field.content_disposition().clone();
|
||||
let name = content_disposition
|
||||
.get_name()
|
||||
.ok_or_else(|| CreateError::MissingValueError("Missing content name".to_string()))?;
|
||||
|
||||
@@ -105,7 +105,7 @@ pub async fn download_version(
|
||||
transaction.commit().await?;
|
||||
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
.header("Location", &*id.url)
|
||||
.append_header(("Location", &*id.url))
|
||||
.json(DownloadRedirect { url: id.url }))
|
||||
} else {
|
||||
Ok(HttpResponse::NotFound().body(""))
|
||||
@@ -128,10 +128,10 @@ async fn download_version_inner(
|
||||
if let Some(header) = req.headers().get("CF-Connecting-IP") {
|
||||
header.to_str().ok()
|
||||
} else {
|
||||
real_ip.borrow().remote_addr()
|
||||
real_ip.borrow().peer_addr()
|
||||
}
|
||||
} else {
|
||||
real_ip.borrow().remote_addr()
|
||||
real_ip.borrow().peer_addr()
|
||||
};
|
||||
|
||||
if let Some(ip) = ip_option {
|
||||
|
||||
Reference in New Issue
Block a user