Initial setup

This commit is contained in:
maurice committed 2026-11-14 16:06:11 +01:00
commit 377bd1e198
7 files changed
+1863

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
use sqlx::SqlitePool;
/**
* Initialize database
*/
pub async fn init_db(pool: &SqlitePool) -> Result<(), sqlx::Error> {
sqlx::query(
r#"
CREATE TABLE IF NOT EXISTS notes (
id TEXT PRIMARY KEY,
type INTEGER NOT NULL,
content TEXT NOT NULL,
language TEXT,
expiration INTEGER,
max_views INTEGER,
views INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER,
password TEXT
)
"#
)
.execute(pool)
.await?;
Ok(())
}
+24
View File
@@ -0,0 +1,24 @@
use axum::{Router, extract::Path, http::{HeaderMap, header::ACCEPT}, response::{Html, IntoResponse}, routing::get, serve};
use tokio::net::TcpListener;
mod db;
mod paste;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(|| async {}))
.route("/{id}", get(get_note));
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
println!("Listening on http://localhost:3000");
serve(listener, app).await.unwrap();
}
async fn get_note(Path(id): Path<String>, headers: HeaderMap) -> impl IntoResponse {
let return_html = headers.get(ACCEPT)
.and_then(|v|v.to_str().ok())
.and_then(|h| Some(h.contains("text/html")))
.unwrap_or_default();
Html::from("test")
}
+8
View File
@@ -0,0 +1,8 @@
/**
* Paste type
*/
#[repr(u8)]
pub enum PasteType {
TextV1 = 0,
UrlV1 = 100
}