diff --git a/src/config.rs b/src/config.rs index 0933c21..dbd4c6a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,6 +40,12 @@ pub struct Config { #[arg(long)] pub tracker: Option>, + /// Format timestamps (on the web view) + /// + /// * tip: escape with `%%d/%%m/%%Y %%H:%%M` in the CLI/bash argument + #[arg(long, short, default_value_t = String::from("%d/%m/%Y %H:%M"))] + pub format_time: String, + /// Bind server on given host #[arg(long, short, default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))] pub address: IpAddr, diff --git a/src/main.rs b/src/main.rs index 13e79a5..9b4fbbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use url::Url; pub struct Meta { pub canonical: Option, pub description: Option, + pub format_time: String, pub stats: Option, pub title: String, pub trackers: Option>, @@ -34,8 +35,11 @@ fn index(storage: &State, meta: &State) -> Result, + indexed: String, magnet: String, + size: String, + torrent: Torrent, } Ok(Template::render( "index", @@ -49,7 +53,10 @@ fn index(storage: &State, meta: &State) -> Result>() @@ -95,6 +102,7 @@ fn rocket() -> _ { .manage(Meta { canonical: config.link, description: config.description, + format_time: config.format_time, stats: config.stats, title: config.title, trackers: config.tracker.map(|u| u.into_iter().collect()), diff --git a/src/storage.rs b/src/storage.rs index 4826374..22893da 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -40,6 +40,7 @@ pub struct Torrent { pub name: Option, pub publisher_url: Option, pub publisher: Option, + pub size: u64, /// File (modified) pub time: DateTime, } @@ -90,6 +91,7 @@ impl Storage { &fs::read(file.path()).map_err(|e| e.to_string())?, ) .map_err(|e| e.to_string())?; + b.push(Torrent { info_hash: i.info_hash.as_string(), announce: i.announce.map(|a| a.to_string()), @@ -98,6 +100,12 @@ impl Storage { creation_date: i .creation_date .map(|t| DateTime::from_timestamp_nanos(t as i64)), + size: i.info.length.unwrap_or_default() + + i.info + .files + .as_ref() + .map(|files| files.iter().map(|f| f.length).sum::()) + .unwrap_or_default(), files: i.info.files.map(|files| { let limit = 1000; // @TODO let mut b = Vec::with_capacity(files.len()); diff --git a/templates/index.html.tera b/templates/index.html.tera index 863b466..a7c91f1 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -4,7 +4,13 @@

{{ row.torrent.name }}

+ {% if row.torrent.comment %}

{{ row.torrent.comment }}

{% endif %}
+
    +
  • {{ row.indexed }}{% + if row.created %} ({{ row.created }}){% endif %}
  • {% + if row.size %}
  • {{ row.size }}
  • {% endif %} +
diff --git a/templates/layout/default.html.tera b/templates/layout/default.html.tera index 6af7a3e..2242a10 100644 --- a/templates/layout/default.html.tera +++ b/templates/layout/default.html.tera @@ -94,12 +94,45 @@ padding: 24px; } - /* controls */ - main > div > div { - float: right; + /* description */ + main > div > p { + margin: 8px 0; } - main > div > div > a> svg { + /* meta, controls */ + main > div > div { + border-top: 1px #4f536a solid; + margin-top: 16px; + overflow: hidden; + padding-top: 16px; + } + + main > div > div > ul { + list-style: none; + } + + main > div > div > ul > li { + cursor: default; + float: left; + } + + main > div > div > ul > li > span { + color: white; + font-size: smaller; + opacity: 0.7; + } + + main > div > div > ul > li > span:hover { + opacity: 1; + } + + main > div > div > ul > li:not(:last-child)::after { + content: "•"; + margin: 0 6px; + } + + main > div > div > a > svg { + float: right; vertical-align: middle; }