mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
init tera layout
This commit is contained in:
parent
0d155d6ef2
commit
8a32bdda63
6 changed files with 166 additions and 12 deletions
|
|
@ -32,6 +32,10 @@ pub struct Config {
|
|||
#[arg(long)]
|
||||
pub link: Option<Url>,
|
||||
|
||||
/// Optional reference to the [Aquatic](https://github.com/greatest-ape/aquatic) stats page
|
||||
#[arg(long)]
|
||||
pub stats: Option<Url>,
|
||||
|
||||
/// Appends following tracker(s) to the magnet links
|
||||
#[arg(long)]
|
||||
pub tracker: Option<Vec<Url>>,
|
||||
|
|
|
|||
46
src/main.rs
46
src/main.rs
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use librqbit_core::{torrent_metainfo, torrent_metainfo::TorrentMetaV1Owned};
|
||||
use rocket::serde::Serialize;
|
||||
use std::{
|
||||
fs::{self, DirEntry},
|
||||
path::PathBuf,
|
||||
|
|
@ -15,14 +16,18 @@ pub enum Sort {
|
|||
pub enum Order {
|
||||
#[default]
|
||||
Asc,
|
||||
Desc,
|
||||
//Desc,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct File {
|
||||
pub name: Option<String>,
|
||||
pub length: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct Torrent {
|
||||
pub announce: Option<String>,
|
||||
pub comment: Option<String>,
|
||||
|
|
@ -171,7 +176,7 @@ impl Storage {
|
|||
match sort {
|
||||
Sort::Modified => match order {
|
||||
Order::Asc => b.sort_by(|a, b| a.0.cmp(&b.0)),
|
||||
Order::Desc => b.sort_by(|a, b| b.0.cmp(&a.0)),
|
||||
//Order::Desc => b.sort_by(|a, b| b.0.cmp(&a.0)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue