new finctions and fixes

This commit is contained in:
Mateusz Gruszczyński committed 2026-07-30 00:12:48 +02:00
1 parent 9ca055de5f
commit 2274cf57c9
31 files changed
+1348 -505

No files matched your search

+4 -3
View File
@@ -46,9 +46,10 @@ pub fn router(
}
});
let asset_cache_control =
HeaderValue::from_str(&format!("public, max-age={asset_cache_max_age_seconds}"))
.expect("valid asset cache-control header");
let asset_cache_control = HeaderValue::from_str(&crate::cache::cache_control(
asset_cache_max_age_seconds,
))
.expect("valid asset cache-control header");
Router::new()
.route("/", get(home))
+52 -42
View File
@@ -15,6 +15,36 @@ use axum::{
use crate::{assets, db, state::SharedState};
fn render_editor_page(
state: &SharedState,
entrypoint: &str,
resource_kind: &str,
document_title: &str,
parent_title: &str,
parent_url: &str,
parent_class: &str,
protected_resource_label: &str,
extra_shortcuts: &str,
) -> Response {
let html = include_str!("../../static/editor.html")
.replace("__RESOURCE_KIND__", resource_kind)
.replace("__DOCUMENT_TITLE__", &escape_html(document_title))
.replace("__PARENT_TITLE__", &escape_html(parent_title))
.replace("__PARENT_URL__", &escape_html(parent_url))
.replace("__PARENT_CLASS__", parent_class)
.replace("__PROTECTED_RESOURCE_LABEL__", protected_resource_label)
.replace("__EXTRA_SHORTCUTS__", extra_shortcuts);
assets::render_html(
&html,
&state.asset_version,
state.registration_enabled,
state.ldap.is_some(),
&state.frontend_log_level,
state.upload_max_size_bytes,
entrypoint,
)
}
pub(super) async fn health() -> &'static str {
"ok"
}
@@ -46,19 +76,17 @@ pub(super) async fn home(State(state): State<SharedState>) -> Response {
pub(super) async fn pad(State(state): State<SharedState>, Path(slug): Path<String>) -> Response {
match db::find_pad(&state.db, &slug).await {
Ok(Some(pad)) => {
let html = include_str!("../../static/pad.html")
.replace("__PAD_TITLE__", &escape_html(&pad.title));
assets::render_html(
&html,
&state.asset_version,
state.registration_enabled,
state.ldap.is_some(),
&state.frontend_log_level,
state.upload_max_size_bytes,
"pad",
)
}
Ok(Some(pad)) => render_editor_page(
&state,
"pad",
"pad",
&pad.title,
"RustPad",
"/",
"home-brand",
"note",
"<kbd>Alt+Enter</kbd><span>New line while editing Preview</span><kbd>Esc</kbd><span>Edit raw Markdown of current Preview line</span>",
),
Ok(None) => error_response(
StatusCode::NOT_FOUND,
"404",
@@ -169,35 +197,17 @@ pub(super) async fn note(
};
match db::find_note(&state.db, workspace.id, &note_slug).await {
Ok(Some(note)) => {
let html = include_str!("../../static/note.html")
.replace(
"__NOTE_TITLE__",
&escape_html(if workspace.is_private != 0 {
"Note"
} else {
&note.title
}),
)
.replace(
"__WORKSPACE_TITLE__",
&escape_html(if workspace.is_private != 0 {
"Workspace"
} else {
&workspace.title
}),
)
.replace("__WORKSPACE_SLUG__", &escape_html(&workspace_slug));
assets::render_html(
&html,
&state.asset_version,
state.registration_enabled,
state.ldap.is_some(),
&state.frontend_log_level,
state.upload_max_size_bytes,
"note",
)
}
Ok(Some(note)) => render_editor_page(
&state,
"note",
"note",
if workspace.is_private != 0 { "Note" } else { &note.title },
if workspace.is_private != 0 { "Workspace" } else { &workspace.title },
&format!("/w/{workspace_slug}"),
"",
"workspace",
"",
),
Ok(None) => error_response(
StatusCode::NOT_FOUND,
"404",