This commit is contained in:
arrelin
2026-01-17 12:52:07 +03:00
parent 31bafb3c76
commit 35e79de378

View File

@@ -1,6 +1,6 @@
use axum::{
extract::{Path, State},
http::StatusCode,
http::{StatusCode, HeaderMap},
Json,
};
use axum_login::AuthSession;
@@ -70,6 +70,7 @@ fn model_to_response(model: InviteLinkModel, base_url: &str) -> InviteLinkRespon
)]
pub async fn create_invite_link(
auth_session: AuthSession<AuthBackend>,
headers: HeaderMap,
State(db): State<DatabaseConnection>,
Json(payload): Json<CreateInviteLinkRequest>,
) -> Result<Json<InviteLinkResponse>, StatusCode> {
@@ -84,7 +85,11 @@ pub async fn create_invite_link(
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string());
let base_url = headers
.get("origin")
.and_then(|v| v.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()));
Ok(Json(model_to_response(invite, &base_url)))
}
@@ -101,6 +106,7 @@ pub async fn create_invite_link(
)]
pub async fn get_my_invite_links(
auth_session: AuthSession<AuthBackend>,
headers: HeaderMap,
State(db): State<DatabaseConnection>,
) -> Result<Json<Vec<InviteLinkResponse>>, StatusCode> {
let user = auth_session.user.ok_or(StatusCode::UNAUTHORIZED)?;
@@ -110,7 +116,11 @@ pub async fn get_my_invite_links(
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string());
let base_url = headers
.get("origin")
.and_then(|v| v.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()));
let responses: Vec<InviteLinkResponse> = invites
.into_iter()
.map(|i| model_to_response(i, &base_url))