Skip to content

Commit 6b7c23a

Browse files
committed
Fix: incorrect download ct suffix
1 parent 54096ef commit 6b7c23a

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
use constcat::concat;
2323
use percent_encoding::{AsciiSet, CONTROLS};
2424
use reqwest::StatusCode;
25-
use serde::{Deserialize, Serialize};
25+
use serde::{Serialize, de::DeserializeOwned};
2626
use std::{
2727
borrow::Cow,
2828
collections::BTreeMap,
@@ -432,7 +432,7 @@ pub fn startup(on_remote: bool) -> Result<Vec<Mod>, Error> {
432432
Ok(input.mods)
433433
}
434434

435-
pub(crate) fn read<T: for<'de> Deserialize<'de>>(path: &str) -> Result<T, Error> {
435+
pub(crate) fn read<T: DeserializeOwned>(path: &str) -> Result<T, Error> {
436436
let file = File::open(path)?;
437437
let reader = BufReader::new(file);
438438
let data = serde_json::from_reader(reader)?;
@@ -460,10 +460,13 @@ fn write_badges(output: BTreeMap<String, ModDetails>, universal_url: &str) -> Re
460460

461461
let encoded_fields = badge_prefs.encoded_fields(universal_url, URL_ENCODE_SET);
462462

463-
writeln!(writer, "# Shields.io Badges via Nexus Badges")?;
464-
writeln!(writer, "Base template: {BADGE_URL}")?;
465-
writeln!(writer, "Data source URL: {universal_url}")?;
466-
writeln!(writer, "{badge_prefs}")?;
463+
writeln!(
464+
writer,
465+
"# Shields.io Badges via Nexus Badges\n\
466+
Base template: {BADGE_URL}\n\
467+
Data source URL: {universal_url}\n\n\
468+
{badge_prefs}\n"
469+
)?;
467470

468471
for (uid, entry) in output.into_iter() {
469472
let query = format!("$.{uid}.{}", badge_prefs.count.field_name());
@@ -475,9 +478,7 @@ fn write_badges(output: BTreeMap<String, ModDetails>, universal_url: &str) -> Re
475478
&query,
476479
&entry.url,
477480
)?;
478-
writeln!(writer)?;
479-
writeln!(writer, "Configuration:")?;
480-
writeln!(writer, "- Query: {query}")?;
481+
writeln!(writer, "\nConfiguration:\n- Query: {query}")?;
481482
if !entry.url.is_empty() {
482483
writeln!(writer, "- Link: {}", entry.url)?;
483484
}

src/models/badge_options.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ impl Default for BadgePreferences {
5353

5454
impl Display for BadgePreferences {
5555
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56-
writeln!(f, "Style preferences:")?;
57-
writeln!(f, "- Label: {}", self.label)?;
58-
writeln!(f, "- Count: {}", self.count)?;
59-
writeln!(f, "- Style: {}", self.style)?;
60-
writeln!(f, "- Format: {}", self.format)?;
61-
writeln!(f, "- Label color: {}", self.label_color)?;
56+
writeln!(
57+
f,
58+
"Style preferences:\n\
59+
- Label: {}\n\
60+
- Count: {}\n\
61+
- Style: {}\n\
62+
- Format: {}\n\
63+
- Label color: {}",
64+
self.label, self.count, self.style, self.format, self.label_color
65+
)?;
6266
if self.label_color_light_mode.is_some() && matches!(self.format, BadgeFormat::GithubHtml) {
6367
writeln!(
6468
f,
6569
"- Label color light mode: {}",
6670
self.label_color_light_mode
6771
)?;
6872
}
69-
writeln!(f, "- Color: {}", self.color)?;
70-
Ok(())
73+
write!(f, "- Color: {}", self.color)
7174
}
7275
}
7376

src/models/json_data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn format_download_ct(count: usize) -> String {
4343
}
4444

4545
let (delta, suf) = {
46-
const CT_SUF: [char; 3] = ['k', 'M', 'T'];
46+
const CT_SUF: [char; 3] = ['k', 'M', 'B'];
4747
const STEP: f64 = 1000.0;
4848

4949
let mut delta = count as f64 / STEP;
@@ -123,8 +123,8 @@ mod test {
123123
test!(6_156_000, "6.15M");
124124
test!(45_425_000, "45.4M");
125125
test!(346_425_000, "346M");
126-
test!(3_634_425_000, "3.63T");
127-
test!(999_999_999_999, "999T");
126+
test!(3_634_425_000, "3.63B");
127+
test!(999_999_999_999, "999B");
128128
test!(5_835_742_000_000, "5.8e12");
129129
test!(106_634_154_000_000, "1.1e14");
130130
test!(usize::MAX, "1.8e19");

0 commit comments

Comments
 (0)