- NIP-42 Can be enabled in nix module or as environment variable 'CONFIG_ENABLE_AUTH' - NIP-05 Still WIP, but building up slowly
78 lines
2.5 KiB
Rust
78 lines
2.5 KiB
Rust
use crate::noose::user::User;
|
|
|
|
// use super::accounts::create_account;
|
|
use super::dto::{Account, UserBody, UserQuery};
|
|
use super::filter::{validate_body_filter, validate_query_filter};
|
|
use super::handler::{create_user, get_account, get_user};
|
|
use crate::utils::filter::with_context;
|
|
use crate::utils::structs::Context;
|
|
use warp::{Filter, Rejection, Reply};
|
|
|
|
pub fn routes(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
let cors = warp::cors().allow_any_origin();
|
|
let index = warp::path::end().map(|| warp::reply::html("<h1>SNEED!</h1>"));
|
|
|
|
index
|
|
.or(nip05_get(context.clone()))
|
|
.or(nip05_create(context.clone()))
|
|
.with(&cors)
|
|
}
|
|
|
|
fn well_known<M>(warp_method: M) -> impl Filter<Extract = (), Error = Rejection> + Clone
|
|
where
|
|
M: (Filter<Extract = (), Error = Rejection>) + Copy,
|
|
{
|
|
warp_method.and(warp::path(".well-known"))
|
|
}
|
|
|
|
fn nostr_well_known() -> impl Filter<Extract = (), Error = Rejection> + Clone {
|
|
well_known(warp::get()).and(warp::path("nostr.json"))
|
|
}
|
|
|
|
fn nip05_get(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
nostr_well_known()
|
|
.and(validate_query_filter::<UserQuery>())
|
|
.and(with_context(context.clone()))
|
|
.and_then(get_user)
|
|
}
|
|
|
|
fn nip05_create(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
well_known(warp::post())
|
|
.and(warp::path("nostr.json"))
|
|
.and(warp::body::content_length_limit(1024))
|
|
.and(validate_body_filter::<UserBody>())
|
|
.and(with_context(context.clone()))
|
|
.and_then(create_user)
|
|
}
|
|
|
|
// pub fn account_create(
|
|
// context: Context,
|
|
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
// warp::path("account")
|
|
// .and(warp::post())
|
|
// .and(validate_body_filter::<User>())
|
|
// .and(with_context(context))
|
|
// .and_then(create_account)
|
|
// }
|
|
|
|
// pub fn account_get(
|
|
// context: Context,
|
|
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
// warp::path("account")
|
|
// .and(warp::get())
|
|
// .and(validate_body_filter::<Account>())
|
|
// .and(with_context(context))
|
|
// .and_then(get_account)
|
|
// }
|
|
|
|
// pub fn account_update(
|
|
// context: Context,
|
|
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
|
// warp::path("account")
|
|
// .and(warp::put())
|
|
// .and(warp::body::json::<Account>())
|
|
// .then(validate_body)
|
|
// .and(with_context(context))
|
|
// .and_then(update_account)
|
|
// }
|