feat: Add attachment management with upload, deletion, serving, and media metadata stripping.

This commit is contained in:
2026-03-03 17:24:45 +00:00
parent 57f2610164
commit 82f7e006cf
8 changed files with 1085 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
use axum::Router;
use axum::{routing::get, Router};
use sqlx::{sqlite::{SqliteConnectOptions, SqlitePoolOptions}, SqlitePool};
use std::str::FromStr;
use std::sync::Arc;
@@ -95,10 +95,29 @@ async fn main() {
.expect("Failed to create posts table");
sqlx::query(
r#"
CREATE TABLE IF NOT EXISTS attachments (
id TEXT PRIMARY KEY,
filename TEXT NOT NULL,
content_type TEXT NOT NULL,
size INTEGER NOT NULL,
created_at INTEGER NOT NULL
);
"#,
)
.execute(&db_pool)
.await
.expect("Failed to create attachments table");
// Create attachments directory
std::fs::create_dir_all("attachments").expect("Failed to create attachments directory");
let app_state = Arc::new(AppState { db: db_pool });
let app = Router::new()
.merge(handlers::public::router())
.route("/__attachments/{id}", get(handlers::attachments::serve_attachment))
.nest("/__dungeon", handlers::router(&app_state)) // I'll create a single `handlers::router`
.with_state(app_state.clone())
.layer(tower_http::trace::TraceLayer::new_for_http());