diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-29 11:10:21 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-29 11:10:21 +0200 |
commit | f62c7f2a8cc143454779dc99334ca9fc80ddabd5 (patch) | |
tree | f31dbb908715d2deb2860e2097fa13dd41d759d5 /server/src/ui/search.rs | |
parent | 73d2d5eb01fceae9e0b1c58afb648822000c878a (diff) | |
download | jellything-f62c7f2a8cc143454779dc99334ca9fc80ddabd5.tar jellything-f62c7f2a8cc143454779dc99334ca9fc80ddabd5.tar.bz2 jellything-f62c7f2a8cc143454779dc99334ca9fc80ddabd5.tar.zst |
still just moving code around
Diffstat (limited to 'server/src/ui/search.rs')
-rw-r--r-- | server/src/ui/search.rs | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/server/src/ui/search.rs b/server/src/ui/search.rs index 51fdcb8..bacaaee 100644 --- a/server/src/ui/search.rs +++ b/server/src/ui/search.rs @@ -3,17 +3,19 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use super::{ - error::MyResult, - layout::{trs, DynLayoutPage, LayoutPage}, - node::{DatabaseNodeUserDataExt, NodeCard}, -}; -use crate::{api::AcceptJson, locale::AcceptLanguage, logic::session::Session}; +use super::error::MyResult; +use crate::{api::AcceptJson, locale::AcceptLanguage}; use anyhow::anyhow; -use jellybase::{database::Database, locale::tr}; -use jellycommon::{api::ApiSearchResponse, Visibility}; -use rocket::{get, serde::json::Json, Either, State}; -use std::time::Instant; +use jellybase::database::Database; +use jellycommon::api::ApiSearchResponse; +use jellyimport::is_importing; +use jellylogic::{search::search, session::Session}; +use jellyui::{ + render_page, + scaffold::{RenderInfo, SessionInfo}, + search::SearchPage, +}; +use rocket::{get, response::content::RawHtml, serde::json::Json, Either, State}; #[get("/search?<query>&<page>")] pub async fn r_search<'a>( @@ -23,15 +25,30 @@ pub async fn r_search<'a>( query: Option<&str>, page: Option<usize>, lang: AcceptLanguage, -) -> MyResult<Either<DynLayoutPage<'a>, Json<ApiSearchResponse>>> { +) -> MyResult<Either<RawHtml<String>, Json<ApiSearchResponse>>> { let AcceptLanguage(lang) = lang; - + + let r = query + .map(|query| search(db, &session, query, page)) + .transpose()?; + Ok(if *aj { - let Some((count, results, _)) = results else { + let Some(r) = r else { Err(anyhow!("no query"))? }; - Either::Right(Json(ApiSearchResponse { count, results })) + Either::Right(Json(r)) } else { - Either::Left() + Either::Left(RawHtml(render_page( + &SearchPage { + lang: &lang, + query: &query.map(|s| s.to_string()), + r, + }, + RenderInfo { + importing: is_importing(), + session: Some(SessionInfo { user: session.user }), + }, + lang, + ))) }) } |