init tera layout

This commit is contained in:
yggverse 2025-08-05 13:01:27 +03:00
parent 0d155d6ef2
commit 8a32bdda63
6 changed files with 166 additions and 12 deletions

View file

@ -12,16 +12,40 @@ use rocket::{
State,
http::Status,
response::{content::RawXml, status::Custom},
serde::Serialize,
};
use rocket_dyn_templates::{Template, context};
use storage::{Order, Sort, Storage};
use url::Url;
#[derive(Clone, Debug, Serialize)]
#[serde(crate = "rocket::serde")]
pub struct Meta {
pub canonical: Option<Url>,
pub description: Option<String>,
pub stats: Option<Url>,
pub title: String,
pub trackers: Option<Vec<Url>>,
}
#[get("/")]
pub fn index() -> &'static str {
"Catalog in development, use /rss"
fn index(storage: &State<Storage>, meta: &State<Meta>) -> Result<Template, Custom<String>> {
Ok(Template::render(
"index",
context! {
meta: meta.inner(),
torrents: storage
.torrents(
Some((Sort::Modified, Order::Asc)),
Some(storage.default_limit),
)
.map_err(|e| Custom(Status::InternalServerError, e.to_string()))?
},
))
}
#[get("/rss")]
pub fn rss(feed: &State<Feed>, storage: &State<Storage>) -> Result<RawXml<String>, Custom<String>> {
fn rss(feed: &State<Feed>, storage: &State<Storage>) -> Result<RawXml<String>, Custom<String>> {
let mut b = feed.transaction(1024); // @TODO
for torrent in storage
.torrents(
@ -40,13 +64,14 @@ fn rocket() -> _ {
use clap::Parser;
let config = Config::parse();
let feed = Feed::init(
config.title,
config.description,
config.link,
config.tracker.map(|u| u.into_iter().collect()), // make sure it's unique
config.title.clone(),
config.description.clone(),
config.link.clone(),
config.tracker.clone().map(|u| u.into_iter().collect()), // make sure it's unique
);
let storage = Storage::init(config.storage, config.limit, config.capacity).unwrap(); // @TODO handle
rocket::build()
.attach(Template::fairing())
.configure(rocket::Config {
port: config.port,
address: config.address,
@ -54,5 +79,12 @@ fn rocket() -> _ {
})
.manage(feed)
.manage(storage)
.manage(Meta {
canonical: config.link,
description: config.description,
stats: config.stats,
title: config.title,
trackers: config.tracker,
})
.mount("/", routes![index, rss])
}