Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make first first and last sat in range clickable #3903

Merged
merged 6 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 4 additions & 65 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
InputHtml, InscriptionHtml, InscriptionsBlockHtml, InscriptionsHtml, OutputHtml, PageContent,
PageHtml, ParentsHtml, PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml,
PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml,
PreviewVideoHtml, RangeHtml, RareTxt, RuneHtml, RunesHtml, SatHtml, TransactionHtml,
PreviewVideoHtml, RareTxt, RuneHtml, RunesHtml, SatHtml, TransactionHtml,
},
axum::{
body,
Expand All @@ -29,7 +29,7 @@ use {
caches::DirCache,
AcmeConfig,
},
std::{cmp::Ordering, str, sync::Arc},
std::{str, sync::Arc},
tokio_stream::StreamExt,
tower_http::{
compression::CompressionLayer,
Expand Down Expand Up @@ -254,7 +254,6 @@ impl Server {
"/r/sat/:sat_number/at/:index",
get(Self::sat_inscription_at_index),
)
.route("/range/:start/:end", get(Self::range))
.route("/rare.txt", get(Self::rare_txt))
.route("/rune/:rune", get(Self::rune))
.route("/runes", get(Self::runes))
Expand Down Expand Up @@ -654,22 +653,6 @@ impl Server {
})
}

async fn range(
Extension(server_config): Extension<Arc<ServerConfig>>,
Path((DeserializeFromStr(start), DeserializeFromStr(end))): Path<(
DeserializeFromStr<Sat>,
DeserializeFromStr<Sat>,
)>,
) -> ServerResult<PageHtml<RangeHtml>> {
match start.cmp(&end) {
Ordering::Equal => Err(ServerError::BadRequest("empty range".to_string())),
Ordering::Greater => Err(ServerError::BadRequest(
"range start greater than range end".to_string(),
)),
Ordering::Less => Ok(RangeHtml { start, end }.page(server_config)),
}
}

async fn rare_txt(Extension(index): Extension<Arc<Index>>) -> ServerResult<RareTxt> {
task::block_in_place(|| Ok(RareTxt(index.rare_sat_satpoints()?)))
}
Expand Down Expand Up @@ -3677,50 +3660,6 @@ mod tests {
assert_eq!(response.text().unwrap(), "1231006505");
}

#[test]
fn range_end_before_range_start_returns_400() {
TestServer::new().assert_response(
"/range/1/0",
StatusCode::BAD_REQUEST,
"range start greater than range end",
);
}

#[test]
fn invalid_range_start_returns_400() {
TestServer::new().assert_response(
"/range/=/0",
StatusCode::BAD_REQUEST,
"Invalid URL: failed to parse sat `=`: invalid integer: invalid digit found in string",
);
}

#[test]
fn invalid_range_end_returns_400() {
TestServer::new().assert_response(
"/range/0/=",
StatusCode::BAD_REQUEST,
"Invalid URL: failed to parse sat `=`: invalid integer: invalid digit found in string",
);
}

#[test]
fn empty_range_returns_400() {
TestServer::new().assert_response("/range/0/0", StatusCode::BAD_REQUEST, "empty range");
}

#[test]
fn range() {
TestServer::new().assert_response_regex(
"/range/0/1",
StatusCode::OK,
r".*<title>Sat Range 0–1</title>.*<h1>Sat Range 0–1</h1>
<dl>
<dt>value</dt><dd>1</dd>
<dt>first</dt><dd><a href=/sat/0 class=mythic>0</a></dd>
</dl>.*",
);
}
#[test]
fn sat_number() {
TestServer::new().assert_response_regex("/sat/0", StatusCode::OK, ".*<h1>Sat 0</h1>.*");
Expand Down Expand Up @@ -3800,7 +3739,7 @@ mod tests {
</dl>
<h2>1 Sat Range</h2>
<ul class=monospace>
<li><a href=/range/0/5000000000 class=mythic>05000000000</a></li>
<li><a href=/sat/0 class=mythic>0</a>-<a href=/sat/5000000000>5000000000</a><a href=/range/0/5000000000> \\(5000000000 sats\\)</a></li>
</ul>.*"
),
);
Expand Down Expand Up @@ -3866,7 +3805,7 @@ mod tests {
</dl>
<h2>1 Sat Range</h2>
<ul class=monospace>
<li><a href=/range/5000000000/10000000000 class=uncommon>500000000010000000000</a></li>
<li><a href=/sat/5000000000 class=uncommon>5000000000</a>-<a href=/sat/10000000000>10000000000</a><a href=/range/5000000000/10000000000> \\(5000000000 sats\\)</a></li>
</ul>.*"
),
);
Expand Down
2 changes: 0 additions & 2 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub(crate) use {
PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml,
PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml,
},
range::RangeHtml,
rare::RareTxt,
sat::SatHtml,
};
Expand All @@ -46,7 +45,6 @@ mod metadata;
pub mod output;
mod parents;
mod preview;
mod range;
mod rare;
pub mod rune;
pub mod runes;
Expand Down
4 changes: 2 additions & 2 deletions src/templates/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {
<h2>2 Sat Ranges</h2>
<ul class=monospace>
<li><a href=/sat/0 class=mythic>0</a></li>
<li><a href=/range/1/3 class=common>1–3</a></li>
<li><a href=/sat/1 class=common>1</a>-<a href=/sat/3>3</a><a href=/range/1/3> \\(2 sats\\)</a></li>
</ul>
"
.unindent()
Expand Down Expand Up @@ -107,7 +107,7 @@ mod tests {
<h2>2 Sat Ranges</h2>
<ul class=monospace>
<li><a href=/sat/0 class=mythic>0</a></li>
<li><a href=/range/1/3 class=common>1–3</a></li>
<li><a href=/sat/1 class=common>1</a>-<a href=/sat/3>3</a><a href=/range/1/3> \\(2 sats\\)</a></li>
</ul>
"
.unindent()
Expand Down
56 changes: 0 additions & 56 deletions src/templates/range.rs

This file was deleted.

5 changes: 3 additions & 2 deletions templates/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ <h1>Output <span class=monospace>{{self.outpoint}}</span></h1>
<h2>{{"Sat Range".tally(sat_ranges.len())}}</h2>
<ul class=monospace>
%% for (start, end) in sat_ranges {
%% if end - start == 1 {
%% let value = end - start;
%% if value == 1 {
<li><a href=/sat/{{start}} class={{Sat(*start).rarity()}}>{{start}}</a></li>
%% } else {
<li><a href=/range/{{start}}/{{end}} class={{Sat(*start).rarity()}}>{{start}}{{end}}</a></li>
<li><a href=/sat/{{start}} class={{Sat(*start).rarity()}}>{{start}}</a>-<a href=/sat/{{end}}>{{end}}</a><a href=/range/{{start}}/{{end}}> ({{value}} sats)</a></li>
%% }
%% }
</ul>
Expand Down
5 changes: 0 additions & 5 deletions templates/range.html

This file was deleted.

Loading