refactor opds to something usable
This commit is contained in:
parent
cccd3cbdc9
commit
a41dcab889
25 changed files with 636 additions and 501 deletions
|
@ -17,6 +17,7 @@ pub struct Entry {
|
|||
pub updated: OffsetDateTime,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content: Option<Content>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub author: Option<Author>,
|
||||
#[serde(rename = "link")]
|
||||
pub links: Vec<Link>,
|
||||
|
|
|
@ -8,7 +8,10 @@ use quick_xml::{
|
|||
use serde::Serialize;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use super::{author::Author, entry::Entry, error::OpdsError, link::Link};
|
||||
use super::{
|
||||
author::Author, entry::Entry, error::OpdsError, link::Link, media_type::MediaType,
|
||||
relation::Relation,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename = "feed")]
|
||||
|
@ -26,6 +29,42 @@ pub struct Feed {
|
|||
}
|
||||
|
||||
impl Feed {
|
||||
pub fn create(
|
||||
now: OffsetDateTime,
|
||||
id: &str,
|
||||
title: &str,
|
||||
self_link: Link,
|
||||
mut additional_links: Vec<Link>,
|
||||
entries: Vec<Entry>,
|
||||
) -> Self {
|
||||
let author = Author {
|
||||
name: "Thallian".to_string(),
|
||||
uri: "https://code.vanwa.ch/shu/rusty-library".to_string(),
|
||||
email: None,
|
||||
};
|
||||
let mut links = vec![
|
||||
Link {
|
||||
href: "/opds".to_string(),
|
||||
media_type: MediaType::Navigation,
|
||||
rel: Relation::Start,
|
||||
title: Some("Home".to_string()),
|
||||
count: None,
|
||||
},
|
||||
self_link,
|
||||
];
|
||||
links.append(&mut additional_links);
|
||||
|
||||
Self {
|
||||
title: title.to_string(),
|
||||
id: id.to_string(),
|
||||
updated: now,
|
||||
icon: "favicon.ico".to_string(),
|
||||
author,
|
||||
links,
|
||||
entries,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_xml(&self) -> Result<String, OpdsError> {
|
||||
let xml = to_string(&self)?;
|
||||
let mut reader = Reader::from_str(&xml);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue