c13f5b9a88
Adds a server-side HTML management page and supporting backend for full CRUD on emotes. The /manage prefix is kept isolated so an auth middleware can be applied to it later without touching other routes. - GET /manage — serves the management UI (add, edit, delete, search) - GET /manage/emotes — admin JSON endpoint with uuid and alias included - AdminEmoteResponse model for the expanded admin representation - Client-side search filters by name or alias as you type
44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
use axum::{
|
|
extract::State,
|
|
http::StatusCode,
|
|
response::{Html, IntoResponse, Json},
|
|
};
|
|
use serde_json::json;
|
|
|
|
use crate::{models::AdminEmoteResponse, AppState};
|
|
|
|
/// GET /manage
|
|
/// Serves the emote management HTML page.
|
|
pub async fn manage_root() -> impl IntoResponse {
|
|
Html(include_str!("../templates/manage.html"))
|
|
}
|
|
|
|
/// GET /manage/emotes
|
|
/// Returns all emotes with full admin data (uuid, alias included).
|
|
pub async fn list_admin_emotes(State(state): State<AppState>) -> impl IntoResponse {
|
|
match state.db.list_emotes().await {
|
|
Ok(rows) => {
|
|
let emotes: Vec<AdminEmoteResponse> = rows
|
|
.into_iter()
|
|
.map(|row| AdminEmoteResponse {
|
|
uuid: row.uuid.clone(),
|
|
name: row.name.clone(),
|
|
alias: row.alias.clone(),
|
|
url: state.storage.public_url(&row.image_key),
|
|
created: row.created_dt(),
|
|
modified: row.modified_dt(),
|
|
})
|
|
.collect();
|
|
(StatusCode::OK, Json(json!({"emotes": emotes}))).into_response()
|
|
}
|
|
Err(e) => {
|
|
tracing::error!("Failed to list emotes: {e}");
|
|
(
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
Json(json!({"error": "Failed to list emotes"})),
|
|
)
|
|
.into_response()
|
|
}
|
|
}
|
|
}
|