From 2ae98869112c7975d3bdd1c2ed81e9f7204451b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sn=C3=ADda=C5=88ov=C3=BD=20Mistr?= Date: Sun, 10 Mar 2024 10:22:30 +0100 Subject: [PATCH] =?UTF-8?q?Skripty=20na=20konci=20(SEO)=20+=20Hledan=C3=A9?= =?UTF-8?q?=20v=C3=BDsledky=20chronologicky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/post.rs | 4 ++-- src/error.rs | 3 +++ src/web/search.rs | 4 ++++ templates/base.html | 15 +++++++-------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/db/post.rs b/src/db/post.rs index 379b6e6..8dfd198 100755 --- a/src/db/post.rs +++ b/src/db/post.rs @@ -284,7 +284,7 @@ impl Post { page: i64, ) -> Result, NekrochanError> { let posts = query_as(&format!( - "SELECT * FROM posts_{} WHERE LOWER(content_nomarkup) LIKE LOWER($1) LIMIT $2 OFFSET $3", + "SELECT * FROM posts_{} WHERE LOWER(content_nomarkup) LIKE LOWER($1) ORDER BY created DESC LIMIT $2 OFFSET $3", board.id )) .bind(format!("%{query}%")) @@ -302,7 +302,7 @@ impl Post { page: i64, ) -> Result, NekrochanError> { let posts = - query_as("SELECT * FROM overboard WHERE LOWER(content_nomarkup) LIKE LOWER($1) LIMIT $2 OFFSET $3") + query_as("SELECT * FROM overboard WHERE LOWER(content_nomarkup) LIKE LOWER($1) ORDER BY created DESC LIMIT $2 OFFSET $3") .bind(format!("%{query}%")) .bind(GENERIC_PAGE_SIZE) .bind((page - 1) * GENERIC_PAGE_SIZE) diff --git a/src/error.rs b/src/error.rs index 6ec536d..97f4b5e 100755 --- a/src/error.rs +++ b/src/error.rs @@ -84,6 +84,8 @@ pub enum NekrochanError { PostNameFormatError, #[error("Příspěvek /{}/{} neexistuje.", .0, .1)] PostNotFound(String, i64), + #[error("Hledaný termín musí mít 1-256 znaků.")] + QueryFormatError, #[error("Vlákno dosáhlo limitu odpovědí.")] ReplyLimitError, #[error("Hlášení můsí mít 1-200 znaků.")] @@ -255,6 +257,7 @@ impl ResponseError for NekrochanError { NekrochanError::PasswordFormatError => StatusCode::BAD_REQUEST, NekrochanError::PostNameFormatError => StatusCode::BAD_REQUEST, NekrochanError::PostNotFound(_, _) => StatusCode::NOT_FOUND, + NekrochanError::QueryFormatError => StatusCode::BAD_REQUEST, NekrochanError::ReplyLimitError => StatusCode::FORBIDDEN, NekrochanError::ReportFormatError => StatusCode::BAD_REQUEST, NekrochanError::RequiredCaptchaError => StatusCode::UNAUTHORIZED, diff --git a/src/web/search.rs b/src/web/search.rs index 720cf9f..10e1b25 100644 --- a/src/web/search.rs +++ b/src/web/search.rs @@ -65,6 +65,10 @@ pub async fn search( let query = query.query; + if query.is_empty() || query.len() > 256 { + return Err(NekrochanError::QueryFormatError); + } + let posts = if let Some(board) = &board_opt { Post::read_by_query(&ctx, board, query.clone(), page).await? } else { diff --git a/templates/base.html b/templates/base.html index 9209776..75b2019 100755 --- a/templates/base.html +++ b/templates/base.html @@ -9,14 +9,6 @@ - - - - - - - - {% block scripts %}{% endblock %}
@@ -64,5 +56,12 @@
+ + + + + + + {% block scripts %}{% endblock %}