fixes in ux
This commit is contained in:
+26
-6
@@ -55,6 +55,8 @@ pub fn router(state: SharedState, static_dir: &str, upload_max_size_bytes: usize
|
||||
"/ws/{workspace_slug}/{note_slug}",
|
||||
get(websocket::upgrade),
|
||||
)
|
||||
.route("/static", get(static_not_found))
|
||||
.route("/static/{*path}", get(static_not_found))
|
||||
.nest_service("/assets", ServeDir::new(static_dir))
|
||||
.fallback(not_found)
|
||||
.layer(DefaultBodyLimit::max(upload_max_size_bytes.saturating_add(1024 * 1024)))
|
||||
@@ -75,7 +77,11 @@ async fn pad(
|
||||
Path(slug): Path<String>,
|
||||
) -> Response {
|
||||
match db::find_pad(&state.db, &slug).await {
|
||||
Ok(Some(_)) => versioned_html(include_str!("../static/pad.html"), &state.asset_version),
|
||||
Ok(Some(pad)) => {
|
||||
let html = include_str!("../static/pad.html")
|
||||
.replace("__PAD_TITLE__", &escape_html(&pad.title));
|
||||
versioned_html(&html, &state.asset_version)
|
||||
},
|
||||
Ok(None) => error_response(
|
||||
StatusCode::NOT_FOUND,
|
||||
"404",
|
||||
@@ -119,10 +125,11 @@ async fn workspace(
|
||||
Path(workspace_slug): Path<String>,
|
||||
) -> Response {
|
||||
match db::find_workspace(&state.db, &workspace_slug).await {
|
||||
Ok(Some(_)) => versioned_html(
|
||||
include_str!("../static/workspace.html"),
|
||||
&state.asset_version,
|
||||
),
|
||||
Ok(Some(workspace)) => {
|
||||
let html = include_str!("../static/workspace.html")
|
||||
.replace("__WORKSPACE_TITLE__", &escape_html(&workspace.title));
|
||||
versioned_html(&html, &state.asset_version)
|
||||
},
|
||||
Ok(None) => error_response(
|
||||
StatusCode::NOT_FOUND,
|
||||
"404",
|
||||
@@ -163,7 +170,11 @@ async fn note(
|
||||
};
|
||||
|
||||
match db::find_note(&state.db, workspace.id, ¬e_slug).await {
|
||||
Ok(Some(_)) => versioned_html(include_str!("../static/note.html"), &state.asset_version),
|
||||
Ok(Some(note)) => {
|
||||
let html = include_str!("../static/note.html")
|
||||
.replace("__NOTE_TITLE__", &escape_html(¬e.title));
|
||||
versioned_html(&html, &state.asset_version)
|
||||
},
|
||||
Ok(None) => error_response(
|
||||
StatusCode::NOT_FOUND,
|
||||
"404",
|
||||
@@ -180,6 +191,15 @@ async fn note(
|
||||
}
|
||||
}
|
||||
|
||||
async fn static_not_found() -> Response {
|
||||
let mut response = (StatusCode::NOT_FOUND, "404").into_response();
|
||||
response.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("text/plain; charset=utf-8"),
|
||||
);
|
||||
response
|
||||
}
|
||||
|
||||
async fn not_found(State(state): State<SharedState>) -> Response {
|
||||
error_response(
|
||||
StatusCode::NOT_FOUND,
|
||||
|
||||
Reference in New Issue
Block a user