This commit is contained in:
Sebastian Hugentobler 2024-05-08 18:11:39 +02:00
parent 47e8c74419
commit faea154ff5
Signed by: shu
GPG key ID: BB32CF3CA052C2F0
12 changed files with 533 additions and 6 deletions

View file

@ -0,0 +1,68 @@
use std::sync::Arc;
use poem::{
handler,
web::{headers::ContentType, Data, WithContentType},
IntoResponse,
};
use quick_xml::se::to_string;
use time::macros::datetime;
use crate::{
app_state::AppState,
opds::{
author::Author, content::Content, entry::Entry, feed::Feed, link::Link,
media_type::MediaType, relation::Relation,
},
};
#[handler]
pub async fn handler(state: Data<&Arc<AppState>>) -> Result<WithContentType<String>, poem::Error> {
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: datetime!(2024-05-06 19:14:54 UTC),
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: datetime!(2024-05-06 19:14:54 UTC),
icon: "favicon.ico".to_string(),
author,
links: vec![home_link, self_link],
entries: vec![books_entry],
};
let xml = feed.as_xml();
Ok(xml.with_content_type("application/atom+xml"))
}