This commit is contained in:
maurice committed 2026-11-14 18:25:54 +01:00
1 parent b444b5759d
commit a3067b011d
8 files changed
+123 -110

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ pub async fn create(
.fetch_optional(db)
.await
.map_err(db_error)?;
if let Some(id) = created {
return Ok(id);
}
+14 -3
View File
@@ -5,6 +5,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Response},
};
use base64::{Engine, engine::general_purpose::STANDARD};
use irosashi::{CodeToHtmlOptions, Highlighter};
use sqlx::SqlitePool;
@@ -17,6 +18,7 @@ use super::{db_error, return_html};
pub struct NotePage {
paste: Paste,
code: String,
raw_code: String,
}
pub async fn get_note(
@@ -24,10 +26,12 @@ pub async fn get_note(
Path(id): Path<String>,
headers: HeaderMap,
) -> Result<Response, StatusCode> {
let paste = Paste::read(&db, &id, PasteType::TextV1)
let Some(paste) = Paste::read(&db, &id, PasteType::TextV1)
.await
.map_err(db_error)?
.ok_or(StatusCode::NOT_FOUND)?;
else {
return Ok((StatusCode::NOT_FOUND, "Note not found").into_response());
};
let mut metadata = HeaderMap::new();
metadata.insert("x-paste-views", HeaderValue::from(paste.views));
@@ -46,9 +50,16 @@ pub async fn get_note(
),
)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
NotePage { paste, code }.into_response()
let raw_code = STANDARD.encode(&paste.content);
NotePage {
paste,
code,
raw_code,
}
.into_response()
} else {
paste.content.into_response()
};
Ok((metadata, response).into_response())
}