Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6a7f725c12 | |||
2533e8cef5 | |||
772d20615b | |||
0bb1677520 | |||
da4883db29 |
@ -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.6.0"
|
version = "0.8.0"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ async-recursion = "0.3.2"
|
|||||||
cached = "0.23.0"
|
cached = "0.23.0"
|
||||||
clap = { version = "2.33.3", default-features = false }
|
clap = { version = "2.33.3", default-features = false }
|
||||||
regex = "1.4.5"
|
regex = "1.4.5"
|
||||||
serde = { version = "1.0.124", features = ["derive"] }
|
serde = { version = "1.0.125", features = ["derive"] }
|
||||||
cookie = "0.15.0"
|
cookie = "0.15.0"
|
||||||
futures-lite = "1.11.3"
|
futures-lite = "1.11.3"
|
||||||
hyper = { version = "0.14.4", features = ["full"] }
|
hyper = { version = "0.14.4", features = ["full"] }
|
||||||
|
@ -49,6 +49,7 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
|
|||||||
| [libreddit.bcow.xyz](https://libreddit.bcow.xyz) | 🇺🇸 US | |
|
| [libreddit.bcow.xyz](https://libreddit.bcow.xyz) | 🇺🇸 US | |
|
||||||
| [libreddit.40two.app](https://libreddit.40two.app) | 🇳🇱 NL | |
|
| [libreddit.40two.app](https://libreddit.40two.app) | 🇳🇱 NL | |
|
||||||
| [reddit.invak.id](https://reddit.invak.id) | 🇧🇬 BG | |
|
| [reddit.invak.id](https://reddit.invak.id) | 🇧🇬 BG | |
|
||||||
|
| [reddit.phii.me](https://reddit.phii.me) | 🇺🇸 US | |
|
||||||
| [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | |
|
| [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | |
|
||||||
| [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | |
|
| [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | |
|
||||||
| [libreddit.himiko7xl2skojc6odi7hykl626gt4qki3vxdbv33u2u3af76d6k32ad.onion](http://libreddit.himiko7xl2skojc6odi7hykl626gt4qki3vxdbv33u2u3af76d6k32ad.onion) | 🇫🇮 FI | |
|
| [libreddit.himiko7xl2skojc6odi7hykl626gt4qki3vxdbv33u2u3af76d6k32ad.onion](http://libreddit.himiko7xl2skojc6odi7hykl626gt4qki3vxdbv33u2u3af76d6k32ad.onion) | 🇫🇮 FI | |
|
||||||
|
@ -209,6 +209,8 @@ async fn main() {
|
|||||||
app.at("/r/:sub/wiki").get(|r| subreddit::wiki(r).boxed());
|
app.at("/r/:sub/wiki").get(|r| subreddit::wiki(r).boxed());
|
||||||
app.at("/r/:sub/wiki/:page").get(|r| subreddit::wiki(r).boxed());
|
app.at("/r/:sub/wiki/:page").get(|r| subreddit::wiki(r).boxed());
|
||||||
|
|
||||||
|
app.at("/r/:sub/about/sidebar").get(|r| subreddit::sidebar(r).boxed());
|
||||||
|
|
||||||
app.at("/r/:sub/:sort").get(|r| subreddit::community(r).boxed());
|
app.at("/r/:sub/:sort").get(|r| subreddit::community(r).boxed());
|
||||||
|
|
||||||
// Comments handler
|
// Comments handler
|
||||||
|
@ -40,7 +40,7 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
dbg!(req.param("id").unwrap_or_default());
|
dbg!(req.param("id").unwrap_or_default());
|
||||||
|
|
||||||
let single_thread = &req.param("comment_id").is_some();
|
let single_thread = req.param("comment_id").is_some();
|
||||||
let highlighted_comment = &req.param("comment_id").unwrap_or_default();
|
let highlighted_comment = &req.param("comment_id").unwrap_or_default();
|
||||||
|
|
||||||
// Send a request to the url, receive JSON in response
|
// Send a request to the url, receive JSON in response
|
||||||
@ -57,7 +57,7 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
post,
|
post,
|
||||||
sort,
|
sort,
|
||||||
prefs: Preferences::new(req),
|
prefs: Preferences::new(req),
|
||||||
single_thread: *single_thread,
|
single_thread,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// If the Reddit API returns an error, exit and send error page to user
|
// If the Reddit API returns an error, exit and send error page to user
|
||||||
|
@ -16,19 +16,6 @@ struct SettingsTemplate {
|
|||||||
prefs: Preferences,
|
prefs: Preferences,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Default, Debug)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct Form {
|
|
||||||
theme: Option<String>,
|
|
||||||
front_page: Option<String>,
|
|
||||||
layout: Option<String>,
|
|
||||||
wide: Option<String>,
|
|
||||||
comment_sort: Option<String>,
|
|
||||||
show_nsfw: Option<String>,
|
|
||||||
redirect: Option<String>,
|
|
||||||
subscriptions: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
|
|
||||||
// Retrieve cookies from request "Cookie" header
|
// Retrieve cookies from request "Cookie" header
|
||||||
@ -63,7 +50,7 @@ pub async fn set(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
|
|
||||||
let mut res = redirect("/settings".to_string());
|
let mut res = redirect("/settings".to_string());
|
||||||
|
|
||||||
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "show_nsfw", "subscriptions"];
|
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "post_sort", "show_nsfw", "subscriptions"];
|
||||||
|
|
||||||
for name in names {
|
for name in names {
|
||||||
match form.get(name) {
|
match form.get(name) {
|
||||||
@ -98,7 +85,7 @@ pub async fn restore(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
|
|
||||||
let form = url::form_urlencoded::parse(query).collect::<HashMap<_, _>>();
|
let form = url::form_urlencoded::parse(query).collect::<HashMap<_, _>>();
|
||||||
|
|
||||||
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "show_nsfw", "subscriptions"];
|
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "post_sort", "show_nsfw", "subscriptions"];
|
||||||
|
|
||||||
let path = match form.get("redirect") {
|
let path = match form.get("redirect") {
|
||||||
Some(value) => format!("/{}/", value),
|
Some(value) => format!("/{}/", value),
|
||||||
|
@ -32,7 +32,8 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
// Build Reddit API path
|
// Build Reddit API path
|
||||||
let subscribed = cookie(&req, "subscriptions");
|
let subscribed = cookie(&req, "subscriptions");
|
||||||
let front_page = cookie(&req, "front_page");
|
let front_page = cookie(&req, "front_page");
|
||||||
let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or("hot".to_string()));
|
let post_sort = req.cookie("post_sort").map(|c| c.value().to_string()).unwrap_or("hot".to_string());
|
||||||
|
let sort = req.param("sort").unwrap_or(req.param("id").unwrap_or(post_sort));
|
||||||
|
|
||||||
let sub = req.param("sub").map(String::from).unwrap_or(if front_page == "default" || front_page.is_empty() {
|
let sub = req.param("sub").map(String::from).unwrap_or(if front_page == "default" || front_page.is_empty() {
|
||||||
if subscribed.is_empty() {
|
if subscribed.is_empty() {
|
||||||
@ -151,6 +152,25 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
|
let sub = req.param("sub").unwrap_or("reddit.com".to_string());
|
||||||
|
|
||||||
|
// Build the Reddit JSON API url
|
||||||
|
let path: String = format!("/r/{}/about.json?raw_json=1", sub);
|
||||||
|
|
||||||
|
// Send a request to the url
|
||||||
|
match json(path).await {
|
||||||
|
// If success, receive JSON in response
|
||||||
|
Ok(response) => template(WikiTemplate {
|
||||||
|
sub,
|
||||||
|
wiki: rewrite_urls(&val(&response, "description_html").replace("\\", "")),
|
||||||
|
page: "Sidebar".to_string(),
|
||||||
|
prefs: Preferences::new(req),
|
||||||
|
}),
|
||||||
|
Err(msg) => error(req, msg).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SUBREDDIT
|
// SUBREDDIT
|
||||||
async fn subreddit(sub: &str) -> Result<Subreddit, String> {
|
async fn subreddit(sub: &str) -> Result<Subreddit, String> {
|
||||||
// Build the Reddit JSON API url
|
// Build the Reddit JSON API url
|
||||||
|
@ -365,6 +365,7 @@ pub struct Preferences {
|
|||||||
pub wide: String,
|
pub wide: String,
|
||||||
pub show_nsfw: String,
|
pub show_nsfw: String,
|
||||||
pub comment_sort: String,
|
pub comment_sort: String,
|
||||||
|
pub post_sort: String,
|
||||||
pub subscriptions: Vec<String>,
|
pub subscriptions: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +379,7 @@ impl Preferences {
|
|||||||
wide: cookie(&req, "wide"),
|
wide: cookie(&req, "wide"),
|
||||||
show_nsfw: cookie(&req, "show_nsfw"),
|
show_nsfw: cookie(&req, "show_nsfw"),
|
||||||
comment_sort: cookie(&req, "comment_sort"),
|
comment_sort: cookie(&req, "comment_sort"),
|
||||||
|
post_sort: cookie(&req, "post_sort"),
|
||||||
subscriptions: cookie(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
subscriptions: cookie(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,12 @@
|
|||||||
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
|
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
<p>Content</p>
|
<p>Content</p>
|
||||||
|
<div id="post_sort">
|
||||||
|
<label for="post_sort" title="Applies only to subreddit feeds">Default subreddit post sort:</label>
|
||||||
|
<select name="post_sort">
|
||||||
|
{% call utils::options(prefs.post_sort, ["hot", "new", "top", "rising", "controversial"], "hot") %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div id="comment_sort">
|
<div id="comment_sort">
|
||||||
<label for="comment_sort">Default comment sort:</label>
|
<label for="comment_sort">Default comment sort:</label>
|
||||||
<select name="comment_sort">
|
<select name="comment_sort">
|
||||||
|
Reference in New Issue
Block a user