Compare commits

...

7 Commits

Author SHA1 Message Date
56998b8332 Rewrite redd.it links 2021-06-21 22:51:50 -07:00
5418303b08 ARMV7 Docker Image (#234)
* feat: Push dockerfile.

Progress on trying to get armv7 image.

* feat: Add Dockerfile.

Using rust:slim as builder image.

* refactor: Changes to build for armv7.

* feat: Add .cargo config.

Taken from: https://medium.com/swlh/compiling-rust-for-raspberry-pi-arm-922b55dbb050

* refactor: Add environment variable for linker.

Instead of .cargo config file.

* feat: Working cross compile version.

For Armv7.

* refactor: Clean up dockerfile.

* refactor: Rename to armv7.

Rename Dockerfile.armv7rust to Dockerfile.armv7.

* feat: Add workflow to build ARMv7 docker image.

* docs: Add armv7 deployment instructions.
2021-06-21 23:03:27 +00:00
5ab41c4e6e Add r.nf instance. Closes #233 2021-06-18 23:46:20 +00:00
807b3ffeca Add artemislena.eu instance. Closes #232 2021-06-17 20:44:42 +00:00
85deb4947d Support HLS playback in search and user feeds 2021-06-11 17:38:43 -07:00
d2002c9027 Disable dysfunctional moderator list feature 2021-06-11 11:03:36 -07:00
f84f4c0326 Add Trevor instance 2021-05-31 04:55:39 +00:00
13 changed files with 186 additions and 111 deletions

39
.github/workflows/docker-armv7.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Docker ARM V7 Build
on:
push:
paths-ignore:
- "**.md"
branches:
- master
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: build_push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.armv7
platforms: linux/arm/v7
push: true
tags: spikecodes/libreddit:armv7

84
Cargo.lock generated
View File

@ -127,9 +127,9 @@ dependencies = [
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.6.1" version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
[[package]] [[package]]
name = "bytes" name = "bytes"
@ -363,9 +363,9 @@ checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
[[package]] [[package]]
name = "futures-lite" name = "futures-lite"
version = "1.11.3" version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
dependencies = [ dependencies = [
"fastrand", "fastrand",
"futures-core", "futures-core",
@ -492,9 +492,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.8" version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -506,7 +506,7 @@ dependencies = [
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project", "pin-project-lite",
"socket2", "socket2",
"tokio", "tokio",
"tower-service", "tower-service",
@ -603,13 +603,13 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.95" version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]] [[package]]
name = "libreddit" name = "libreddit"
version = "0.14.6" version = "0.14.9"
dependencies = [ dependencies = [
"askama", "askama",
"async-recursion", "async-recursion",
@ -660,9 +660,9 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.7.11" version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
@ -714,9 +714,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.7.2" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]] [[package]]
name = "openssl-probe" name = "openssl-probe"
@ -761,26 +761,6 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.6" version = "0.2.6"
@ -831,9 +811,9 @@ checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.8" version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -944,9 +924,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.2.0" version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"core-foundation", "core-foundation",
@ -957,9 +937,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework-sys" name = "security-framework-sys"
version = "2.2.0" version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -1019,9 +999,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.3.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -1126,9 +1106,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.72" version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1152,9 +1132,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.2.26" version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372" checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242"
dependencies = [ dependencies = [
"const_fn", "const_fn",
"libc", "libc",
@ -1177,9 +1157,9 @@ dependencies = [
[[package]] [[package]]
name = "time-macros-impl" name = "time-macros-impl"
version = "0.1.1" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f"
dependencies = [ dependencies = [
"proc-macro-hack", "proc-macro-hack",
"proc-macro2", "proc-macro2",
@ -1205,9 +1185,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.6.0" version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes", "bytes",
@ -1302,9 +1282,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
version = "0.1.17" version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
dependencies = [ dependencies = [
"tinyvec", "tinyvec",
] ]

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.14.6" version = "0.14.9"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"
@ -15,11 +15,11 @@ clap = { version = "2.33.3", default-features = false }
regex = "1.5.4" regex = "1.5.4"
serde = { version = "1.0.126", features = ["derive"] } serde = { version = "1.0.126", features = ["derive"] }
cookie = "0.15.0" cookie = "0.15.0"
futures-lite = "1.11.3" futures-lite = "1.12.0"
hyper = { version = "0.14.8", features = ["full"] } hyper = { version = "0.14.9", features = ["full"] }
hyper-rustls = "0.22.1" hyper-rustls = "0.22.1"
route-recognizer = "0.3.0" route-recognizer = "0.3.0"
serde_json = "1.0.64" serde_json = "1.0.64"
tokio = { version = "1.6.0", features = ["full"] } tokio = { version = "1.7.1", features = ["full"] }
time = "0.2.26" time = "0.2.27"
url = "2.2.2" url = "2.2.2"

43
Dockerfile.armv7 Normal file
View File

@ -0,0 +1,43 @@
####################################################################################################
## Builder
####################################################################################################
FROM --platform=$BUILDPLATFORM rust:slim AS builder
ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-gcc
ENV CC_armv7_unknown_linux_musleabihf=arm-linux-gnueabihf-gcc
RUN apt-get update && apt-get -y install gcc-arm-linux-gnueabihf \
binutils-arm-linux-gnueabihf \
musl-tools
RUN rustup target add armv7-unknown-linux-musleabihf
WORKDIR /libreddit
COPY . .
RUN cargo build --target armv7-unknown-linux-musleabihf --release
####################################################################################################
## Final image
####################################################################################################
FROM alpine:latest
# Import ca-certificates from builder
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
# Copy our build
COPY --from=builder /libreddit/target/armv7-unknown-linux-musleabihf/release/libreddit /usr/local/bin/libreddit
# Use an unprivileged user.
RUN adduser --home /nonexistent --no-create-home --disabled-password libreddit
USER libreddit
# Tell Docker to expose port 8080
EXPOSE 8080
# Run a healthcheck every minute to make sure Libreddit is functional
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1
CMD ["libreddit"]

View File

@ -1,6 +1,6 @@
# Libreddit # Libreddit
> An alternative private front-end to Reddit > An alternative private front-end to Reddit
![screenshot](https://i.ibb.co/QYbqTQt/libreddit-rust.png) ![screenshot](https://i.ibb.co/QYbqTQt/libreddit-rust.png)
@ -40,10 +40,13 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
| [libreddit.database.red](https://libreddit.database.red) | 🇺🇸 US | ✅ | | [libreddit.database.red](https://libreddit.database.red) | 🇺🇸 US | ✅ |
| [libreddit.exonip.de](https://libreddit.exonip.de) | 🇩🇪 DE | | | [libreddit.exonip.de](https://libreddit.exonip.de) | 🇩🇪 DE | |
| [libreddit.domain.glass](https://libreddit.domain.glass) | 🇺🇸 US | ✅ | | [libreddit.domain.glass](https://libreddit.domain.glass) | 🇺🇸 US | ✅ |
| [libreddit.trevorthalacker.com](https://libreddit.trevorthalacker.com) | 🇺🇸 US | ✅ |
| [reddit.artemislena.eu](https://reddit.artemislena.eu) | 🇩🇪 DE | |
| [r.nf](https://r.nf) | 🇩🇪 DE | ✅ |
| [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | | | [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | |
| [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | | | [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | |
| [dflv6yjt7il3n3tggf4qhcmkzbti2ppytqx3o7pjrzwgntutpewscyid.onion](http://dflv6yjt7il3n3tggf4qhcmkzbti2ppytqx3o7pjrzwgntutpewscyid.onion/) | 🇺🇸 US | | | [dflv6yjt7il3n3tggf4qhcmkzbti2ppytqx3o7pjrzwgntutpewscyid.onion](http://dflv6yjt7il3n3tggf4qhcmkzbti2ppytqx3o7pjrzwgntutpewscyid.onion) | 🇺🇸 US | |
| [kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion](http://kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion/) | 🇳🇱 NL | | | [kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion](http://kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion) | 🇳🇱 NL | |
A checkmark in the "Cloudflare" category here refers to the use of the reverse proxy, [Cloudflare](https://cloudflare). The checkmark will not be listed for a site which uses Cloudflare DNS but rather the proxying service which grants Cloudflare the ability to monitor traffic to the website. A checkmark in the "Cloudflare" category here refers to the use of the reverse proxy, [Cloudflare](https://cloudflare). The checkmark will not be listed for a site which uses Cloudflare DNS but rather the proxying service which grants Cloudflare the ability to monitor traffic to the website.
@ -162,6 +165,8 @@ docker run -d --name libreddit -p 80:8080 spikecodes/libreddit
To deploy on `arm64` platforms, simply replace `spikecodes/libreddit` in the commands above with `spikecodes/libreddit:arm`. To deploy on `arm64` platforms, simply replace `spikecodes/libreddit` in the commands above with `spikecodes/libreddit:arm`.
To deploy on `armv7` platforms, simply replace `spikecodes/libreddit` in the commands above with `spikecodes/libreddit:armv7`.
## 3) AUR ## 3) AUR
For ArchLinux users, Libreddit is available from the AUR as [`libreddit-git`](https://aur.archlinux.org/packages/libreddit-git). For ArchLinux users, Libreddit is available from the AUR as [`libreddit-git`](https://aur.archlinux.org/packages/libreddit-git).

View File

@ -1,7 +1,7 @@
// Global specifiers // Global specifiers
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![warn(clippy::pedantic, clippy::all)] #![warn(clippy::pedantic, clippy::all)]
#![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::find_map)] #![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::manual_find_map)]
// Reference local files // Reference local files
mod post; mod post;

View File

@ -53,7 +53,7 @@ pub trait ResponseExt {
impl RequestExt for Request<Body> { impl RequestExt for Request<Body> {
fn params(&self) -> Params { fn params(&self) -> Params {
self.extensions().get::<Params>().unwrap_or(&Params::new()).to_owned() self.extensions().get::<Params>().unwrap_or(&Params::new()).clone()
// self.extensions() // self.extensions()
// .get::<RequestMeta>() // .get::<RequestMeta>()
// .and_then(|meta| meta.route_params()) // .and_then(|meta| meta.route_params())
@ -171,7 +171,7 @@ impl Server {
// If a route was configured for this path // If a route was configured for this path
Ok(found) => { Ok(found) => {
let mut parammed = req; let mut parammed = req;
parammed.set_params(found.params().to_owned()); parammed.set_params(found.params().clone());
// Run the route's function // Run the route's function
let func = (found.handler().to_owned().to_owned())(parammed); let func = (found.handler().to_owned().to_owned())(parammed);

View File

@ -67,7 +67,7 @@ pub async fn set(req: Request<Body>) -> Result<Response<Body>, String> {
for &name in &PREFS { for &name in &PREFS {
match form.get(name) { match form.get(name) {
Some(value) => response.insert_cookie( Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned()) Cookie::build(name.to_owned(), value.clone())
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
@ -106,7 +106,7 @@ fn set_cookies_method(req: Request<Body>, remove_cookies: bool) -> Response<Body
for name in [PREFS.to_vec(), vec!["subscriptions"]].concat() { for name in [PREFS.to_vec(), vec!["subscriptions"]].concat() {
match form.get(name) { match form.get(name) {
Some(value) => response.insert_cookie( Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned()) Cookie::build(name.to_owned(), value.clone())
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))

View File

@ -51,10 +51,10 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
if subscribed.is_empty() { if subscribed.is_empty() {
"popular".to_string() "popular".to_string()
} else { } else {
subscribed.to_owned() subscribed.clone()
} }
} else { } else {
front_page.to_owned() front_page.clone()
}); });
let quarantined = can_access_quarantine(&req, &sub) || root; let quarantined = can_access_quarantine(&req, &sub) || root;
@ -273,11 +273,12 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
match json(path, quarantined).await { match json(path, quarantined).await {
// If success, receive JSON in response // If success, receive JSON in response
Ok(response) => template(WikiTemplate { Ok(response) => template(WikiTemplate {
wiki: format!( wiki: rewrite_urls(&val(&response, "description_html").replace("\\", "")),
"{}<hr><h1>Moderators</h1><br><ul>{}</ul>", // wiki: format!(
rewrite_urls(&val(&response, "description_html").replace("\\", "")), // "{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
moderators(&sub, quarantined).await?.join(""), // rewrite_urls(&val(&response, "description_html").replace("\\", "")),
), // moderators(&sub, quarantined).await.unwrap_or(vec!["Could not fetch moderators".to_string()]).join(""),
// ),
sub, sub,
page: "Sidebar".to_string(), page: "Sidebar".to_string(),
prefs: Preferences::new(req), prefs: Preferences::new(req),
@ -292,39 +293,39 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
} }
} }
pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> { // pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Retrieve and format the html for the moderators list // // Retrieve and format the html for the moderators list
Ok( // Ok(
moderators_list(sub, quarantined) // moderators_list(sub, quarantined)
.await? // .await?
.iter() // .iter()
.map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m)) // .map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m))
.collect(), // .collect(),
) // )
} // }
async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> { // async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Build the moderator list URL // // Build the moderator list URL
let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub); // let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub);
// Retrieve response // // Retrieve response
json(path, quarantined).await.map(|response| { // json(path, quarantined).await.map(|response| {
// Traverse json tree and format into list of strings // // Traverse json tree and format into list of strings
response["data"]["children"] // response["data"]["children"]
.as_array() // .as_array()
.unwrap_or(&Vec::new()) // .unwrap_or(&Vec::new())
.iter() // .iter()
.filter_map(|moderator| { // .filter_map(|moderator| {
let name = moderator["name"].as_str().unwrap_or_default(); // let name = moderator["name"].as_str().unwrap_or_default();
if name.is_empty() { // if name.is_empty() {
None // None
} else { // } else {
Some(name.to_string()) // Some(name.to_string())
} // }
}) // })
.collect::<Vec<_>>() // .collect::<Vec<_>>()
}) // })
} // }
// SUBREDDIT // SUBREDDIT
async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> { async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
@ -347,7 +348,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
title: esc!(&res, "title"), title: esc!(&res, "title"),
description: esc!(&res, "public_description"), description: esc!(&res, "public_description"),
info: rewrite_urls(&val(&res, "description_html").replace("\\", "")), info: rewrite_urls(&val(&res, "description_html").replace("\\", "")),
moderators: moderators_list(sub, quarantined).await?, // moderators: moderators_list(sub, quarantined).await.unwrap_or_default(),
icon: format_url(&icon), icon: format_url(&icon),
members: format_num(members), members: format_num(members),
active: format_num(active), active: format_num(active),

View File

@ -253,7 +253,7 @@ impl Post {
posts.push(Self { posts.push(Self {
id: val(post, "id"), id: val(post, "id"),
title: esc!(if title.is_empty() { fallback_title.to_owned() } else { title }), title: esc!(if title.is_empty() { fallback_title.clone() } else { title }),
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_urls(&val(post, "body_html")), body: rewrite_urls(&val(post, "body_html")),
author: Author { author: Author {
@ -362,7 +362,7 @@ pub struct Subreddit {
pub title: String, pub title: String,
pub description: String, pub description: String,
pub info: String, pub info: String,
pub moderators: Vec<String>, // pub moderators: Vec<String>,
pub icon: String, pub icon: String,
pub members: (String, String), pub members: (String, String),
pub active: (String, String), pub active: (String, String),
@ -424,7 +424,7 @@ pub fn param(path: &str, value: &str) -> Option<String> {
.into_owned() .into_owned()
.collect::<HashMap<_, _>>() .collect::<HashMap<_, _>>()
.get(value)? .get(value)?
.to_owned(), .clone(),
) )
} }
@ -518,7 +518,7 @@ pub fn format_url(url: &str) -> String {
// Rewrite Reddit links to Libreddit in body of text // Rewrite Reddit links to Libreddit in body of text
pub fn rewrite_urls(input_text: &str) -> String { pub fn rewrite_urls(input_text: &str) -> String {
let text1 = Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit).(com)/"#).map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string()); let text1 = Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit.com|redd.it)/"#).map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string());
// Rewrite external media previews to Libreddit // Rewrite external media previews to Libreddit
Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| { Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {

View File

@ -68,6 +68,10 @@
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if prefs.use_hls == "on" %}
<script src="/hls.min.js"></script>
<script src="/playHLSVideo.js"></script>
{% endif %}
<footer> <footer>
{% if params.before != "" %} {% if params.before != "" %}

View File

@ -105,14 +105,14 @@
<summary id="sidebar_label">Sidebar</summary> <summary id="sidebar_label">Sidebar</summary>
<div id="sidebar_contents"> <div id="sidebar_contents">
{{ sub.info }} {{ sub.info }}
<hr> {# <hr>
<h2>Moderators</h2> <h2>Moderators</h2>
<br> <br>
<ul> <ul>
{% for moderator in sub.moderators %} {% for moderator in sub.moderators %}
<li><a style="color: var(--accent)" href="/u/{{ moderator }}">{{ moderator }}</a></li> <li><a style="color: var(--accent)" href="/u/{{ moderator }}">{{ moderator }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul> #}
</div> </div>
</details> </details>
</aside> </aside>

View File

@ -49,8 +49,11 @@
</details> </details>
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if prefs.use_hls == "on" %}
<script src="/hls.min.js"></script>
<script src="/playHLSVideo.js"></script>
{% endif %}
</div> </div>
<footer> <footer>