add: profiles ui, communities ui, posts ui
This commit is contained in:
parent
00abbc8fa2
commit
eecf357325
36 changed files with 1460 additions and 147 deletions
|
@ -1,6 +1,12 @@
|
|||
use axum::{Extension, Json, body::Body, extract::Path, response::IntoResponse};
|
||||
use axum::{
|
||||
Extension, Json,
|
||||
body::Body,
|
||||
extract::{Path, Query},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use pathbufd::{PathBufD, pathd};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
fs::{File, exists},
|
||||
io::Read,
|
||||
|
@ -23,15 +29,36 @@ pub fn read_image(path: PathBufD) -> Vec<u8> {
|
|||
bytes
|
||||
}
|
||||
|
||||
#[derive(Deserialize, PartialEq, Eq)]
|
||||
pub enum AvatarSelectorType {
|
||||
#[serde(alias = "username")]
|
||||
Username,
|
||||
#[serde(alias = "id")]
|
||||
Id,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AvatarSelectorQuery {
|
||||
pub selector_type: AvatarSelectorType,
|
||||
}
|
||||
|
||||
/// Get a profile's avatar image
|
||||
/// `/api/v1/auth/profile/{id}/avatar`
|
||||
pub async fn avatar_request(
|
||||
Path(username): Path<String>,
|
||||
Path(selector): Path<String>,
|
||||
Extension(data): Extension<State>,
|
||||
Query(req): Query<AvatarSelectorQuery>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
|
||||
let user = match data.get_user_by_username(&username).await {
|
||||
let user = match {
|
||||
if req.selector_type == AvatarSelectorType::Id {
|
||||
data.get_user_by_id(selector.parse::<usize>().unwrap())
|
||||
.await
|
||||
} else {
|
||||
data.get_user_by_username(&selector).await
|
||||
}
|
||||
} {
|
||||
Ok(ua) => ua,
|
||||
Err(_) => {
|
||||
return (
|
||||
|
@ -88,7 +115,7 @@ pub async fn banner_request(
|
|||
};
|
||||
|
||||
let path =
|
||||
PathBufD::current().extend(&["avatars", &data.0.dirs.media, &format!("{}.avif", &user.id)]);
|
||||
PathBufD::current().extend(&["banners", &data.0.dirs.media, &format!("{}.avif", &user.id)]);
|
||||
|
||||
if !exists(&path).unwrap() {
|
||||
return (
|
||||
|
@ -107,7 +134,7 @@ pub async fn banner_request(
|
|||
)
|
||||
}
|
||||
|
||||
static MAXIUMUM_FILE_SIZE: usize = 8388608;
|
||||
pub static MAXIUMUM_FILE_SIZE: usize = 8388608;
|
||||
|
||||
/// Upload avatar
|
||||
pub async fn upload_avatar_request(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue