use std::sync::Arc; use poem::{ handler, web::{Data, WithContentType}, IntoResponse, }; use time::OffsetDateTime; use crate::{ app_state::AppState, handlers::error::HandlerError, opds::{ author::Author, content::Content, entry::Entry, feed::Feed, link::Link, media_type::MediaType, relation::Relation, }, }; #[handler] pub async fn handler(state: Data<&Arc>) -> Result, poem::Error> { let now = OffsetDateTime::now_utc(); let author = Author { name: "Thallian".to_string(), uri: "https://code.vanwa.ch/shu/rusty-library".to_string(), email: None, }; let home_link = Link { href: "/opds".to_string(), media_type: MediaType::Navigation, rel: Relation::Start, title: Some("Home".to_string()), count: None, }; let self_link = Link { href: "/opds".to_string(), media_type: MediaType::Navigation, rel: Relation::Myself, title: None, count: None, }; let books_entry = Entry { title: "Books".to_string(), id: "rusty:books".to_string(), updated: now, content: Content { media_type: MediaType::Text, content: "Index of all books".to_string(), }, links: vec![Link { href: "/opds/books".to_string(), media_type: MediaType::Navigation, rel: Relation::Subsection, title: None, count: None, }], }; let feed = Feed { title: "rusty-library".to_string(), id: "rusty:catalog".to_string(), updated: now, icon: "favicon.ico".to_string(), author, links: vec![home_link, self_link], entries: vec![books_entry], }; let xml = feed.as_xml().map_err(HandlerError::OpdsError)?; Ok(xml.with_content_type("application/atom+xml")) }