feat: require auth for search

This commit is contained in:
Zomatree
2025-08-08 00:44:01 +01:00
committed by Angelo Kontaxis
parent b0c977b324
commit b5cd5e30ef
5 changed files with 37 additions and 11 deletions

View File

@@ -1,21 +1,20 @@
use axum::{
extract::{FromRef, FromRequestParts},
http::request::Parts,
};
use axum::{extract::{FromRef, FromRequestParts}, http::request::Parts};
use revolt_result::{create_error, Error, Result};
use crate::{Database, User};
#[async_trait::async_trait]
impl<S: Send + Sync> FromRequestParts<S> for User
impl<S> FromRequestParts<S> for User
where
Database: FromRef<S>,
S: Send + Sync
{
type Rejection = Error;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<User> {
let db = Database::from_ref(state);
if let Some(Ok(bot_token)) = parts.headers.get("x-bot-token").map(|v| v.to_str()) {
let bot = db.fetch_bot_by_token(bot_token).await?;
db.fetch_user(&bot.id).await