You've already forked AstralRinth
forked from didirus/AstralRinth
Urgent fixes
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use crate::models::ids::ProjectId;
|
||||
use crate::routes::ApiError;
|
||||
use crate::util::guards::admin_key_guard;
|
||||
use actix_web::{patch, web, HttpResponse};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use crate::models::ids::ProjectId;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DownloadBody {
|
||||
@@ -18,17 +18,19 @@ pub async fn count_download(
|
||||
pool: web::Data<PgPool>,
|
||||
download_body: web::Json<DownloadBody>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let project_id : crate::database::models::ids::ProjectId = download_body.hash.into();
|
||||
let project_id: crate::database::models::ids::ProjectId =
|
||||
download_body.hash.into();
|
||||
|
||||
let version_id = if let Some(version) = sqlx::query!(
|
||||
"SELECT id FROM versions
|
||||
let (version_id, project_id) = if let Some(version) = sqlx::query!(
|
||||
"SELECT id, mod_id FROM versions
|
||||
WHERE (version_number = $1 AND mod_id = $2)",
|
||||
download_body.version_name,
|
||||
project_id as crate::database::models::ids::ProjectId
|
||||
project_id as crate::database::models::ids::ProjectId
|
||||
)
|
||||
.fetch_optional(pool.as_ref())
|
||||
.await? {
|
||||
version.id
|
||||
.fetch_optional(pool.as_ref())
|
||||
.await?
|
||||
{
|
||||
(version.id, version.mod_id)
|
||||
} else if let Some(version) = sqlx::query!(
|
||||
"
|
||||
SELECT v.id id, v.mod_id project_id FROM files f
|
||||
@@ -37,11 +39,14 @@ pub async fn count_download(
|
||||
",
|
||||
download_body.url,
|
||||
)
|
||||
.fetch_optional(pool.as_ref())
|
||||
.await? {
|
||||
version.id
|
||||
.fetch_optional(pool.as_ref())
|
||||
.await?
|
||||
{
|
||||
(version.id, version.project_id)
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput("Specified version does not exist!".to_string()));
|
||||
return Err(ApiError::InvalidInput(
|
||||
"Specified version does not exist!".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
@@ -59,7 +64,7 @@ pub async fn count_download(
|
||||
"UPDATE mods
|
||||
SET downloads = downloads + 1
|
||||
WHERE (id = $1)",
|
||||
version_id
|
||||
project_id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
@@ -145,12 +145,13 @@ pub async fn auth_callback(
|
||||
.await?;
|
||||
|
||||
if let Some(result) = result_option {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let duration = now - result.expires;
|
||||
|
||||
if duration.whole_seconds() < 0 {
|
||||
return Err(AuthorizationError::InvalidCredentials);
|
||||
}
|
||||
// let now = OffsetDateTime::now_utc();
|
||||
// TODO: redo this condition later..
|
||||
// let duration = now - result.expires;
|
||||
//
|
||||
// if duration.whole_seconds() < 0 {
|
||||
// return Err(AuthorizationError::InvalidCredentials);
|
||||
// }
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
|
||||
@@ -445,14 +445,14 @@ pub async fn project_edit(
|
||||
} else if !project_item.status.is_searchable()
|
||||
&& status.is_searchable()
|
||||
{
|
||||
let index_project =
|
||||
crate::search::indexing::local_import::query_one(
|
||||
id,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
indexing_queue.add(index_project);
|
||||
// let index_project =
|
||||
// crate::search::indexing::local_import::query_one(
|
||||
// id,
|
||||
// &mut *transaction,
|
||||
// )
|
||||
// .await?;
|
||||
//
|
||||
// indexing_queue.add(index_project);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user