You've already forked pages
forked from didirus/AstralRinth
* chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix postgres version mismatch * fix version creation * Implement routes * fix up tech review * Allow adding a moderation comment to Delphi rejections * fix up rebase * exclude rejected projects from tech review * add status change msg to tech review thread * cargo sqlx prepare * also ignore withheld projects * More filtering on issue search * wip: report routes * Fix up for build * cargo sqlx prepare * fix thread message privacy * New tech review search route * submit route * details have statuses now * add default to drid status * dedup issue details * fix sqlx query on empty files * fixes * Dedupe issue detail statuses and message on entering tech rev * Fix qa issues * Fix qa issues * fix review comments * typos * fix ci * feat: tech review frontend (#4781) * chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix ci * fix postgres version mismatch * fix version creation * Implement routes * feat: batch scan alert * feat: layout * feat: introduce surface variables * fix: theme selector * feat: rough draft of tech review card * feat: tab switcher * feat: batch scan btn * feat: api-client module for tech review * draft: impl * feat: auto icons * fix: layout issues * feat: fixes to code blocks + flag labels * feat: temp remove mock data * fix: search sort types * fix: intl & lint * chore: re-enable mock data * fix: flag badges + auto open first issue in file tab * feat: update for new routes * fix: more qa issues * feat: lazy load sources * fix: re-enable auth middleware * feat: impl threads * fix: lint & severity * feat: download btn + switch to using NavTabs with new local mode option * feat: re-add toplevel btns * feat: reports page consistency * fix: consistency on project queue * fix: icons + sizing * fix: colors and gaps * fix: impl endpoints * feat: load all flags on file tab * feat: thread generics changes * feat: more qa * feat: fix collapse * fix: qa * feat: msg modal * fix: ISO import * feat: qa fixes * fix: empty state basic * fix: collapsible region * fix: collapse thread by default * feat: rough draft of new process/flow * fix labrinth build * fix thread message privacy * New tech review search route * feat: qa fixes * feat: QA changes * fix: verdict on detail not whole issue * fix: lint + intl * fix: lint * fix: thread message for tech rev verdict * feat: use anim frames * fix: exports + typecheck * polish: qa changes * feat: qa * feat: qa polish * feat: fix malic modal * fix: lint * fix: qa + lint * fix: pagination * fix: lint * fix: qa * intl extract * fix ci --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: aecsocket <aecsocket@tutanota.com> --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: Calum H. <contact@cal.engineer>
160 lines
4.7 KiB
Rust
160 lines
4.7 KiB
Rust
use crate::auth::validate::get_user_record_from_bearer_token;
|
|
use crate::database::redis::RedisPool;
|
|
use crate::models::analytics::Download;
|
|
use crate::models::ids::ProjectId;
|
|
use crate::models::pats::Scopes;
|
|
use crate::queue::analytics::AnalyticsQueue;
|
|
use crate::queue::session::AuthQueue;
|
|
use crate::routes::ApiError;
|
|
use crate::search::SearchConfig;
|
|
use crate::util::date::get_current_tenths_of_ms;
|
|
use crate::util::guards::admin_key_guard;
|
|
use actix_web::{HttpRequest, HttpResponse, patch, post, web};
|
|
use modrinth_maxmind::MaxMind;
|
|
use serde::Deserialize;
|
|
use sqlx::PgPool;
|
|
use std::collections::HashMap;
|
|
use std::net::Ipv4Addr;
|
|
use std::sync::Arc;
|
|
|
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(
|
|
web::scope("admin")
|
|
.service(count_download)
|
|
.service(force_reindex),
|
|
);
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct DownloadBody {
|
|
pub url: String,
|
|
pub project_id: ProjectId,
|
|
pub version_name: String,
|
|
|
|
pub ip: String,
|
|
pub headers: HashMap<String, String>,
|
|
}
|
|
|
|
// This is an internal route, cannot be used without key
|
|
#[patch("/_count-download", guard = "admin_key_guard")]
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn count_download(
|
|
req: HttpRequest,
|
|
pool: web::Data<PgPool>,
|
|
redis: web::Data<RedisPool>,
|
|
maxmind: web::Data<MaxMind>,
|
|
analytics_queue: web::Data<Arc<AnalyticsQueue>>,
|
|
session_queue: web::Data<AuthQueue>,
|
|
download_body: web::Json<DownloadBody>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
let token = download_body
|
|
.headers
|
|
.iter()
|
|
.find(|x| x.0.to_lowercase() == "authorization")
|
|
.map(|x| &**x.1);
|
|
|
|
let user = get_user_record_from_bearer_token(
|
|
&req,
|
|
token,
|
|
&**pool,
|
|
&redis,
|
|
&session_queue,
|
|
)
|
|
.await
|
|
.ok()
|
|
.flatten();
|
|
|
|
let project_id: crate::database::models::ids::DBProjectId =
|
|
download_body.project_id.into();
|
|
|
|
let id_option =
|
|
ariadne::ids::base62_impl::parse_base62(&download_body.version_name)
|
|
.ok()
|
|
.map(|x| x as i64);
|
|
|
|
let (version_id, project_id) = if let Some(version) = sqlx::query!(
|
|
"
|
|
SELECT v.id id, v.mod_id mod_id FROM files f
|
|
INNER JOIN versions v ON v.id = f.version_id
|
|
WHERE f.url = $1
|
|
",
|
|
download_body.url,
|
|
)
|
|
.fetch_optional(pool.as_ref())
|
|
.await?
|
|
{
|
|
(version.id, version.mod_id)
|
|
} else if let Some(version) = sqlx::query!(
|
|
"
|
|
SELECT id, mod_id FROM versions
|
|
WHERE ((version_number = $1 OR id = $3) AND mod_id = $2)
|
|
",
|
|
download_body.version_name,
|
|
project_id as crate::database::models::ids::DBProjectId,
|
|
id_option
|
|
)
|
|
.fetch_optional(pool.as_ref())
|
|
.await?
|
|
{
|
|
(version.id, version.mod_id)
|
|
} else {
|
|
return Err(ApiError::InvalidInput(
|
|
"Specified version does not exist!".to_string(),
|
|
));
|
|
};
|
|
|
|
let url = url::Url::parse(&download_body.url).map_err(|_| {
|
|
ApiError::InvalidInput("invalid download URL specified!".to_string())
|
|
})?;
|
|
|
|
let ip = crate::util::ip::convert_to_ip_v6(&download_body.ip)
|
|
.unwrap_or_else(|_| Ipv4Addr::new(127, 0, 0, 1).to_ipv6_mapped());
|
|
|
|
analytics_queue.add_download(Download {
|
|
recorded: get_current_tenths_of_ms(),
|
|
domain: url.host_str().unwrap_or_default().to_string(),
|
|
site_path: url.path().to_string(),
|
|
user_id: user
|
|
.and_then(|(scopes, x)| {
|
|
if scopes.contains(Scopes::PERFORM_ANALYTICS) {
|
|
Some(x.id.0 as u64)
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.unwrap_or(0),
|
|
project_id: project_id as u64,
|
|
version_id: version_id as u64,
|
|
ip,
|
|
country: maxmind.query_country(ip).await.unwrap_or_default(),
|
|
user_agent: download_body
|
|
.headers
|
|
.get("user-agent")
|
|
.cloned()
|
|
.unwrap_or_default(),
|
|
headers: download_body
|
|
.headers
|
|
.clone()
|
|
.into_iter()
|
|
.filter(|x| {
|
|
!crate::routes::analytics::FILTERED_HEADERS
|
|
.contains(&&*x.0.to_lowercase())
|
|
})
|
|
.collect(),
|
|
});
|
|
|
|
Ok(HttpResponse::NoContent().body(""))
|
|
}
|
|
|
|
#[post("/_force_reindex", guard = "admin_key_guard")]
|
|
pub async fn force_reindex(
|
|
pool: web::Data<PgPool>,
|
|
redis: web::Data<RedisPool>,
|
|
config: web::Data<SearchConfig>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
use crate::search::indexing::index_projects;
|
|
let redis = redis.get_ref();
|
|
index_projects(pool.as_ref().clone(), redis.clone(), &config).await?;
|
|
Ok(HttpResponse::NoContent().finish())
|
|
}
|