Footer and Setting Fixes
This commit is contained in:
+33
-1
@@ -7,7 +7,7 @@ use axum_extra::extract::cookie::{Cookie, SameSite, SignedCookieJar};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
models::{User, RegisterRequest, LoginRequest, ChangePasswordRequest, UpdateProfileRequest},
|
||||
models::{User, RegisterRequest, LoginRequest, ChangePasswordRequest, UpdateProfileRequest, StorageStats},
|
||||
AppState,
|
||||
};
|
||||
|
||||
@@ -188,3 +188,35 @@ pub async fn change_password(
|
||||
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
pub async fn storage_stats(
|
||||
State(state): State<AppState>,
|
||||
jar: SignedCookieJar,
|
||||
) -> Result<Json<StorageStats>, (StatusCode, String)> {
|
||||
let user_id = jar.get("session_user_id").map(|c| c.value().to_string())
|
||||
.ok_or((StatusCode::UNAUTHORIZED, "Not logged in".to_string()))?;
|
||||
|
||||
let docs_size: (i64,) = sqlx::query_as(
|
||||
"SELECT COALESCE(SUM(LENGTH(content)), 0) FROM documents WHERE owner_id = ?"
|
||||
)
|
||||
.bind(&user_id)
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.unwrap_or((0,));
|
||||
|
||||
let files_size: (i64,) = sqlx::query_as(
|
||||
"SELECT COALESCE(SUM(LENGTH(data)), 0) FROM files WHERE owner_id = ?"
|
||||
)
|
||||
.bind(&user_id)
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.unwrap_or((0,));
|
||||
|
||||
let stats = StorageStats {
|
||||
documents_size_bytes: docs_size.0,
|
||||
files_size_bytes: files_size.0,
|
||||
total_size_bytes: docs_size.0 + files_size.0,
|
||||
};
|
||||
|
||||
Ok(Json(stats))
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ async fn main() {
|
||||
.route("/auth/login", post(auth::login))
|
||||
.route("/auth/logout", post(auth::logout))
|
||||
.route("/auth/me", get(auth::me).put(auth::update_profile))
|
||||
.route("/auth/storage", get(auth::storage_stats))
|
||||
.route("/auth/change-password", put(auth::change_password))
|
||||
.route("/folders", get(folders::list_folders).post(folders::create_folder))
|
||||
.route("/folders/{id}", delete(folders::delete_folder).patch(folders::update_folder))
|
||||
|
||||
@@ -83,3 +83,10 @@ pub struct UpdateDocumentRequest {
|
||||
pub title: Option<String>,
|
||||
pub folder_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct StorageStats {
|
||||
pub documents_size_bytes: i64,
|
||||
pub files_size_bytes: i64,
|
||||
pub total_size_bytes: i64,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user