Compare commits
2 Commits
672c50e5c5
...
ed8b69de13
Author | SHA1 | Date | |
---|---|---|---|
ed8b69de13 | |||
c9e7566aee |
54
Cargo.lock
generated
54
Cargo.lock
generated
@ -321,9 +321,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.0"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
|
||||
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
@ -349,9 +349,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.19"
|
||||
version = "0.8.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
|
||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
@ -889,7 +889,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "little-hesinde"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
dependencies = [
|
||||
"calibre-db",
|
||||
"clap",
|
||||
@ -922,6 +922,12 @@ dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lockfree-object-pool"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.21"
|
||||
@ -1258,9 +1264,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.31.0"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
|
||||
checksum = "6f24d770aeca0eacb81ac29dfbc55ebcc09312fdd1f8bbecdc7e4a84e000e3b4"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"serde",
|
||||
@ -1572,6 +1578,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.11"
|
||||
@ -1669,18 +1681,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.59"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
|
||||
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.59"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
|
||||
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -2250,9 +2262,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "1.2.2"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed14a57c18714abaa03196c0714ed36bab969d7457f72d12fb5c2e1ced4c24ae"
|
||||
checksum = "775a2b471036342aa69bc5a602bc889cb0a06cda00477d0c69566757d5553d39"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crc32fast",
|
||||
@ -2260,5 +2272,21 @@ dependencies = [
|
||||
"displaydoc",
|
||||
"flate2",
|
||||
"indexmap 2.2.6",
|
||||
"memchr",
|
||||
"thiserror",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"lockfree-object-pool",
|
||||
"log",
|
||||
"once_cell",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "little-hesinde"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
edition = "2021"
|
||||
license = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
@ -24,8 +24,8 @@ tokio-util = "0.7.11"
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
|
||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||
quick-xml = { version = "0.34.0", features = ["serialize"] }
|
||||
|
||||
[build-dependencies]
|
||||
ignore = "0.4.22"
|
||||
zip = { version = "1.2.2", default-features = false, features = ["deflate"] }
|
||||
zip = { version = "2.1.3", default-features = false, features = ["deflate"] }
|
||||
|
@ -1,16 +1,13 @@
|
||||
//! Deal with cursor pagination.
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use super::error::HandlerError;
|
||||
use crate::templates::TEMPLATES;
|
||||
use calibre_db::data::error::DataStoreError;
|
||||
use poem::{error::InternalServerError, web::Html, IntoResponse, Response};
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
use tera::Context;
|
||||
|
||||
use crate::templates::TEMPLATES;
|
||||
|
||||
use super::error::HandlerError;
|
||||
|
||||
/// Render a tera template with paginated items and generate back and forth links.
|
||||
pub fn render<T: Serialize + Debug, F, S, P, M>(
|
||||
template: &str,
|
||||
@ -25,11 +22,18 @@ where
|
||||
P: Fn(&str) -> Result<bool, DataStoreError>,
|
||||
M: Fn(&str) -> Result<bool, DataStoreError>,
|
||||
{
|
||||
let items = fetcher().map_err(HandlerError::DataError)?;
|
||||
|
||||
let mut context = Context::new();
|
||||
context.insert("nav", template);
|
||||
|
||||
let items = fetcher().map_err(HandlerError::DataError)?;
|
||||
if items.is_empty() {
|
||||
return Ok(TEMPLATES
|
||||
.render("empty", &context)
|
||||
.map_err(InternalServerError)
|
||||
.map(Html)?
|
||||
.into_response());
|
||||
}
|
||||
|
||||
// fails already in the sql query if there is nothing returned
|
||||
let first_item = items.first().unwrap();
|
||||
let last_item = items.last().unwrap();
|
||||
|
||||
@ -42,7 +46,6 @@ where
|
||||
context.insert("has_more", &has_more);
|
||||
context.insert("backward_cursor", &backward_cursor);
|
||||
context.insert("forward_cursor", &forward_cursor);
|
||||
context.insert("nav", template);
|
||||
context.insert(template, &items);
|
||||
|
||||
Ok(TEMPLATES
|
||||
|
@ -71,7 +71,7 @@ pub mod opds {
|
||||
pub mod templates;
|
||||
|
||||
pub const APP_NAME: &str = "little-hesinde";
|
||||
pub const VERSION: &str = "0.1.4";
|
||||
pub const VERSION: &str = "0.1.5";
|
||||
|
||||
/// Internal marker data in lieu of a proper `Accept` header.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -80,7 +80,7 @@ impl Feed {
|
||||
pub fn as_xml(&self) -> Result<String, OpdsError> {
|
||||
let xml = to_string(&self)?;
|
||||
let mut reader = Reader::from_str(&xml);
|
||||
reader.trim_text(true);
|
||||
reader.config_mut().trim_text(true);
|
||||
|
||||
let declaration = BytesDecl::new("1.0", Some("UTF-8"), None);
|
||||
let mut writer = Writer::new(Cursor::new(Vec::new()));
|
||||
|
@ -13,6 +13,7 @@ pub static TEMPLATES: Lazy<Tera> = Lazy::new(|| {
|
||||
("book_list", include_str!("../templates/book_list.html")),
|
||||
("books", include_str!("../templates/books.html")),
|
||||
("series", include_str!("../templates/series.html")),
|
||||
("empty", include_str!("../templates/empty.html")),
|
||||
])
|
||||
.expect("failed to parse tera templates");
|
||||
|
||||
|
6
little-hesinde/templates/empty.html
Normal file
6
little-hesinde/templates/empty.html
Normal file
@ -0,0 +1,6 @@
|
||||
{% extends "base" %}
|
||||
{% block title %}
|
||||
{% endblock title %}
|
||||
{% block content %}
|
||||
<h2>No items</h2>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user