Download counting (#388)

This commit is contained in:
Geometrically
2022-07-01 19:31:37 -07:00
committed by GitHub
parent 1fc579e907
commit 1e4d07a52c
3 changed files with 21 additions and 1 deletions

5
.env
View File

@@ -42,4 +42,7 @@ RATE_LIMIT_IGNORE_IPS='["127.0.0.1"]'
WHITELISTED_MODPACK_DOMAINS='["cdn.modrinth.com", "edge.forgecdn.net", "github.com", "raw.githubusercontent.com"]'
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "-modrinth.vercel.app"]'
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "-modrinth.vercel.app"]'
ARIADNE_ADMIN_KEY=feedbeef
ARIADNE_URL=https://staging-ariadne.modrinth.com/v1/

View File

@@ -343,5 +343,8 @@ fn check_env_vars() -> bool {
failed |= check_var::<String>("GITHUB_CLIENT_ID");
failed |= check_var::<String>("GITHUB_CLIENT_SECRET");
failed |= check_var::<String>("ARIADNE_ADMIN_KEY");
failed |= check_var::<String>("ARIADNE_URL");
failed
}

View File

@@ -4,6 +4,7 @@ use crate::util::guards::admin_key_guard;
use crate::DownloadQueue;
use actix_web::{patch, web, HttpResponse};
use serde::Deserialize;
use serde_json::json;
use sqlx::PgPool;
use std::sync::Arc;
@@ -59,5 +60,18 @@ pub async fn count_download(
)
.await;
let client = reqwest::Client::new();
client
.post(format!("{}downloads", dotenv::var("ARIADNE_URL")?))
.header("Modrinth-Admin", dotenv::var("ARIADNE_ADMIN_KEY")?)
.json(&json!({
"url": download_body.url,
"project_id": download_body.hash
}))
.send()
.await
.ok();
Ok(HttpResponse::Ok().body(""))
}