watchdogs/src/pages/index.rs

36 lines
882 B
Rust
Raw Normal View History

2024-12-12 20:28:11 +01:00
use maud::html;
2024-10-05 01:21:43 +02:00
use rocket::{get, State};
use serde_json::json;
2023-10-06 18:29:55 +02:00
2024-10-05 01:21:43 +02:00
use crate::library::Library;
2023-10-06 18:29:55 +02:00
2024-10-07 09:24:54 +02:00
use super::vec_to_api;
2023-10-06 18:29:55 +02:00
2024-10-05 01:21:43 +02:00
#[get("/search?<query>&<offset>")]
2024-10-07 09:24:54 +02:00
pub async fn search(
query: &str,
offset: Option<i64>,
library: &State<Library>,
) -> Option<serde_json::Value> {
const NUM_OF_RESULTS: i64 = 20;
// get start parameter for search result chunks
let start = offset.unwrap_or(0);
let mut video_matches = library.search_video(query, start, NUM_OF_RESULTS).await;
Some(json!(vec_to_api(&mut video_matches).await))
2023-10-06 18:29:55 +02:00
}
2024-10-05 01:21:43 +02:00
#[get("/d/<dir>")]
pub async fn channel_page(dir: &str, library: &State<Library>) -> Option<serde_json::Value> {
let mut dir_videos = library.get_directory_videos(dir).await;
2023-10-06 18:29:55 +02:00
2024-10-07 09:24:54 +02:00
Some(json!(vec_to_api(&mut dir_videos).await))
2023-10-06 18:29:55 +02:00
}
2024-12-12 20:28:11 +01:00
#[get("/")]
pub async fn index_page(library: &State<Library>) -> String {
unimplemented!()
}