You've already forked AstralRinth
forked from didirus/AstralRinth
* Initial work for modpacks and project types * Code cleanup, fix some issues * Username route getting, remove pointless tests * Base validator types + fixes * Fix strange IML generation * Multiple hash requests for version files * Fix docker build (hopefully) * Legacy routes * Finish validator architecture * Update rust version in dockerfile * Added caching and fixed typo (#203) * Added caching and fixed typo * Fixed clippy error * Removed log for cache * Add final validators, fix how loaders are handled and add icons to tags * Fix search module * Fix parts of legacy API not working Co-authored-by: Redblueflame <contact@redblueflame.com>
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use crate::auth::check_is_moderator_from_headers;
|
|
use crate::database;
|
|
use crate::models::projects::{Project, ProjectStatus};
|
|
use crate::routes::moderation::ResultCount;
|
|
use crate::routes::ApiError;
|
|
use actix_web::web;
|
|
use actix_web::{get, HttpRequest, HttpResponse};
|
|
use sqlx::PgPool;
|
|
|
|
#[get("mods")]
|
|
pub async fn get_mods(
|
|
req: HttpRequest,
|
|
pool: web::Data<PgPool>,
|
|
count: web::Query<ResultCount>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
check_is_moderator_from_headers(req.headers(), &**pool).await?;
|
|
|
|
use futures::stream::TryStreamExt;
|
|
|
|
let project_ids = sqlx::query!(
|
|
"
|
|
SELECT id FROM mods
|
|
WHERE status = (
|
|
SELECT id FROM statuses WHERE status = $1
|
|
)
|
|
ORDER BY updated ASC
|
|
LIMIT $2;
|
|
",
|
|
ProjectStatus::Processing.as_str(),
|
|
count.count as i64
|
|
)
|
|
.fetch_many(&**pool)
|
|
.try_filter_map(|e| async { Ok(e.right().map(|m| database::models::ProjectId(m.id))) })
|
|
.try_collect::<Vec<database::models::ProjectId>>()
|
|
.await?;
|
|
|
|
let projects: Vec<Project> = database::Project::get_many_full(project_ids, &**pool)
|
|
.await?
|
|
.into_iter()
|
|
.map(crate::routes::projects::convert_project)
|
|
.collect();
|
|
|
|
Ok(HttpResponse::Ok().json(projects))
|
|
}
|