Implement Rust-based emote database and REST API

Co-authored-by: Ganonmaster <168445+Ganonmaster@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-18 13:18:40 +00:00
parent fd843535e6
commit 4fb17abb71
12 changed files with 4761 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
/// Row as stored in the database.
/// Timestamps are stored as ISO 8601 strings because `sqlx::Any` does not
/// provide a blanket `Encode`/`Decode` impl for `chrono::DateTime<Utc>`.
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct EmoteRow {
pub uuid: String,
pub name: String,
pub alias: Option<String>,
pub image_key: String,
/// ISO 8601 string, e.g. "2022-02-13T11:27:38.219685+00:00"
pub created: String,
/// ISO 8601 string
pub modified: String,
}
impl EmoteRow {
pub fn created_dt(&self) -> DateTime<Utc> {
DateTime::parse_from_rfc3339(&self.created)
.map(|dt| dt.with_timezone(&Utc))
.unwrap_or_else(|_| Utc::now())
}
pub fn modified_dt(&self) -> DateTime<Utc> {
DateTime::parse_from_rfc3339(&self.modified)
.map(|dt| dt.with_timezone(&Utc))
.unwrap_or_else(|_| Utc::now())
}
}
/// JSON representation returned by the API.
#[derive(Debug, Serialize, Deserialize)]
pub struct EmoteResponse {
pub name: String,
pub url: String,
pub created: DateTime<Utc>,
pub modified: DateTime<Utc>,
}
/// Payload for updating an existing emote.
#[derive(Debug, Deserialize)]
pub struct UpdateEmoteRequest {
pub name: Option<String>,
pub alias: Option<String>,
pub image_key: Option<String>,
}
pub fn new_uuid() -> String {
Uuid::new_v4().to_string()
}