Truncate negative scores

This commit is contained in:
spikecodes 2021-03-19 22:04:44 -07:00
parent 0d6e18d97d
commit dc7e087ed0
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
4 changed files with 14 additions and 16 deletions

View File

@ -3,7 +3,7 @@ name = "libreddit"
description = " Alternative private front-end to Reddit" description = " Alternative private front-end to Reddit"
license = "AGPL-3.0" license = "AGPL-3.0"
repository = "https://github.com/spikecodes/libreddit" repository = "https://github.com/spikecodes/libreddit"
version = "0.5.3" version = "0.5.4"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"

View File

@ -3,7 +3,6 @@ use futures_lite::{future::Boxed, FutureExt};
use hyper::{body::Buf, client, Body, Request, Response, Uri}; use hyper::{body::Buf, client, Body, Request, Response, Uri};
use serde_json::Value; use serde_json::Value;
use std::{result::Result, str::FromStr}; use std::{result::Result, str::FromStr};
// use async_recursion::async_recursion;
use crate::server::RequestExt; use crate::server::RequestExt;

View File

@ -175,6 +175,10 @@ async fn main() {
// Subreddit services // Subreddit services
app.at("/r/:sub").get(|r| subreddit::community(r).boxed()); 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/subscribe").post(|r| subreddit::subscriptions(r).boxed());
app.at("/r/:sub/unsubscribe").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 // Handle about pages
app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed()); app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed());
app.at("/:id").get(|req: Request<Body>| { app.at("/:id").get(|req: Request<Body>| match req.param("id").as_deref() {
async { // Sort front page
match req.param("id").as_deref() { Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).boxed(),
// Sort front page // Short link for post
Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).await, Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(),
// Short link for post // Error message for unknown pages
Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).await, _ => error(req, "Nothing here".to_string()).boxed(),
// Error message for unknown pages
_ => error(req, "Nothing here".to_string()).await,
}
}
.boxed()
}); });
// Default service in case no routes match // Default service in case no routes match

View File

@ -451,9 +451,9 @@ pub fn rewrite_urls(text: &str) -> String {
// Append `m` and `k` for millions and thousands respectively // Append `m` and `k` for millions and thousands respectively
pub fn format_num(num: i64) -> String { 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) format!("{}m", num / 1_000_000)
} else if num >= 1000 { } else if num >= 1000 || num <= -1000 {
format!("{}k", num / 1_000) format!("{}k", num / 1_000)
} else { } else {
num.to_string() num.to_string()