summaryrefslogtreecommitdiff
path: root/src/api/users.rs
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-01-31 22:21:19 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-01-31 22:21:19 -0500
commitd9125314809e7f03cb155f91d535e94da583a365 (patch)
treef34bc2e978d5e79f0dc62aa7a5faa8f096b46dc5 /src/api/users.rs
parentfix admin (diff)
downloadxssbook-d9125314809e7f03cb155f91d535e94da583a365.tar.gz
xssbook-d9125314809e7f03cb155f91d535e94da583a365.tar.bz2
xssbook-d9125314809e7f03cb155f91d535e94da583a365.zip
custosm avatars and banners
Diffstat (limited to 'src/api/users.rs')
-rw-r--r--src/api/users.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/api/users.rs b/src/api/users.rs
index afcdddd..83a0d4e 100644
--- a/src/api/users.rs
+++ b/src/api/users.rs
@@ -1,9 +1,9 @@
use crate::types::{
- extract::{AuthorizedUser, Check, CheckResult, Json},
+ extract::{AuthorizedUser, Check, CheckResult, Json, Png},
http::ResponseCode,
user::User,
};
-use axum::{response::Response, routing::post, Router};
+use axum::{response::Response, routing::{post, put}, Router};
use serde::Deserialize;
#[derive(Deserialize)]
@@ -63,9 +63,33 @@ async fn load_self(AuthorizedUser(user): AuthorizedUser) -> Response {
ResponseCode::Success.json(&json)
}
+async fn avatar(AuthorizedUser(user): AuthorizedUser, Png(img): Png) -> Response {
+
+ let path = format!("./public/image/custom/avatar/{}.png", user.user_id);
+
+ if img.save(path).is_err() {
+ return ResponseCode::InternalServerError.text("Failed to update avatar");
+ }
+
+ ResponseCode::Success.text("Successfully updated avatar")
+}
+
+async fn banner(AuthorizedUser(user): AuthorizedUser, Png(img): Png) -> Response {
+
+ let path = format!("./public/image/custom/banner/{}.png", user.user_id);
+
+ if img.save(path).is_err() {
+ return ResponseCode::InternalServerError.text("Failed to update banner");
+ }
+
+ ResponseCode::Success.text("Successfully updated banner")
+}
+
pub fn router() -> Router {
Router::new()
.route("/load", post(load_batch))
.route("/self", post(load_self))
.route("/page", post(load_page))
+ .route("/avatar", put(avatar))
+ .route("/banner", put(banner))
}