summaryrefslogtreecommitdiff
path: root/src/public
diff options
context:
space:
mode:
Diffstat (limited to 'src/public')
-rw-r--r--src/public/admin.rs64
-rw-r--r--src/public/docs.rs96
2 files changed, 105 insertions, 55 deletions
diff --git a/src/public/admin.rs b/src/public/admin.rs
index 1da2f1e..25941f1 100644
--- a/src/public/admin.rs
+++ b/src/public/admin.rs
@@ -4,8 +4,8 @@ use rand::{distributions::Alphanumeric, Rng};
use tokio::sync::Mutex;
use crate::{
- console::{self, sanatize},
- types::{http::ResponseCode, post::Post, session::Session, user::User},
+ console::sanatize,
+ types::{http::ResponseCode, post::Post, session::Session, user::User, comment::Comment, like::Like},
};
lazy_static! {
@@ -79,24 +79,17 @@ pub fn generate_posts() -> Response {
<th>Post ID</th>
<th>User ID</th>
<th>Content</th>
- <th>Likes</th>
- <th>Comments</th>
<th>Date</th>
</tr>
"#
.to_string();
for post in posts {
- let Ok(likes) = serde_json::to_string(&post.likes) else { continue };
- let Ok(comments) = serde_json::to_string(&post.comments) else { continue };
-
html.push_str(&format!(
- "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
+ "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
post.post_id,
post.user_id,
sanatize(&post.content),
- console::beautify(&likes),
- console::beautify(&comments),
post.date
));
}
@@ -127,3 +120,54 @@ pub fn generate_sessions() -> Response {
ResponseCode::Success.text(&html)
}
+
+pub fn generate_comments() -> Response {
+ let comments = match Comment::reterieve_all() {
+ Ok(comments) => comments,
+ Err(err) => return err,
+ };
+
+ let mut html = r#"
+ <tr>
+ <th>Comment ID</th>
+ <th>User ID</th>
+ <th>Post ID</th>
+ <th>Content</th>
+ <th>Date</th>
+ </tr>
+ "#
+ .to_string();
+
+ for comment in comments {
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
+ comment.comment_id, comment.user_id, comment.post_id, sanatize(&comment.content), comment.date
+ ));
+ }
+
+ ResponseCode::Success.text(&html)
+}
+
+pub fn generate_likes() -> Response {
+ let likes = match Like::reterieve_all() {
+ Ok(likes) => likes,
+ Err(err) => return err,
+ };
+
+ let mut html = r#"
+ <tr>
+ <th>User ID</th>
+ <th>Post ID</th>
+ </tr>
+ "#
+ .to_string();
+
+ for like in likes {
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td></tr>",
+ like.user_id, like.post_id
+ ));
+ }
+
+ ResponseCode::Success.text(&html)
+}
diff --git a/src/public/docs.rs b/src/public/docs.rs
index 1f1448b..f4e26be 100644
--- a/src/public/docs.rs
+++ b/src/public/docs.rs
@@ -2,7 +2,10 @@ use axum::response::Response;
use lazy_static::lazy_static;
use tokio::sync::Mutex;
-use crate::{api::{admin, users, posts, auth}, types::http::ResponseCode};
+use crate::{
+ api::{admin, auth, posts, users},
+ types::http::ResponseCode,
+};
use super::console::beautify;
@@ -40,10 +43,10 @@ fn generate_body(body: Option<&'static str>) -> String {
return String::new()
};
let html = r#"
- <h2>Body</h2>
- <div class="body">
- $body
- </div>
+ <h2>Body</h2>
+ <div class="body">
+ $body
+ </div>
"#
.to_string();
let body = body.trim();
@@ -60,20 +63,20 @@ fn generate_body(body: Option<&'static str>) -> String {
fn generate_responses(responses: &[(u16, &'static str)]) -> String {
let mut html = r#"
- <h2>Responses</h2>
- $responses
+ <h2>Responses</h2>
+ $responses
"#
.to_string();
for response in responses {
let res = format!(
r#"
- <div>
- <span class="ptype">{}</span>
- <span class="pdesc">{}</span>
- </div>
- $responses
- "#,
+ <div>
+ <span class="ptype">{}</span>
+ <span class="pdesc">{}</span>
+ </div>
+ $responses
+ "#,
response.0, response.1
);
html = html.replace("$responses", &res);
@@ -93,18 +96,18 @@ fn generate_cookie(cookie: Option<&'static str>) -> String {
fn generate_endpoint(doc: &EndpointDocumentation) -> String {
let html = r#"
- <div>
- <div class="endpoint">
- <span class="method $method_class">$method</span>
- <span class="uri">$uri</span>
- <span class="desc">$description</span>
- $cookie
- </div>
- <div class="info">
- $body
- $responses
- </div>
+ <div>
+ <div class="endpoint">
+ <span class="method $method_class">$method</span>
+ <span class="uri">$uri</span>
+ <span class="desc">$description</span>
+ $cookie
</div>
+ <div class="info">
+ $body
+ $responses
+ </div>
+ </div>
"#;
html.replace("$method_class", &doc.method.to_string().to_lowercase())
@@ -123,6 +126,7 @@ pub async fn init() {
auth::AUTH_LOGOUT,
posts::POSTS_CREATE,
posts::POSTS_PAGE,
+ posts::COMMENTS_PAGE,
posts::POSTS_USER,
posts::POSTS_COMMENT,
posts::POSTS_LIKE,
@@ -136,6 +140,8 @@ pub async fn init() {
admin::ADMIN_POSTS,
admin::ADMIN_USERS,
admin::ADMIN_SESSIONS,
+ admin::ADMIN_COMMENTS,
+ admin::ADMIN_LIKES
];
let mut endpoints = ENDPOINTS.lock().await;
for doc in docs {
@@ -154,27 +160,27 @@ pub async fn generate() -> Response {
let html = format!(
r#"
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <link rel="stylesheet" href="/css/main.css">
- <link rel="stylesheet" href="/css/header.css">
- <link rel="stylesheet" href="/css/console.css">
- <link rel="stylesheet" href="/css/api.css">
- <title>XSSBook - API Documentation</title>
- </head>
- <body>
- <div id="header">
- <span class="logo"><a href="/">xssbook</a></span>
- <span class="gtext desc" style="margin-left: 6em; font-size: 2em; color: #606770">API Documentation</span>
- </div>
- <div id="docs">
- {data}
- </div>
- </body>
- </html>
- "#
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="/css/main.css">
+ <link rel="stylesheet" href="/css/header.css">
+ <link rel="stylesheet" href="/css/console.css">
+ <link rel="stylesheet" href="/css/api.css">
+ <title>XSSBook - API Documentation</title>
+ </head>
+ <body>
+ <div id="header">
+ <span class="logo"><a href="/">xssbook</a></span>
+ <span class="gtext desc" style="margin-left: 6em; font-size: 2em; color: #606770">API Documentation</span>
+ </div>
+ <div id="docs">
+ {data}
+ </div>
+ </body>
+ </html>
+ "#
);
ResponseCode::Success.html(&html)