Truncate negative scores
This commit is contained in:
parent
0d6e18d97d
commit
dc7e087ed0
@ -3,7 +3,7 @@ name = "libreddit"
|
||||
description = " Alternative private front-end to Reddit"
|
||||
license = "AGPL-3.0"
|
||||
repository = "https://github.com/spikecodes/libreddit"
|
||||
version = "0.5.3"
|
||||
version = "0.5.4"
|
||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
@ -3,7 +3,6 @@ use futures_lite::{future::Boxed, FutureExt};
|
||||
use hyper::{body::Buf, client, Body, Request, Response, Uri};
|
||||
use serde_json::Value;
|
||||
use std::{result::Result, str::FromStr};
|
||||
// use async_recursion::async_recursion;
|
||||
|
||||
use crate::server::RequestExt;
|
||||
|
||||
|
17
src/main.rs
17
src/main.rs
@ -175,6 +175,10 @@ async fn main() {
|
||||
// Subreddit services
|
||||
app.at("/r/:sub").get(|r| subreddit::community(r).boxed());
|
||||
|
||||
app
|
||||
.at("/r/u_:name")
|
||||
.get(|r| async move { Ok(redirect(format!("/user/{}", r.param("name").unwrap_or_default()))) }.boxed());
|
||||
|
||||
app.at("/r/:sub/subscribe").post(|r| subreddit::subscriptions(r).boxed());
|
||||
app.at("/r/:sub/unsubscribe").post(|r| subreddit::subscriptions(r).boxed());
|
||||
|
||||
@ -215,18 +219,13 @@ async fn main() {
|
||||
// Handle about pages
|
||||
app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed());
|
||||
|
||||
app.at("/:id").get(|req: Request<Body>| {
|
||||
async {
|
||||
match req.param("id").as_deref() {
|
||||
app.at("/:id").get(|req: Request<Body>| match req.param("id").as_deref() {
|
||||
// Sort front page
|
||||
Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).await,
|
||||
Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).boxed(),
|
||||
// Short link for post
|
||||
Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).await,
|
||||
Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(),
|
||||
// Error message for unknown pages
|
||||
_ => error(req, "Nothing here".to_string()).await,
|
||||
}
|
||||
}
|
||||
.boxed()
|
||||
_ => error(req, "Nothing here".to_string()).boxed(),
|
||||
});
|
||||
|
||||
// Default service in case no routes match
|
||||
|
@ -451,9 +451,9 @@ pub fn rewrite_urls(text: &str) -> String {
|
||||
|
||||
// Append `m` and `k` for millions and thousands respectively
|
||||
pub fn format_num(num: i64) -> String {
|
||||
if num >= 1_000_000 {
|
||||
if num >= 1_000_000 || num <= -1_000_000 {
|
||||
format!("{}m", num / 1_000_000)
|
||||
} else if num >= 1000 {
|
||||
} else if num >= 1000 || num <= -1000 {
|
||||
format!("{}k", num / 1_000)
|
||||
} else {
|
||||
num.to_string()
|
||||
|
Loading…
Reference in New Issue
Block a user