summaryrefslogtreecommitdiff
path: root/src/public
diff options
context:
space:
mode:
authortylerm <tylerm@tylerm.dev>2023-08-22 04:16:31 +0000
committertylerm <tylerm@tylerm.dev>2023-08-22 04:16:31 +0000
commitedbbdf72c78536c48357a86181bbf6897fc52074 (patch)
tree91d91e9dfb77ae3b7d75f4348c01bba59d0f13dc /src/public
parentallow port env (diff)
parentfinish dms (diff)
downloadxssbook-edbbdf72c78536c48357a86181bbf6897fc52074.tar.gz
xssbook-edbbdf72c78536c48357a86181bbf6897fc52074.tar.bz2
xssbook-edbbdf72c78536c48357a86181bbf6897fc52074.zip
Merge pull request 'dms are cool' (#1) from dev into main
Reviewed-on: https://g.tylerm.dev/tylerm/xssbook/pulls/1
Diffstat (limited to 'src/public')
-rw-r--r--src/public/docs.rs14
-rw-r--r--src/public/mod.rs29
-rw-r--r--src/public/pages.rs5
3 files changed, 21 insertions, 27 deletions
diff --git a/src/public/docs.rs b/src/public/docs.rs
index 397e696..976638b 100644
--- a/src/public/docs.rs
+++ b/src/public/docs.rs
@@ -3,24 +3,28 @@ use lazy_static::lazy_static;
use tokio::sync::Mutex;
use crate::{
- api::{admin, auth, posts, users},
+ api::{admin, auth, posts, users, chat},
types::http::ResponseCode,
};
use super::console::beautify;
pub enum EndpointMethod {
+ Get,
Post,
Put,
Patch,
+ Delete
}
impl ToString for EndpointMethod {
fn to_string(&self) -> String {
match self {
+ Self::Get => "GET".to_owned(),
Self::Post => "POST".to_owned(),
Self::Put => "PUT".to_owned(),
Self::Patch => "PATCH".to_owned(),
+ Self::Delete => "DELETE".to_owned(),
}
}
}
@@ -139,6 +143,14 @@ pub async fn init() {
users::USERS_FOLLOW,
users::USERS_FOLLOW_STATUS,
users::USERS_FRIENDS,
+ chat::CHAT_LIST,
+ chat::CHAT_CREATE,
+ chat::CHAT_ADD,
+ chat::CHAT_LEAVE,
+ chat::CHAT_SEND,
+ chat::CHAT_LOAD,
+ chat::CHAT_TYPING,
+ chat::CHAT_CONNECT,
admin::ADMIN_AUTH,
admin::ADMIN_QUERY,
admin::ADMIN_POSTS,
diff --git a/src/public/mod.rs b/src/public/mod.rs
index bb75ef0..bd40fda 100644
--- a/src/public/mod.rs
+++ b/src/public/mod.rs
@@ -1,17 +1,12 @@
use axum::{
body::Body,
- error_handling::HandleErrorLayer,
headers::HeaderName,
http::{HeaderValue, Request, StatusCode},
- response::{IntoResponse, Response},
+ response::{Response, IntoResponse},
routing::get,
- BoxError, Router,
-};
-use tower::{ServiceBuilder, ServiceExt};
-use tower_governor::{
- errors::display_error, governor::GovernorConfigBuilder, key_extractor::SmartIpKeyExtractor,
- GovernorLayer,
+ Router,
};
+use tower::ServiceExt;
use tower_http::services::ServeFile;
use crate::types::http::ResponseCode;
@@ -23,15 +18,6 @@ pub mod file;
pub mod pages;
pub fn router() -> Router {
- let governor_conf = Box::new(
- GovernorConfigBuilder::default()
- .burst_size(30)
- .per_second(1)
- .key_extractor(SmartIpKeyExtractor)
- .finish()
- .expect("Failed to create rate limiter"),
- );
-
Router::new()
.nest("/", pages::router())
.route("/favicon.ico", get(file::favicon))
@@ -42,15 +28,6 @@ pub fn router() -> Router {
.route("/image/*path", get(file::image))
.route("/image/avatar", get(file::avatar))
.route("/image/banner", get(file::banner))
- .layer(
- ServiceBuilder::new()
- .layer(HandleErrorLayer::new(|e: BoxError| async move {
- display_error(e)
- }))
- .layer(GovernorLayer {
- config: Box::leak(governor_conf),
- }),
- )
}
pub async fn serve(path: &str) -> Response {
diff --git a/src/public/pages.rs b/src/public/pages.rs
index a7789b2..0eef51b 100644
--- a/src/public/pages.rs
+++ b/src/public/pages.rs
@@ -66,6 +66,10 @@ async fn forgot(UserAgent(agent): UserAgent, _: Log) -> Response {
Redirect::to("https://www.youtube.com/watch?v=dQw4w9WgXcQ").into_response()
}
+async fn chat() -> Response {
+ super::serve("/chat.html").await
+}
+
pub fn router() -> Router {
Router::new()
.route("/", get(root))
@@ -79,4 +83,5 @@ pub fn router() -> Router {
.route("/admin", get(admin))
.route("/docs", get(api))
.route("/forgot", get(forgot))
+ .route("/chat", get(chat))
}