Compare commits
No commits in common. "master" and "v0.29.0" have entirely different histories.
38 changed files with 747 additions and 1370 deletions
38
.github/workflows/docker-arm.yml
vendored
Normal file
38
.github/workflows/docker-arm.yml
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
name: Docker ARM Build
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build-docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up 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
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.arm
|
||||
platforms: linux/arm64
|
||||
push: true
|
||||
tags: libreddit/libreddit:arm
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
41
.github/workflows/docker-armv7.yml
vendored
Normal file
41
.github/workflows/docker-armv7.yml
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
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: libreddit/libreddit:armv7
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
|
@ -1,58 +1,44 @@
|
|||
name: Docker Build
|
||||
name: Docker amd64 Build
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
branches:
|
||||
- 'main'
|
||||
- 'master'
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build-docker:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
config:
|
||||
- { platform: 'linux/amd64', tag: 'latest', dockerfile: 'Dockerfile' }
|
||||
- { platform: 'linux/arm64', tag: 'latest-arm', dockerfile: 'Dockerfile.arm' }
|
||||
- { platform: 'linux/arm/v7', tag: 'latest-armv7', dockerfile: 'Dockerfile.armv7' }
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
if: matrix.config.platform == 'linux/amd64'
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
repository: libreddit/libreddit
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./${{ matrix.config.dockerfile }}
|
||||
platforms: ${{ matrix.config.platform }}
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: libreddit/libreddit:${{ matrix.config.tag }}
|
||||
tags: libreddit/libreddit:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
78
.github/workflows/main-rust.yml
vendored
78
.github/workflows/main-rust.yml
vendored
|
@ -1,78 +0,0 @@
|
|||
name: Rust Build & Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
|
||||
branches:
|
||||
- 'main'
|
||||
- 'master'
|
||||
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Cache Packages
|
||||
uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
# Building actions
|
||||
- name: Build
|
||||
run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu
|
||||
|
||||
- name: Calculate SHA512 checksum
|
||||
run: sha512sum target/x86_64-unknown-linux-gnu/release/libreddit > libreddit.sha512
|
||||
|
||||
- name: Calculate SHA256 checksum
|
||||
run: sha256sum target/x86_64-unknown-linux-gnu/release/libreddit > libreddit.sha256
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload a Build Artifact
|
||||
with:
|
||||
name: libreddit
|
||||
path: |
|
||||
target/x86_64-unknown-linux-gnu/release/libreddit
|
||||
libreddit.sha512
|
||||
libreddit.sha256
|
||||
|
||||
- name: Versions
|
||||
id: version
|
||||
run: echo "VERSION=$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Publishing actions
|
||||
|
||||
- name: Publish to crates.io
|
||||
if: github.event_name == 'release'
|
||||
run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: github.base_ref != 'master' && github.event_name == 'release'
|
||||
with:
|
||||
tag_name: ${{ steps.version.outputs.VERSION }}
|
||||
name: ${{ steps.version.outputs.VERSION }} - ${{ github.event.head_commit.message }}
|
||||
draft: true
|
||||
files: |
|
||||
target/x86_64-unknown-linux-gnu/release/libreddit
|
||||
libreddit.sha512
|
||||
libreddit.sha256
|
||||
body: |
|
||||
- ${{ github.event.head_commit.message }} ${{ github.sha }}
|
||||
generate_release_notes: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
62
.github/workflows/pull-request.yml
vendored
62
.github/workflows/pull-request.yml
vendored
|
@ -1,62 +0,0 @@
|
|||
name: Pull Request
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'master'
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: cargo test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Run cargo test
|
||||
run: cargo test
|
||||
|
||||
format:
|
||||
name: cargo fmt --all -- --check
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install stable toolchain with rustfmt component
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rustfmt
|
||||
|
||||
- name: Run cargo fmt
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
name: cargo clippy -- -D warnings
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install stable toolchain with clippy component
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
components: clippy
|
||||
|
||||
- name: Run cargo clippy
|
||||
run: cargo clippy -- -D warnings
|
22
.github/workflows/rust-tests.yml
vendored
Normal file
22
.github/workflows/rust-tests.yml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
59
.github/workflows/rust.yml
vendored
Normal file
59
.github/workflows/rust.yml
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Cache Packages
|
||||
uses: Swatinem/rust-cache@v1.0.1
|
||||
|
||||
- name: Build
|
||||
run: cargo build --release
|
||||
|
||||
- name: Publish to crates.io
|
||||
continue-on-error: true
|
||||
run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
- uses: actions/upload-artifact@v2.2.1
|
||||
name: Upload a Build Artifact
|
||||
with:
|
||||
name: libreddit
|
||||
path: target/release/libreddit
|
||||
|
||||
- name: Versions
|
||||
id: version
|
||||
run: |
|
||||
echo "::set-output name=version::$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')"
|
||||
echo "::set-output name=tag::$(git describe --tags)"
|
||||
|
||||
- name: Calculate SHA512 checksum
|
||||
run: sha512sum target/release/libreddit > libreddit.sha512
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: github.base_ref != 'master'
|
||||
with:
|
||||
tag_name: ${{ steps.version.outputs.version }}
|
||||
name: ${{ steps.version.outputs.version }} - ${{ github.event.head_commit.message }}
|
||||
draft: true
|
||||
files: |
|
||||
target/release/libreddit
|
||||
libreddit.sha512
|
||||
body: |
|
||||
- ${{ github.event.head_commit.message }} ${{ github.sha }}
|
||||
generate_release_notes: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,4 +1 @@
|
|||
/target
|
||||
|
||||
# Idea Files
|
||||
.idea/
|
||||
/target
|
2
.replit
2
.replit
|
@ -1,2 +1,2 @@
|
|||
run = "while :; do set -ex; nix-env -iA nixpkgs.unzip; curl -o./libreddit.zip -fsSL -- https://nightly.link/libreddit/libreddit/workflows/main-rust/master/libreddit.zip; unzip -n libreddit.zip; mv target/x86_64-unknown-linux-gnu/release/libreddit .; chmod +x libreddit; set +e; ./libreddit -H 63115200; sleep 1; done"
|
||||
run = "while :; do set -ex; curl -o./libreddit -fsSL -- https://github.com/libreddit/libreddit/releases/latest/download/libreddit ; chmod +x libreddit; set +e; ./libreddit -H 63115200; sleep 1; done"
|
||||
language = "bash"
|
||||
|
|
4
CREDITS
4
CREDITS
|
@ -21,7 +21,6 @@ Daniel Valentine <daniel@vielle.ws>
|
|||
dbrennand <52419383+dbrennand@users.noreply.github.com>
|
||||
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
|
||||
Diego Magdaleno <38844659+DiegoMagdaleno@users.noreply.github.com>
|
||||
domve <domve@posteo.net>
|
||||
Dyras <jevwmguf@duck.com>
|
||||
Edward <101938856+EdwardLangdon@users.noreply.github.com>
|
||||
elliot <75391956+ellieeet123@users.noreply.github.com>
|
||||
|
@ -59,11 +58,9 @@ Nicholas Christopher <nchristopher@tuta.io>
|
|||
Nick Lowery <ClockVapor@users.noreply.github.com>
|
||||
Nico <github@dr460nf1r3.org>
|
||||
NKIPSC <15067635+NKIPSC@users.noreply.github.com>
|
||||
o69mar <119129086+o69mar@users.noreply.github.com>
|
||||
obeho <71698631+obeho@users.noreply.github.com>
|
||||
obscurity <z@x4.pm>
|
||||
Om G <34579088+OxyMagnesium@users.noreply.github.com>
|
||||
pin <90570748+0323pin@users.noreply.github.com>
|
||||
potatoesAreGod <118043038+potatoesAreGod@users.noreply.github.com>
|
||||
RiversideRocks <59586759+RiversideRocks@users.noreply.github.com>
|
||||
robin <8597693+robrobinbin@users.noreply.github.com>
|
||||
|
@ -91,6 +88,5 @@ Tsvetomir Bonev <invakid404@riseup.net>
|
|||
Vladislav Nepogodin <nepogodin.vlad@gmail.com>
|
||||
Walkx <walkxnl@gmail.com>
|
||||
Wichai <1482605+Chengings@users.noreply.github.com>
|
||||
wsy2220 <wsy@dogben.com>
|
||||
xatier <xatierlike@gmail.com>
|
||||
Zach <72994911+zachjmurphy@users.noreply.github.com>
|
||||
|
|
775
Cargo.lock
generated
775
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
14
Cargo.toml
14
Cargo.toml
|
@ -3,20 +3,20 @@ name = "libreddit"
|
|||
description = " Alternative private front-end to Reddit"
|
||||
license = "AGPL-3.0"
|
||||
repository = "https://github.com/spikecodes/libreddit"
|
||||
version = "0.30.1"
|
||||
version = "0.29.0"
|
||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
askama = { version = "0.12.0", default-features = false }
|
||||
cached = "0.43.0"
|
||||
askama = { version = "0.11.1", default-features = false }
|
||||
cached = "0.42.0"
|
||||
clap = { version = "4.1.1", default-features = false, features = ["std", "env"] }
|
||||
regex = "1.7.1"
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
cookie = "0.17.0"
|
||||
cookie = "0.16.2"
|
||||
futures-lite = "1.12.0"
|
||||
hyper = { version = "0.14.23", features = ["full"] }
|
||||
hyper-rustls = "0.24.0"
|
||||
hyper-rustls = "0.23.2"
|
||||
percent-encoding = "2.2.0"
|
||||
route-recognizer = "0.3.1"
|
||||
serde_json = "1.0.91"
|
||||
|
@ -26,13 +26,13 @@ url = "2.3.1"
|
|||
rust-embed = { version = "6.4.2", features = ["include-exclude"] }
|
||||
libflate = "1.2.0"
|
||||
brotli = { version = "3.3.4", features = ["std"] }
|
||||
toml = "0.7.4"
|
||||
toml = "0.5.10"
|
||||
once_cell = "1.17.0"
|
||||
serde_yaml = "0.9.16"
|
||||
build_html = "2.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
lipsum = "0.9.0"
|
||||
lipsum = "0.8.2"
|
||||
sealed_test = "1.0.0"
|
||||
|
||||
[profile.release]
|
||||
|
|
|
@ -7,10 +7,6 @@ RUN apk add --no-cache g++ git
|
|||
|
||||
WORKDIR /usr/src/libreddit
|
||||
|
||||
# cache dependencies in their own layer
|
||||
COPY Cargo.lock Cargo.toml .
|
||||
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo install --config net.git-fetch-with-cli=true --path . && rm -rf ./src
|
||||
|
||||
COPY . .
|
||||
|
||||
# net.git-fetch-with-cli is specified in order to prevent a potential OOM kill
|
||||
|
|
87
README.md
87
README.md
|
@ -2,15 +2,11 @@
|
|||
|
||||
> An alternative private front-end to Reddit
|
||||
|
||||
# ⚠️ Why do I get TOO MANY REQUESTS errors? ⚠️
|
||||
## As of July 12th, 2023, Libreddit is currently not operational as Reddit's API changes, that were designed to kill third-party apps and content scrapers who don't pay [large fees](https://www.theverge.com/2023/5/31/23743993/reddit-apollo-client-api-cost), went into effect. [Read the full announcement here.](https://github.com/libreddit/libreddit/issues/840)
|
||||
## One of the project maintainers is working towards keeping this project alive to some extent: https://github.com/libreddit/libreddit/issues/836
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
**10-second pitch:** Libreddit is a portmanteau of "libre" (meaning freedom) and "Reddit". It is a private front-end like [Invidious](https://github.com/iv-org/invidious) but for Reddit. Browse the coldest takes of [r/unpopularopinion](https://libreddit.spike.codes/r/unpopularopinion) without being [tracked](#reddit).
|
||||
**10 second pitch:** Libreddit is a portmanteau of "libre" (meaning freedom) and "Reddit". It is a private front-end like [Invidious](https://github.com/iv-org/invidious) but for Reddit. Browse the coldest takes of [r/unpopularopinion](https://libreddit.spike.codes/r/unpopularopinion) without being [tracked](#reddit).
|
||||
|
||||
- 🚀 Fast: written in Rust for blazing-fast speeds and memory safety
|
||||
- ☁️ Light: no JavaScript, no ads, no tracking, no bloat
|
||||
|
@ -35,7 +31,7 @@ I appreciate any donations! Your support allows me to continue developing Libred
|
|||
|
||||
🔗 **Want to automatically redirect Reddit links to Libreddit? Use [LibRedirect](https://github.com/libredirect/libredirect) or [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect)!**
|
||||
|
||||
[Follow this link](https://github.com/libreddit/libreddit-instances/blob/master/instances.md) for an up-to-date table of instances in Markdown format. This list is also available as [a machine-readable JSON](https://github.com/libreddit/libreddit-instances/blob/master/instances.json).
|
||||
[Follow this link](https://github.com/libreddit/libreddit-instances/blob/master/instances.md) for an up-to-date table of instances in markdown format. This list is also available as [a machine-readable JSON](https://github.com/libreddit/libreddit-instances/blob/master/instances.json).
|
||||
|
||||
Both files are part of the [libreddit-instances](https://github.com/libreddit/libreddit-instances) repository. To contribute your [self-hosted instance](#deployment) to the list, see the [libreddit-instances README](https://github.com/libreddit/libreddit-instances/blob/master/README.md).
|
||||
|
||||
|
@ -59,7 +55,7 @@ Libreddit currently implements most of Reddit's (signed-out) functionalities but
|
|||
|
||||
## How does it compare to Teddit?
|
||||
|
||||
Teddit is another awesome open source project designed to provide an alternative frontend to Reddit. There is no connection between the two, and you're welcome to use whichever one you favor. Competition fosters innovation and Teddit's release has motivated me to build Libreddit into an even more polished product.
|
||||
Teddit is another awesome open source project designed to provide an alternative frontend to Reddit. There is no connection between the two and you're welcome to use whichever one you favor. Competition fosters innovation and Teddit's release has motivated me to build Libreddit into an even more polished product.
|
||||
|
||||
If you are looking to compare, the biggest differences I have noticed are:
|
||||
- Libreddit is themed around Reddit's redesign whereas Teddit appears to stick much closer to Reddit's old design. This may suit some users better as design is always subjective.
|
||||
|
@ -118,21 +114,13 @@ Results from Google PageSpeed Insights ([Libreddit Report](https://pagespeed.web
|
|||
|
||||
For transparency, I hope to describe all the ways Libreddit handles user privacy.
|
||||
|
||||
#### Server
|
||||
**Logging:** In production (when running the binary, hosting with docker, or using the official instances), Libreddit logs nothing. When debugging (running from source without `--release`), Libreddit logs post IDs fetched to aid with troubleshooting.
|
||||
|
||||
* **Logging:** In production (when running the binary, hosting with docker, or using the official instances), Libreddit logs nothing. When debugging (running from source without `--release`), Libreddit logs post IDs fetched to aid with troubleshooting.
|
||||
**DNS:** Both official domains (`libredd.it` and `libreddit.spike.codes`) use Cloudflare as the DNS resolver. Though, the sites are not proxied through Cloudflare meaning Cloudflare doesn't have access to user traffic.
|
||||
|
||||
* **Cookies:** Libreddit uses optional cookies to store any configured settings in [the settings menu](https://libreddit.spike.codes/settings). These are not cross-site cookies and the cookies hold no personal data.
|
||||
**Cookies:** Libreddit uses optional cookies to store any configured settings in [the settings menu](https://libreddit.spike.codes/settings). These are not cross-site cookies and the cookies hold no personal data.
|
||||
|
||||
#### Official instance (libreddit.spike.codes)
|
||||
|
||||
The official instance is hosted at https://libreddit.spike.codes.
|
||||
|
||||
* **Server:** The official instance runs a production binary, and thus logs nothing.
|
||||
|
||||
* **DNS:** The domain for the official instance uses Cloudflare as the DNS resolver. However, this site is not proxied through Cloudflare, and thus Cloudflare doesn't have access to user traffic.
|
||||
|
||||
* **Hosting:** The official instance is hosted on [Replit](https://replit.com/), which monitors usage to prevent abuse. I can understand if this invalidates certain users' threat models, and therefore, self-hosting, using unofficial instances, and browsing through Tor are welcomed.
|
||||
**Hosting:** The official instances are hosted on [Replit](https://replit.com/) which monitors usage to prevent abuse. I can understand if this invalidates certain users' threat models and therefore, self-hosting, using unofficial instances, and browsing through Tor are welcomed.
|
||||
|
||||
---
|
||||
|
||||
|
@ -171,29 +159,15 @@ For ArchLinux users, Libreddit is available from the AUR as [`libreddit-git`](ht
|
|||
```
|
||||
yay -S libreddit-git
|
||||
```
|
||||
## 4) NetBSD/pkgsrc
|
||||
|
||||
For NetBSD users, Libreddit is available from the official repositories.
|
||||
|
||||
```
|
||||
pkgin install libreddit
|
||||
```
|
||||
|
||||
Or, if you prefer to build from source
|
||||
|
||||
```
|
||||
cd /usr/pkgsrc/libreddit
|
||||
make install
|
||||
```
|
||||
|
||||
## 5) GitHub Releases
|
||||
## 4) GitHub Releases
|
||||
|
||||
If you're on Linux and none of these methods work for you, you can grab a Linux binary from [the newest release](https://github.com/libreddit/libreddit/releases/latest).
|
||||
|
||||
## 6) Replit/Heroku/Glitch
|
||||
## 5) Replit/Heroku/Glitch
|
||||
|
||||
> **Warning**
|
||||
> These are free hosting options, but they are *not* private and will monitor server usage to prevent abuse. If you need a free and easy setup, this method may work best for you.
|
||||
> These are free hosting options but they are *not* private and will monitor server usage to prevent abuse. If you need a free and easy setup, this method may work best for you.
|
||||
|
||||
<a href="https://repl.it/github/libreddit/libreddit"><img src="https://repl.it/badge/github/libreddit/libreddit" alt="Run on Repl.it" height="32" /></a>
|
||||
[](https://heroku.com/deploy?template=https://github.com/libreddit/libreddit)
|
||||
|
@ -213,33 +187,30 @@ libreddit
|
|||
|
||||
Assign a default value for each instance-specific setting by passing environment variables to Libreddit in the format `LIBREDDIT_{X}`. Replace `{X}` with the setting name (see list below) in capital letters.
|
||||
|
||||
| Name | Possible values | Default value | Description |
|
||||
|---------------------------|-----------------|------------------|-----------------------------------------------------------------------------------------------------------|
|
||||
| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. |
|
||||
| `BANNER` | String | (empty) | Allows the server to set a banner to be displayed. Currently this is displayed on the instance info page. |
|
||||
| `ROBOTS_DISABLE_INDEXING` | `["on", "off"]` | `off` | Disables indexing of the instance by search engines. |
|
||||
| `PUSHSHIFT_FRONTEND` | String | `www.unddit.com` | Allows the server to set the Pushshift frontend to be used with "removed" links. |
|
||||
|Name|Possible values|Default value|Description|
|
||||
|-|-|-|-|
|
||||
| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. |
|
||||
| `BANNER` | String | (empty) | Allows the server to set a banner to be displayed. Currently this is displayed on the instance info page. |
|
||||
|
||||
## Default User Settings
|
||||
|
||||
Assign a default value for each user-modifiable setting by passing environment variables to Libreddit in the format `LIBREDDIT_DEFAULT_{Y}`. Replace `{Y}` with the setting name (see list below) in capital letters.
|
||||
|
||||
| Name | Possible values | Default value |
|
||||
|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|---------------|
|
||||
| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox", "gruvboxdark", "gruvboxlight"]` | `system` |
|
||||
| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` |
|
||||
| `LAYOUT` | `["card", "clean", "compact"]` | `card` |
|
||||
| `WIDE` | `["on", "off"]` | `off` |
|
||||
| `POST_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` |
|
||||
| `COMMENT_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` |
|
||||
| `SHOW_NSFW` | `["on", "off"]` | `off` |
|
||||
| `BLUR_NSFW` | `["on", "off"]` | `off` |
|
||||
| `USE_HLS` | `["on", "off"]` | `off` |
|
||||
| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` |
|
||||
| `AUTOPLAY_VIDEOS` | `["on", "off"]` | `off` |
|
||||
| `SUBSCRIPTIONS` | `+`-delimited list of subreddits (`sub1+sub2+sub3+...`) | _(none)_ |
|
||||
| `HIDE_AWARDS` | `["on", "off"]` | `off` |
|
||||
| `DISABLE_VISIT_REDDIT_CONFIRMATION` | `["on", "off"]` | `off` |
|
||||
| Name | Possible values | Default value |
|
||||
|-------------------------|-----------------------------------------------------------------------------------------------------|---------------|
|
||||
| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox", "gruvboxdark", "gruvboxlight"]` | `system` |
|
||||
| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` |
|
||||
| `LAYOUT` | `["card", "clean", "compact"]` | `card` |
|
||||
| `WIDE` | `["on", "off"]` | `off` |
|
||||
| `POST_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` |
|
||||
| `COMMENT_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` |
|
||||
| `SHOW_NSFW` | `["on", "off"]` | `off` |
|
||||
| `BLUR_NSFW` | `["on", "off"]` | `off` |
|
||||
| `USE_HLS` | `["on", "off"]` | `off` |
|
||||
| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` |
|
||||
| `AUTOPLAY_VIDEOS` | `["on", "off"]` | `off` |
|
||||
| `HIDE_AWARDS` | `["on", "off"]` | `off`
|
||||
| `DISABLE_VISIT_REDDIT_CONFIRMATION` | `["on", "off"]` | `off` |
|
||||
|
||||
You can also configure Libreddit with a configuration file. An example `libreddit.toml` can be found below:
|
||||
|
||||
|
|
9
app.json
9
app.json
|
@ -50,17 +50,8 @@
|
|||
"LIBREDDIT_BANNER": {
|
||||
"required": false
|
||||
},
|
||||
"LIBREDDIT_ROBOTS_DISABLE_INDEXING": {
|
||||
"required": false
|
||||
},
|
||||
"LIBREDDIT_DEFAULT_SUBSCRIPTIONS": {
|
||||
"required": false
|
||||
},
|
||||
"LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION": {
|
||||
"required": false
|
||||
},
|
||||
"LIBREDDIT_PUSHSHIFT_FRONTEND": {
|
||||
"required": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
build.rs
12
build.rs
|
@ -1,11 +1,7 @@
|
|||
use std::process::{Command, ExitStatus, Output};
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::os::windows::process::ExitStatusExt;
|
||||
|
||||
use std::{
|
||||
os::unix::process::ExitStatusExt,
|
||||
process::{Command, ExitStatus, Output},
|
||||
};
|
||||
fn main() {
|
||||
let output = String::from_utf8(
|
||||
Command::new("git")
|
||||
|
|
|
@ -1,16 +1,2 @@
|
|||
ADDRESS=0.0.0.0
|
||||
PORT=12345
|
||||
#LIBREDDIT_DEFAULT_THEME=default
|
||||
#LIBREDDIT_DEFAULT_FRONT_PAGE=default
|
||||
#LIBREDDIT_DEFAULT_LAYOUT=card
|
||||
#LIBREDDIT_DEFAULT_WIDE=off
|
||||
#LIBREDDIT_DEFAULT_POST_SORT=hot
|
||||
#LIBREDDIT_DEFAULT_COMMENT_SORT=confidence
|
||||
#LIBREDDIT_DEFAULT_SHOW_NSFW=off
|
||||
#LIBREDDIT_DEFAULT_BLUR_NSFW=off
|
||||
#LIBREDDIT_DEFAULT_USE_HLS=off
|
||||
#LIBREDDIT_DEFAULT_HIDE_HLS_NOTIFICATION=off
|
||||
#LIBREDDIT_DEFAULT_AUTOPLAY_VIDEOS=off
|
||||
#LIBREDDIT_DEFAULT_SUBSCRIPTIONS=off (sub1+sub2+sub3)
|
||||
#LIBREDDIT_DEFAULT_HIDE_AWARDS=off
|
||||
#LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION=off
|
||||
|
|
|
@ -5,8 +5,8 @@ After=network.service
|
|||
[Service]
|
||||
DynamicUser=yes
|
||||
# Default Values
|
||||
#Environment=ADDRESS=0.0.0.0
|
||||
#Environment=PORT=8080
|
||||
Environment=ADDRESS=0.0.0.0
|
||||
Environment=PORT=8080
|
||||
# Optional Override
|
||||
EnvironmentFile=-/etc/libreddit.conf
|
||||
ExecStart=/usr/bin/libreddit -a ${ADDRESS} -p ${PORT}
|
||||
|
|
|
@ -7,18 +7,7 @@ services:
|
|||
container_name: "libreddit"
|
||||
ports:
|
||||
- 8080:8080
|
||||
user: nobody
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
networks:
|
||||
- libreddit
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--spider", "-q", "--tries=1", "http://localhost:8080/settings"]
|
||||
interval: 5m
|
||||
timeout: 3s
|
||||
|
||||
networks:
|
||||
libreddit:
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
use cached::proc_macro::cached;
|
||||
use futures_lite::{future::Boxed, FutureExt};
|
||||
use hyper::client::HttpConnector;
|
||||
use hyper::{body, body::Buf, client, header, Body, Client, Method, Request, Response, Uri};
|
||||
use hyper_rustls::HttpsConnector;
|
||||
use hyper::{body, body::Buf, client, header, Body, Method, Request, Response, Uri};
|
||||
use libflate::gzip;
|
||||
use once_cell::sync::Lazy;
|
||||
use percent_encoding::{percent_encode, CONTROLS};
|
||||
use serde_json::Value;
|
||||
use std::{io, result::Result};
|
||||
|
@ -14,11 +11,6 @@ use crate::server::RequestExt;
|
|||
|
||||
const REDDIT_URL_BASE: &str = "https://www.reddit.com";
|
||||
|
||||
static CLIENT: Lazy<Client<HttpsConnector<HttpConnector>>> = Lazy::new(|| {
|
||||
let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
|
||||
client::Client::builder().build(https)
|
||||
});
|
||||
|
||||
/// Gets the canonical path for a resource on Reddit. This is accomplished by
|
||||
/// making a `HEAD` request to Reddit at the path given in `path`.
|
||||
///
|
||||
|
@ -74,8 +66,11 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String
|
|||
// First parameter is target URL (mandatory).
|
||||
let uri = url.parse::<Uri>().map_err(|_| "Couldn't parse URL".to_string())?;
|
||||
|
||||
// Prepare the HTTPS connector.
|
||||
let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
|
||||
|
||||
// Build the hyper client from the HTTPS connector.
|
||||
let client: client::Client<_, hyper::Body> = CLIENT.clone();
|
||||
let client: client::Client<_, hyper::Body> = client::Client::builder().build(https);
|
||||
|
||||
let mut builder = Request::get(uri);
|
||||
|
||||
|
@ -104,8 +99,6 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String
|
|||
rm("x-cdn-server-region");
|
||||
rm("x-reddit-cdn");
|
||||
rm("x-reddit-video-features");
|
||||
rm("Nel");
|
||||
rm("Report-To");
|
||||
|
||||
res
|
||||
})
|
||||
|
@ -130,8 +123,11 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo
|
|||
// Build Reddit URL from path.
|
||||
let url = format!("{}{}", REDDIT_URL_BASE, path);
|
||||
|
||||
// Prepare the HTTPS connector.
|
||||
let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().build();
|
||||
|
||||
// Construct the hyper client from the HTTPS connector.
|
||||
let client: client::Client<_, hyper::Body> = CLIENT.clone();
|
||||
let client: client::Client<_, hyper::Body> = client::Client::builder().build(https);
|
||||
|
||||
// Build request to Reddit. When making a GET, request gzip compression.
|
||||
// (Reddit doesn't do brotli yet.)
|
||||
|
@ -144,14 +140,7 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo
|
|||
.header("Accept-Encoding", if method == Method::GET { "gzip" } else { "identity" })
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Connection", "keep-alive")
|
||||
.header(
|
||||
"Cookie",
|
||||
if quarantine {
|
||||
"_options=%7B%22pref_quarantine_optin%22%3A%20true%2C%20%22pref_gated_sr_optin%22%3A%20true%7D"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
)
|
||||
.header("Cookie", if quarantine { "_options=%7B%22pref_quarantine_optin%22%3A%20true%7D" } else { "" })
|
||||
.body(Body::empty());
|
||||
|
||||
async move {
|
||||
|
|
|
@ -9,16 +9,12 @@ use std::{env::var, fs::read_to_string};
|
|||
// first request) and contains the instance settings.
|
||||
pub(crate) static CONFIG: Lazy<Config> = Lazy::new(Config::load);
|
||||
|
||||
// This serves as the frontend for the Pushshift API - on removed comments, this URL will
|
||||
// be the base of a link, to display removed content (on another site).
|
||||
pub(crate) const DEFAULT_PUSHSHIFT_FRONTEND: &str = "www.unddit.com";
|
||||
|
||||
/// Stores the configuration parsed from the environment variables and the
|
||||
/// config file. `Config::Default()` contains None for each setting.
|
||||
/// When adding more config settings, add it to `Config::load`,
|
||||
/// `get_setting_from_config`, both below, as well as
|
||||
/// instance_info::InstanceInfo.to_string(), README.md and app.json.
|
||||
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
#[serde(rename = "LIBREDDIT_SFW_ONLY")]
|
||||
pub(crate) sfw_only: Option<String>,
|
||||
|
@ -56,20 +52,8 @@ pub struct Config {
|
|||
#[serde(rename = "LIBREDDIT_DEFAULT_HIDE_AWARDS")]
|
||||
pub(crate) default_hide_awards: Option<String>,
|
||||
|
||||
#[serde(rename = "LIBREDDIT_DEFAULT_SUBSCRIPTIONS")]
|
||||
pub(crate) default_subscriptions: Option<String>,
|
||||
|
||||
#[serde(rename = "LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")]
|
||||
pub(crate) default_disable_visit_reddit_confirmation: Option<String>,
|
||||
|
||||
#[serde(rename = "LIBREDDIT_BANNER")]
|
||||
pub(crate) banner: Option<String>,
|
||||
|
||||
#[serde(rename = "LIBREDDIT_ROBOTS_DISABLE_INDEXING")]
|
||||
pub(crate) robots_disable_indexing: Option<String>,
|
||||
|
||||
#[serde(rename = "LIBREDDIT_PUSHSHIFT_FRONTEND")]
|
||||
pub(crate) pushshift: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -84,7 +68,6 @@ impl Config {
|
|||
// environment variables with "LIBREDDIT", then check the config, then if
|
||||
// both are `None`, return a `None` via the `map_or_else` function
|
||||
let parse = |key: &str| -> Option<String> { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) };
|
||||
|
||||
Self {
|
||||
sfw_only: parse("LIBREDDIT_SFW_ONLY"),
|
||||
default_theme: parse("LIBREDDIT_DEFAULT_THEME"),
|
||||
|
@ -98,11 +81,7 @@ impl Config {
|
|||
default_use_hls: parse("LIBREDDIT_DEFAULT_USE_HLS"),
|
||||
default_hide_hls_notification: parse("LIBREDDIT_DEFAULT_HIDE_HLS"),
|
||||
default_hide_awards: parse("LIBREDDIT_DEFAULT_HIDE_AWARDS"),
|
||||
default_subscriptions: parse("LIBREDDIT_DEFAULT_SUBSCRIPTIONS"),
|
||||
default_disable_visit_reddit_confirmation: parse("LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"),
|
||||
banner: parse("LIBREDDIT_BANNER"),
|
||||
robots_disable_indexing: parse("LIBREDDIT_ROBOTS_DISABLE_INDEXING"),
|
||||
pushshift: parse("LIBREDDIT_PUSHSHIFT_FRONTEND"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +100,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option<String> {
|
|||
"LIBREDDIT_DEFAULT_HIDE_HLS_NOTIFICATION" => config.default_hide_hls_notification.clone(),
|
||||
"LIBREDDIT_DEFAULT_WIDE" => config.default_wide.clone(),
|
||||
"LIBREDDIT_DEFAULT_HIDE_AWARDS" => config.default_hide_awards.clone(),
|
||||
"LIBREDDIT_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(),
|
||||
"LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(),
|
||||
"LIBREDDIT_BANNER" => config.banner.clone(),
|
||||
"LIBREDDIT_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(),
|
||||
"LIBREDDIT_PUSHSHIFT_FRONTEND" => config.pushshift.clone(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -138,13 +113,6 @@ pub(crate) fn get_setting(name: &str) -> Option<String> {
|
|||
#[cfg(test)]
|
||||
use {sealed_test::prelude::*, std::fs::write};
|
||||
|
||||
#[test]
|
||||
fn test_deserialize() {
|
||||
// Must handle empty input
|
||||
let result = toml::from_str::<Config>("");
|
||||
assert!(result.is_ok(), "Error: {}", result.unwrap_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[sealed_test(env = [("LIBREDDIT_SFW_ONLY", "on")])]
|
||||
fn test_env_var() {
|
||||
|
@ -174,8 +142,3 @@ fn test_alt_env_config_precedence() {
|
|||
write("libreddit.toml", config_to_write).unwrap();
|
||||
assert_eq!(get_setting("LIBREDDIT_DEFAULT_COMMENT_SORT"), Some("top".into()))
|
||||
}
|
||||
#[test]
|
||||
#[sealed_test(env = [("LIBREDDIT_DEFAULT_SUBSCRIPTIONS", "news+bestof")])]
|
||||
fn test_default_subscriptions() {
|
||||
assert_eq!(get_setting("LIBREDDIT_DEFAULT_SUBSCRIPTIONS"), Some("news+bestof".into()));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::client::json;
|
||||
use crate::server::RequestExt;
|
||||
use crate::subreddit::{can_access_quarantine, quarantine};
|
||||
use crate::utils::{error, filter_posts, get_filters, nsfw_landing, parse_post, template, Post, Preferences};
|
||||
use crate::utils::{error, filter_posts, get_filters, nsfw_landing, parse_post, setting, template, Post, Preferences};
|
||||
|
||||
use askama::Template;
|
||||
use hyper::{Body, Request, Response};
|
||||
|
@ -67,12 +67,11 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
Ok(response) => {
|
||||
let post = parse_post(&response[0]["data"]["children"][0]).await;
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this post
|
||||
// NSFW, but we have also disabled the display of NSFW content
|
||||
// or if the instance is SFW-only
|
||||
if post.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
// or if the instance is SFW-only.
|
||||
if post.nsfw && (setting(&req, "show_nsfw") != "on" || crate::utils::sfw_only()) {
|
||||
return Ok(nsfw_landing(req).await.unwrap_or_default());
|
||||
}
|
||||
|
||||
let filters = get_filters(&req);
|
||||
|
@ -196,13 +195,14 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
after = response[1]["data"]["after"].as_str().unwrap_or_default().to_string();
|
||||
}
|
||||
}
|
||||
let url = req.uri().to_string();
|
||||
|
||||
template(DuplicatesTemplate {
|
||||
params: DuplicatesParams { before, after, sort },
|
||||
post,
|
||||
duplicates,
|
||||
prefs: Preferences::new(&req),
|
||||
url: req_url,
|
||||
url,
|
||||
num_posts_filtered,
|
||||
all_posts_filtered,
|
||||
})
|
||||
|
@ -210,9 +210,9 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
|
||||
// Process error.
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
if msg == "quarantined" {
|
||||
let sub = req.param("sub").unwrap_or_default();
|
||||
quarantine(req, sub, msg)
|
||||
quarantine(req, sub)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
|
|
@ -122,8 +122,6 @@ impl InstanceInfo {
|
|||
["Deploy timestamp", &self.deploy_unix_ts.to_string()],
|
||||
["Compile mode", &self.compile_mode],
|
||||
["SFW only", &convert(&self.config.sfw_only)],
|
||||
["Pushshift frontend", &convert(&self.config.pushshift)],
|
||||
//TODO: fallback to crate::config::DEFAULT_PUSHSHIFT_FRONTEND
|
||||
])
|
||||
.with_header_row(["Settings"]),
|
||||
);
|
||||
|
@ -141,7 +139,6 @@ impl InstanceInfo {
|
|||
["Blur NSFW", &convert(&self.config.default_blur_nsfw)],
|
||||
["Use HLS", &convert(&self.config.default_use_hls)],
|
||||
["Hide HLS notification", &convert(&self.config.default_hide_hls_notification)],
|
||||
["Subscriptions", &convert(&self.config.default_subscriptions)],
|
||||
])
|
||||
.with_header_row(["Default preferences"]),
|
||||
);
|
||||
|
@ -156,11 +153,10 @@ impl InstanceInfo {
|
|||
Deploy date: {}\n
|
||||
Deploy timestamp: {}\n
|
||||
Compile mode: {}\n
|
||||
SFW only: {:?}\n
|
||||
Pushshift frontend: {:?}\n
|
||||
Config:\n
|
||||
Banner: {:?}\n
|
||||
Hide awards: {:?}\n
|
||||
SFW only: {:?}\n
|
||||
Default theme: {:?}\n
|
||||
Default front page: {:?}\n
|
||||
Default layout: {:?}\n
|
||||
|
@ -170,17 +166,15 @@ impl InstanceInfo {
|
|||
Default show NSFW: {:?}\n
|
||||
Default blur NSFW: {:?}\n
|
||||
Default use HLS: {:?}\n
|
||||
Default hide HLS notification: {:?}\n
|
||||
Default subscriptions: {:?}\n",
|
||||
Default hide HLS notification: {:?}\n",
|
||||
self.crate_version,
|
||||
self.git_commit,
|
||||
self.deploy_date,
|
||||
self.deploy_unix_ts,
|
||||
self.compile_mode,
|
||||
self.config.sfw_only,
|
||||
self.config.pushshift,
|
||||
self.config.banner,
|
||||
self.config.default_hide_awards,
|
||||
self.config.sfw_only,
|
||||
self.config.default_theme,
|
||||
self.config.default_front_page,
|
||||
self.config.default_layout,
|
||||
|
@ -190,8 +184,7 @@ impl InstanceInfo {
|
|||
self.config.default_show_nsfw,
|
||||
self.config.default_blur_nsfw,
|
||||
self.config.default_use_hls,
|
||||
self.config.default_hide_hls_notification,
|
||||
self.config.default_subscriptions,
|
||||
self.config.default_hide_hls_notification
|
||||
)
|
||||
}
|
||||
StringType::Html => self.to_table(),
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -161,7 +161,7 @@ async fn main() {
|
|||
let mut app = server::Server::new();
|
||||
|
||||
// Force evaluation of statics. In instance_info case, we need to evaluate
|
||||
// the timestamp so deploy date is accurate - in config case, we need to
|
||||
// the timestamp so deploy date is accurate - in config case, we need to
|
||||
// evaluate the configuration to avoid paying penalty at first request.
|
||||
|
||||
Lazy::force(&config::CONFIG);
|
||||
|
@ -186,21 +186,9 @@ async fn main() {
|
|||
app
|
||||
.at("/manifest.json")
|
||||
.get(|_| resource(include_str!("../static/manifest.json"), "application/json", false).boxed());
|
||||
app.at("/robots.txt").get(|_| {
|
||||
resource(
|
||||
if match config::get_setting("LIBREDDIT_ROBOTS_DISABLE_INDEXING") {
|
||||
Some(val) => val == "on",
|
||||
None => false,
|
||||
} {
|
||||
"User-agent: *\nDisallow: /"
|
||||
} else {
|
||||
"User-agent: *\nDisallow: /u/\nDisallow: /user/"
|
||||
},
|
||||
"text/plain",
|
||||
true,
|
||||
)
|
||||
.boxed()
|
||||
});
|
||||
app
|
||||
.at("/robots.txt")
|
||||
.get(|_| resource("User-agent: *\nDisallow: /u/\nDisallow: /user/", "text/plain", true).boxed());
|
||||
app.at("/favicon.ico").get(|_| favicon().boxed());
|
||||
app.at("/logo.png").get(|_| pwa_logo().boxed());
|
||||
app.at("/Inter.var.woff2").get(|_| font().boxed());
|
||||
|
|
235
src/post.rs
235
src/post.rs
|
@ -1,6 +1,5 @@
|
|||
// CRATES
|
||||
use crate::client::json;
|
||||
use crate::config::get_setting;
|
||||
use crate::server::RequestExt;
|
||||
use crate::subreddit::{can_access_quarantine, quarantine};
|
||||
use crate::utils::{
|
||||
|
@ -9,8 +8,6 @@ use crate::utils::{
|
|||
use hyper::{Body, Request, Response};
|
||||
|
||||
use askama::Template;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::collections::HashSet;
|
||||
|
||||
// STRUCTS
|
||||
|
@ -23,18 +20,13 @@ struct PostTemplate {
|
|||
prefs: Preferences,
|
||||
single_thread: bool,
|
||||
url: String,
|
||||
url_without_query: String,
|
||||
comment_query: String,
|
||||
}
|
||||
|
||||
static COMMENT_SEARCH_CAPTURE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"\?q=(.*)&type=comment"#).unwrap());
|
||||
|
||||
pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
// Build Reddit API path
|
||||
let mut path: String = format!("{}.json?{}&raw_json=1", req.uri().path(), req.uri().query().unwrap_or_default());
|
||||
let sub = req.param("sub").unwrap_or_default();
|
||||
let quarantined = can_access_quarantine(&req, &sub);
|
||||
let url = req.uri().to_string();
|
||||
|
||||
// Set sort to sort query parameter
|
||||
let sort = param(&path, "sort").unwrap_or_else(|| {
|
||||
|
@ -64,41 +56,31 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
// Parse the JSON into Post and Comment structs
|
||||
let post = parse_post(&response[0]["data"]["children"][0]).await;
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this post
|
||||
// NSFW, but we have also disabled the display of NSFW content
|
||||
// or if the instance is SFW-only.
|
||||
if post.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
if post.nsfw && (setting(&req, "show_nsfw") != "on" || crate::utils::sfw_only()) {
|
||||
return Ok(nsfw_landing(req).await.unwrap_or_default());
|
||||
}
|
||||
|
||||
let query = match COMMENT_SEARCH_CAPTURE.captures(&url) {
|
||||
Some(captures) => captures.get(1).unwrap().as_str().replace("%20", " ").replace('+', " "),
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
let comments = match query.as_str() {
|
||||
"" => parse_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &req),
|
||||
_ => query_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &query, &req),
|
||||
};
|
||||
let comments = parse_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &req);
|
||||
let url = req.uri().to_string();
|
||||
|
||||
// Use the Post and Comment structs to generate a website to show users
|
||||
template(PostTemplate {
|
||||
comments,
|
||||
post,
|
||||
url_without_query: url.clone().trim_end_matches(&format!("?q={query}&type=comment")).to_string(),
|
||||
sort,
|
||||
prefs: Preferences::new(&req),
|
||||
single_thread,
|
||||
url: req_url,
|
||||
comment_query: query,
|
||||
url,
|
||||
})
|
||||
}
|
||||
// If the Reddit API returns an error, exit and send error page to user
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
if msg == "quarantined" {
|
||||
let sub = req.param("sub").unwrap_or_default();
|
||||
quarantine(req, sub, msg)
|
||||
quarantine(req, sub)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
@ -107,7 +89,6 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
}
|
||||
|
||||
// COMMENTS
|
||||
|
||||
fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, highlighted_comment: &str, filters: &HashSet<String>, req: &Request<Body>) -> Vec<Comment> {
|
||||
// Parse the comment JSON into a Vector of Comments
|
||||
let comments = json["data"]["children"].as_array().map_or(Vec::new(), std::borrow::ToOwned::to_owned);
|
||||
|
@ -116,138 +97,88 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
|
|||
comments
|
||||
.into_iter()
|
||||
.map(|comment| {
|
||||
let kind = comment["kind"].as_str().unwrap_or_default().to_string();
|
||||
let data = &comment["data"];
|
||||
|
||||
let unix_time = data["created_utc"].as_f64().unwrap_or_default();
|
||||
let (rel_time, created) = time(unix_time);
|
||||
|
||||
let edited = data["edited"].as_f64().map_or((String::new(), String::new()), time);
|
||||
|
||||
let score = data["score"].as_i64().unwrap_or(0);
|
||||
|
||||
// If this comment contains replies, handle those too
|
||||
let replies: Vec<Comment> = if data["replies"].is_object() {
|
||||
parse_comments(&data["replies"], post_link, post_author, highlighted_comment, filters, req)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
build_comment(&comment, data, replies, post_link, post_author, highlighted_comment, filters, req)
|
||||
|
||||
let awards: Awards = Awards::parse(&data["all_awardings"]);
|
||||
|
||||
let parent_kind_and_id = val(&comment, "parent_id");
|
||||
let parent_info = parent_kind_and_id.split('_').collect::<Vec<&str>>();
|
||||
|
||||
let id = val(&comment, "id");
|
||||
let highlighted = id == highlighted_comment;
|
||||
|
||||
let body = if (val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]") || val(&comment, "body") == "[ Removed by Reddit ]" {
|
||||
format!(
|
||||
"<div class=\"md\"><p>[removed] — <a href=\"https://www.unddit.com{}{}\">view removed comment</a></p></div>",
|
||||
post_link, id
|
||||
)
|
||||
} else {
|
||||
rewrite_urls(&val(&comment, "body_html"))
|
||||
};
|
||||
|
||||
let author = Author {
|
||||
name: val(&comment, "author"),
|
||||
flair: Flair {
|
||||
flair_parts: FlairPart::parse(
|
||||
data["author_flair_type"].as_str().unwrap_or_default(),
|
||||
data["author_flair_richtext"].as_array(),
|
||||
data["author_flair_text"].as_str(),
|
||||
),
|
||||
text: val(&comment, "link_flair_text"),
|
||||
background_color: val(&comment, "author_flair_background_color"),
|
||||
foreground_color: val(&comment, "author_flair_text_color"),
|
||||
},
|
||||
distinguished: val(&comment, "distinguished"),
|
||||
};
|
||||
let is_filtered = filters.contains(&["u_", author.name.as_str()].concat());
|
||||
|
||||
// Many subreddits have a default comment posted about the sub's rules etc.
|
||||
// Many libreddit users do not wish to see this kind of comment by default.
|
||||
// Reddit does not tell us which users are "bots", so a good heuristic is to
|
||||
// collapse stickied moderator comments.
|
||||
let is_moderator_comment = data["distinguished"].as_str().unwrap_or_default() == "moderator";
|
||||
let is_stickied = data["stickied"].as_bool().unwrap_or_default();
|
||||
let collapsed = (is_moderator_comment && is_stickied) || is_filtered;
|
||||
|
||||
Comment {
|
||||
id,
|
||||
kind,
|
||||
parent_id: parent_info[1].to_string(),
|
||||
parent_kind: parent_info[0].to_string(),
|
||||
post_link: post_link.to_string(),
|
||||
post_author: post_author.to_string(),
|
||||
body,
|
||||
author,
|
||||
score: if data["score_hidden"].as_bool().unwrap_or_default() {
|
||||
("\u{2022}".to_string(), "Hidden".to_string())
|
||||
} else {
|
||||
format_num(score)
|
||||
},
|
||||
rel_time,
|
||||
created,
|
||||
edited,
|
||||
replies,
|
||||
highlighted,
|
||||
awards,
|
||||
collapsed,
|
||||
is_filtered,
|
||||
prefs: Preferences::new(req),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn query_comments(
|
||||
json: &serde_json::Value,
|
||||
post_link: &str,
|
||||
post_author: &str,
|
||||
highlighted_comment: &str,
|
||||
filters: &HashSet<String>,
|
||||
query: &str,
|
||||
req: &Request<Body>,
|
||||
) -> Vec<Comment> {
|
||||
let comments = json["data"]["children"].as_array().map_or(Vec::new(), std::borrow::ToOwned::to_owned);
|
||||
let mut results = Vec::new();
|
||||
|
||||
comments.into_iter().for_each(|comment| {
|
||||
let data = &comment["data"];
|
||||
|
||||
// If this comment contains replies, handle those too
|
||||
if data["replies"].is_object() {
|
||||
results.append(&mut query_comments(&data["replies"], post_link, post_author, highlighted_comment, filters, query, req))
|
||||
}
|
||||
|
||||
let c = build_comment(&comment, data, Vec::new(), post_link, post_author, highlighted_comment, filters, req);
|
||||
if c.body.to_lowercase().contains(&query.to_lowercase()) {
|
||||
results.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
results
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn build_comment(
|
||||
comment: &serde_json::Value,
|
||||
data: &serde_json::Value,
|
||||
replies: Vec<Comment>,
|
||||
post_link: &str,
|
||||
post_author: &str,
|
||||
highlighted_comment: &str,
|
||||
filters: &HashSet<String>,
|
||||
req: &Request<Body>,
|
||||
) -> Comment {
|
||||
let id = val(comment, "id");
|
||||
|
||||
let body = if (val(comment, "author") == "[deleted]" && val(comment, "body") == "[removed]") || val(comment, "body") == "[ Removed by Reddit ]" {
|
||||
format!(
|
||||
"<div class=\"md\"><p>[removed] — <a href=\"https://{}{}{}\">view removed comment</a></p></div>",
|
||||
get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(crate::config::DEFAULT_PUSHSHIFT_FRONTEND)),
|
||||
post_link,
|
||||
id
|
||||
)
|
||||
} else {
|
||||
rewrite_urls(&val(comment, "body_html"))
|
||||
};
|
||||
let kind = comment["kind"].as_str().unwrap_or_default().to_string();
|
||||
|
||||
let unix_time = data["created_utc"].as_f64().unwrap_or_default();
|
||||
let (rel_time, created) = time(unix_time);
|
||||
|
||||
let edited = data["edited"].as_f64().map_or((String::new(), String::new()), time);
|
||||
|
||||
let score = data["score"].as_i64().unwrap_or(0);
|
||||
|
||||
// The JSON API only provides comments up to some threshold.
|
||||
// Further comments have to be loaded by subsequent requests.
|
||||
// The "kind" value will be "more" and the "count"
|
||||
// shows how many more (sub-)comments exist in the respective nesting level.
|
||||
// Note that in certain (seemingly random) cases, the count is simply wrong.
|
||||
let more_count = data["count"].as_i64().unwrap_or_default();
|
||||
|
||||
let awards: Awards = Awards::parse(&data["all_awardings"]);
|
||||
|
||||
let parent_kind_and_id = val(comment, "parent_id");
|
||||
let parent_info = parent_kind_and_id.split('_').collect::<Vec<&str>>();
|
||||
|
||||
let highlighted = id == highlighted_comment;
|
||||
|
||||
let author = Author {
|
||||
name: val(comment, "author"),
|
||||
flair: Flair {
|
||||
flair_parts: FlairPart::parse(
|
||||
data["author_flair_type"].as_str().unwrap_or_default(),
|
||||
data["author_flair_richtext"].as_array(),
|
||||
data["author_flair_text"].as_str(),
|
||||
),
|
||||
text: val(comment, "link_flair_text"),
|
||||
background_color: val(comment, "author_flair_background_color"),
|
||||
foreground_color: val(comment, "author_flair_text_color"),
|
||||
},
|
||||
distinguished: val(comment, "distinguished"),
|
||||
};
|
||||
let is_filtered = filters.contains(&["u_", author.name.as_str()].concat());
|
||||
|
||||
// Many subreddits have a default comment posted about the sub's rules etc.
|
||||
// Many libreddit users do not wish to see this kind of comment by default.
|
||||
// Reddit does not tell us which users are "bots", so a good heuristic is to
|
||||
// collapse stickied moderator comments.
|
||||
let is_moderator_comment = data["distinguished"].as_str().unwrap_or_default() == "moderator";
|
||||
let is_stickied = data["stickied"].as_bool().unwrap_or_default();
|
||||
let collapsed = (is_moderator_comment && is_stickied) || is_filtered;
|
||||
|
||||
Comment {
|
||||
id,
|
||||
kind,
|
||||
parent_id: parent_info[1].to_string(),
|
||||
parent_kind: parent_info[0].to_string(),
|
||||
post_link: post_link.to_string(),
|
||||
post_author: post_author.to_string(),
|
||||
body,
|
||||
author,
|
||||
score: if data["score_hidden"].as_bool().unwrap_or_default() {
|
||||
("\u{2022}".to_string(), "Hidden".to_string())
|
||||
} else {
|
||||
format_num(score)
|
||||
},
|
||||
rel_time,
|
||||
created,
|
||||
edited,
|
||||
replies,
|
||||
highlighted,
|
||||
awards,
|
||||
collapsed,
|
||||
is_filtered,
|
||||
more_count,
|
||||
prefs: Preferences::new(req),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,9 +145,9 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
})
|
||||
}
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
if msg == "quarantined" {
|
||||
let sub = req.param("sub").unwrap_or_default();
|
||||
quarantine(req, sub, msg)
|
||||
quarantine(req, sub)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ impl Server {
|
|||
.boxed()
|
||||
}
|
||||
// If there was a routing error
|
||||
Err(e) => new_boilerplate(def_headers, req_headers, 404, e.into()).boxed(),
|
||||
Err(e) => async move { new_boilerplate(def_headers, req_headers, 404, e.into()).await }.boxed(),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ fn determine_compressor(accept_encoding: String) -> Option<CompressionType> {
|
|||
|
||||
// This loop reads the requested compressors and keeps track of whichever
|
||||
// one has the highest priority per our heuristic.
|
||||
for val in accept_encoding.split(',') {
|
||||
for val in accept_encoding.to_string().split(',') {
|
||||
let mut q: f64 = 1.0;
|
||||
|
||||
// The compressor and q-value (if the latter is defined)
|
||||
|
|
|
@ -97,11 +97,10 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
}
|
||||
};
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this is NSFW community but the user
|
||||
// has disabled the display of NSFW content or if the instance is SFW-only.
|
||||
if sub.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
if sub.nsfw && (setting(&req, "show_nsfw") != "on" || crate::utils::sfw_only()) {
|
||||
return Ok(nsfw_landing(req).await.unwrap_or_default());
|
||||
}
|
||||
|
||||
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub_name.clone(), sort, req.uri().query().unwrap_or_default());
|
||||
|
@ -145,7 +144,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
})
|
||||
}
|
||||
Err(msg) => match msg.as_str() {
|
||||
"quarantined" | "gated" => quarantine(req, sub_name, msg),
|
||||
"quarantined" => quarantine(req, sub_name),
|
||||
"private" => error(req, format!("r/{} is a private community", sub_name)).await,
|
||||
"banned" => error(req, format!("r/{} has been banned from Reddit", sub_name)).await,
|
||||
_ => error(req, msg).await,
|
||||
|
@ -154,9 +153,9 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn quarantine(req: Request<Body>, sub: String, restriction: String) -> Result<Response<Body>, String> {
|
||||
pub fn quarantine(req: Request<Body>, sub: String) -> Result<Response<Body>, String> {
|
||||
let wall = WallTemplate {
|
||||
title: format!("r/{} is {}", sub, restriction),
|
||||
title: format!("r/{} is quarantined", sub),
|
||||
msg: "Please click the button below to continue to this subreddit.".to_string(),
|
||||
url: req.uri().to_string(),
|
||||
sub,
|
||||
|
@ -324,8 +323,8 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
url,
|
||||
}),
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
quarantine(req, sub, msg)
|
||||
if msg == "quarantined" {
|
||||
quarantine(req, sub)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
@ -362,8 +361,8 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
url,
|
||||
}),
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
quarantine(req, sub, msg)
|
||||
if msg == "quarantined" {
|
||||
quarantine(req, sub)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
|
|
@ -50,12 +50,11 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
// Retrieve info from user about page.
|
||||
let user = user(&username).await.unwrap_or_default();
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this user NSFW,
|
||||
// but we have also disabled the display of NSFW content or if the instance
|
||||
// is SFW-only.
|
||||
if user.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
if user.nsfw && (setting(&req, "show_nsfw") != "on" || crate::utils::sfw_only()) {
|
||||
return Ok(nsfw_landing(req).await.unwrap_or_default());
|
||||
}
|
||||
|
||||
let filters = get_filters(&req);
|
||||
|
|
227
src/utils.rs
227
src/utils.rs
|
@ -1,4 +1,3 @@
|
|||
use crate::config::get_setting;
|
||||
//
|
||||
// CRATES
|
||||
//
|
||||
|
@ -6,7 +5,6 @@ use crate::{client::json, server::RequestExt};
|
|||
use askama::Template;
|
||||
use cookie::Cookie;
|
||||
use hyper::{Body, Request, Response};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde_json::Value;
|
||||
|
@ -98,61 +96,6 @@ pub struct Author {
|
|||
pub distinguished: String,
|
||||
}
|
||||
|
||||
pub struct Poll {
|
||||
pub poll_options: Vec<PollOption>,
|
||||
pub voting_end_timestamp: (String, String),
|
||||
pub total_vote_count: u64,
|
||||
}
|
||||
|
||||
impl Poll {
|
||||
pub fn parse(poll_data: &Value) -> Option<Self> {
|
||||
poll_data.as_object()?;
|
||||
|
||||
let total_vote_count = poll_data["total_vote_count"].as_u64()?;
|
||||
// voting_end_timestamp is in the format of milliseconds
|
||||
let voting_end_timestamp = time(poll_data["voting_end_timestamp"].as_f64()? / 1000.0);
|
||||
let poll_options = PollOption::parse(&poll_data["options"])?;
|
||||
|
||||
Some(Self {
|
||||
poll_options,
|
||||
total_vote_count,
|
||||
voting_end_timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn most_votes(&self) -> u64 {
|
||||
self.poll_options.iter().filter_map(|o| o.vote_count).max().unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PollOption {
|
||||
pub id: u64,
|
||||
pub text: String,
|
||||
pub vote_count: Option<u64>,
|
||||
}
|
||||
|
||||
impl PollOption {
|
||||
pub fn parse(options: &Value) -> Option<Vec<Self>> {
|
||||
Some(
|
||||
options
|
||||
.as_array()?
|
||||
.iter()
|
||||
.filter_map(|option| {
|
||||
// For each poll option
|
||||
|
||||
// we can't just use as_u64() because "id": String("...") and serde would parse it as None
|
||||
let id = option["id"].as_str()?.parse::<u64>().ok()?;
|
||||
let text = option["text"].as_str()?.to_owned();
|
||||
let vote_count = option["vote_count"].as_u64();
|
||||
|
||||
// Construct PollOption items
|
||||
Some(Self { id, text, vote_count })
|
||||
})
|
||||
.collect::<Vec<Self>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Post flags with nsfw and stickied
|
||||
pub struct Flags {
|
||||
pub nsfw: bool,
|
||||
|
@ -261,17 +204,10 @@ impl GalleryMedia {
|
|||
// For each image in gallery
|
||||
let media_id = item["media_id"].as_str().unwrap_or_default();
|
||||
let image = &metadata[media_id]["s"];
|
||||
let image_type = &metadata[media_id]["m"];
|
||||
|
||||
let url = if image_type == "image/gif" {
|
||||
image["gif"].as_str().unwrap_or_default()
|
||||
} else {
|
||||
image["u"].as_str().unwrap_or_default()
|
||||
};
|
||||
|
||||
// Construct gallery items
|
||||
Self {
|
||||
url: format_url(url),
|
||||
url: format_url(image["u"].as_str().unwrap_or_default()),
|
||||
width: image["x"].as_i64().unwrap_or_default(),
|
||||
height: image["y"].as_i64().unwrap_or_default(),
|
||||
caption: item["caption"].as_str().unwrap_or_default().to_string(),
|
||||
|
@ -290,7 +226,6 @@ pub struct Post {
|
|||
pub body: String,
|
||||
pub author: Author,
|
||||
pub permalink: String,
|
||||
pub poll: Option<Poll>,
|
||||
pub score: (String, String),
|
||||
pub upvote_ratio: i64,
|
||||
pub post_type: String,
|
||||
|
@ -400,7 +335,6 @@ impl Post {
|
|||
stickied: data["stickied"].as_bool().unwrap_or_default() || data["pinned"].as_bool().unwrap_or_default(),
|
||||
},
|
||||
permalink: val(post, "permalink"),
|
||||
poll: Poll::parse(&data["poll_data"]),
|
||||
rel_time,
|
||||
created,
|
||||
num_duplicates: post["data"]["num_duplicates"].as_u64().unwrap_or(0),
|
||||
|
@ -436,7 +370,6 @@ pub struct Comment {
|
|||
pub awards: Awards,
|
||||
pub collapsed: bool,
|
||||
pub is_filtered: bool,
|
||||
pub more_count: i64,
|
||||
pub prefs: Preferences,
|
||||
}
|
||||
|
||||
|
@ -597,21 +530,21 @@ impl Preferences {
|
|||
}
|
||||
Self {
|
||||
available_themes: themes,
|
||||
theme: setting(req, "theme"),
|
||||
front_page: setting(req, "front_page"),
|
||||
layout: setting(req, "layout"),
|
||||
wide: setting(req, "wide"),
|
||||
show_nsfw: setting(req, "show_nsfw"),
|
||||
blur_nsfw: setting(req, "blur_nsfw"),
|
||||
use_hls: setting(req, "use_hls"),
|
||||
hide_hls_notification: setting(req, "hide_hls_notification"),
|
||||
autoplay_videos: setting(req, "autoplay_videos"),
|
||||
disable_visit_reddit_confirmation: setting(req, "disable_visit_reddit_confirmation"),
|
||||
comment_sort: setting(req, "comment_sort"),
|
||||
post_sort: setting(req, "post_sort"),
|
||||
subscriptions: setting(req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
||||
filters: setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
||||
hide_awards: setting(req, "hide_awards"),
|
||||
theme: setting(&req, "theme"),
|
||||
front_page: setting(&req, "front_page"),
|
||||
layout: setting(&req, "layout"),
|
||||
wide: setting(&req, "wide"),
|
||||
show_nsfw: setting(&req, "show_nsfw"),
|
||||
blur_nsfw: setting(&req, "blur_nsfw"),
|
||||
use_hls: setting(&req, "use_hls"),
|
||||
hide_hls_notification: setting(&req, "hide_hls_notification"),
|
||||
autoplay_videos: setting(&req, "autoplay_videos"),
|
||||
disable_visit_reddit_confirmation: setting(&req, "disable_visit_reddit_confirmation"),
|
||||
comment_sort: setting(&req, "comment_sort"),
|
||||
post_sort: setting(&req, "post_sort"),
|
||||
subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
||||
filters: setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
|
||||
hide_awards: setting(&req, "hide_awards"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -659,12 +592,9 @@ pub async fn parse_post(post: &serde_json::Value) -> Post {
|
|||
|
||||
let permalink = val(post, "permalink");
|
||||
|
||||
let poll = Poll::parse(&post["data"]["poll_data"]);
|
||||
|
||||
let body = if val(post, "removed_by_category") == "moderator" {
|
||||
format!(
|
||||
"<div class=\"md\"><p>[removed] — <a href=\"https://{}{}\">view removed post</a></p></div>",
|
||||
get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(crate::config::DEFAULT_PUSHSHIFT_FRONTEND)),
|
||||
"<div class=\"md\"><p>[removed] — <a href=\"https://www.unddit.com{}\">view removed post</a></p></div>",
|
||||
permalink
|
||||
)
|
||||
} else {
|
||||
|
@ -692,7 +622,6 @@ pub async fn parse_post(post: &serde_json::Value) -> Post {
|
|||
distinguished: val(post, "distinguished"),
|
||||
},
|
||||
permalink,
|
||||
poll,
|
||||
score: format_num(score),
|
||||
upvote_ratio: ratio as i64,
|
||||
post_type,
|
||||
|
@ -780,21 +709,6 @@ pub async fn catch_random(sub: &str, additional: &str) -> Result<Response<Body>,
|
|||
}
|
||||
}
|
||||
|
||||
static REGEX_URL_WWW: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://www\.reddit\.com/(.*)").unwrap());
|
||||
static REGEX_URL_OLD: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://old\.reddit\.com/(.*)").unwrap());
|
||||
static REGEX_URL_NP: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://np\.reddit\.com/(.*)").unwrap());
|
||||
static REGEX_URL_PLAIN: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://reddit\.com/(.*)").unwrap());
|
||||
static REGEX_URL_VIDEOS: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$|\?source=fallback))").unwrap());
|
||||
static REGEX_URL_VIDEOS_HLS: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$").unwrap());
|
||||
static REGEX_URL_IMAGES: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://i\.redd\.it/(.*)").unwrap());
|
||||
static REGEX_URL_THUMBS_A: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://a\.thumbs\.redditmedia\.com/(.*)").unwrap());
|
||||
static REGEX_URL_THUMBS_B: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://b\.thumbs\.redditmedia\.com/(.*)").unwrap());
|
||||
static REGEX_URL_EMOJI: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://emoji\.redditmedia\.com/(.*)/(.*)").unwrap());
|
||||
static REGEX_URL_PREVIEW: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://preview\.redd\.it/(.*)").unwrap());
|
||||
static REGEX_URL_EXTERNAL_PREVIEW: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://external\-preview\.redd\.it/(.*)").unwrap());
|
||||
static REGEX_URL_STYLES: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://styles\.redditmedia\.com/(.*)").unwrap());
|
||||
static REGEX_URL_STATIC_MEDIA: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://www\.redditstatic\.com/(.*)").unwrap());
|
||||
|
||||
// Direct urls to proxy if proxy is enabled
|
||||
pub fn format_url(url: &str) -> String {
|
||||
if url.is_empty() || url == "self" || url == "default" || url == "nsfw" || url == "spoiler" {
|
||||
|
@ -803,11 +717,13 @@ pub fn format_url(url: &str) -> String {
|
|||
Url::parse(url).map_or(url.to_string(), |parsed| {
|
||||
let domain = parsed.domain().unwrap_or_default();
|
||||
|
||||
let capture = |regex: &Regex, format: &str, segments: i16| {
|
||||
regex.captures(url).map_or(String::new(), |caps| match segments {
|
||||
1 => [format, &caps[1]].join(""),
|
||||
2 => [format, &caps[1], "/", &caps[2]].join(""),
|
||||
_ => String::new(),
|
||||
let capture = |regex: &str, format: &str, segments: i16| {
|
||||
Regex::new(regex).map_or(String::new(), |re| {
|
||||
re.captures(url).map_or(String::new(), |caps| match segments {
|
||||
1 => [format, &caps[1]].join(""),
|
||||
2 => [format, &caps[1], "/", &caps[2]].join(""),
|
||||
_ => String::new(),
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -833,46 +749,44 @@ pub fn format_url(url: &str) -> String {
|
|||
}
|
||||
|
||||
match domain {
|
||||
"www.reddit.com" => capture(®EX_URL_WWW, "/", 1),
|
||||
"old.reddit.com" => capture(®EX_URL_OLD, "/", 1),
|
||||
"np.reddit.com" => capture(®EX_URL_NP, "/", 1),
|
||||
"reddit.com" => capture(®EX_URL_PLAIN, "/", 1),
|
||||
"v.redd.it" => chain!(capture(®EX_URL_VIDEOS, "/vid/", 2), capture(®EX_URL_VIDEOS_HLS, "/hls/", 2)),
|
||||
"i.redd.it" => capture(®EX_URL_IMAGES, "/img/", 1),
|
||||
"a.thumbs.redditmedia.com" => capture(®EX_URL_THUMBS_A, "/thumb/a/", 1),
|
||||
"b.thumbs.redditmedia.com" => capture(®EX_URL_THUMBS_B, "/thumb/b/", 1),
|
||||
"emoji.redditmedia.com" => capture(®EX_URL_EMOJI, "/emoji/", 2),
|
||||
"preview.redd.it" => capture(®EX_URL_PREVIEW, "/preview/pre/", 1),
|
||||
"external-preview.redd.it" => capture(®EX_URL_EXTERNAL_PREVIEW, "/preview/external-pre/", 1),
|
||||
"styles.redditmedia.com" => capture(®EX_URL_STYLES, "/style/", 1),
|
||||
"www.redditstatic.com" => capture(®EX_URL_STATIC_MEDIA, "/static/", 1),
|
||||
"www.reddit.com" => capture(r"https://www\.reddit\.com/(.*)", "/", 1),
|
||||
"old.reddit.com" => capture(r"https://old\.reddit\.com/(.*)", "/", 1),
|
||||
"np.reddit.com" => capture(r"https://np\.reddit\.com/(.*)", "/", 1),
|
||||
"reddit.com" => capture(r"https://reddit\.com/(.*)", "/", 1),
|
||||
"v.redd.it" => chain!(
|
||||
capture(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$|\?source=fallback))", "/vid/", 2),
|
||||
capture(r"https://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$", "/hls/", 2)
|
||||
),
|
||||
"i.redd.it" => capture(r"https://i\.redd\.it/(.*)", "/img/", 1),
|
||||
"a.thumbs.redditmedia.com" => capture(r"https://a\.thumbs\.redditmedia\.com/(.*)", "/thumb/a/", 1),
|
||||
"b.thumbs.redditmedia.com" => capture(r"https://b\.thumbs\.redditmedia\.com/(.*)", "/thumb/b/", 1),
|
||||
"emoji.redditmedia.com" => capture(r"https://emoji\.redditmedia\.com/(.*)/(.*)", "/emoji/", 2),
|
||||
"preview.redd.it" => capture(r"https://preview\.redd\.it/(.*)", "/preview/pre/", 1),
|
||||
"external-preview.redd.it" => capture(r"https://external\-preview\.redd\.it/(.*)", "/preview/external-pre/", 1),
|
||||
"styles.redditmedia.com" => capture(r"https://styles\.redditmedia\.com/(.*)", "/style/", 1),
|
||||
"www.redditstatic.com" => capture(r"https://www\.redditstatic\.com/(.*)", "/static/", 1),
|
||||
_ => url.to_string(),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static REDDIT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|)(reddit\.com|redd\.it)/"#).unwrap());
|
||||
static REDDIT_PREVIEW_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").unwrap());
|
||||
|
||||
// Rewrite Reddit links to Libreddit in body of text
|
||||
pub fn rewrite_urls(input_text: &str) -> String {
|
||||
let text1 =
|
||||
// Rewrite Reddit links to Libreddit
|
||||
REDDIT_REGEX.replace_all(input_text, r#"href="/"#)
|
||||
.to_string()
|
||||
// Remove (html-encoded) "\" from URLs.
|
||||
.replace("%5C", "")
|
||||
.replace('\\', "");
|
||||
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())
|
||||
// Remove (html-encoded) "\" from URLs.
|
||||
.replace("%5C", "")
|
||||
.replace('\\', "");
|
||||
|
||||
// Rewrite external media previews to Libreddit
|
||||
if REDDIT_PREVIEW_REGEX.is_match(&text1) {
|
||||
REDDIT_PREVIEW_REGEX
|
||||
.replace_all(&text1, format_url(REDDIT_PREVIEW_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default()))
|
||||
.to_string()
|
||||
} else {
|
||||
text1
|
||||
}
|
||||
Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {
|
||||
if re.is_match(&text1) {
|
||||
re.replace_all(&text1, format_url(re.find(&text1).map(|x| x.as_str()).unwrap_or_default())).to_string()
|
||||
} else {
|
||||
text1
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Format vote count to a string that will be displayed.
|
||||
|
@ -893,31 +807,20 @@ pub fn format_num(num: i64) -> (String, String) {
|
|||
// Parse a relative and absolute time from a UNIX timestamp
|
||||
pub fn time(created: f64) -> (String, String) {
|
||||
let time = OffsetDateTime::from_unix_timestamp(created.round() as i64).unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let min = time.min(now);
|
||||
let max = time.max(now);
|
||||
let time_delta = max - min;
|
||||
let time_delta = OffsetDateTime::now_utc() - time;
|
||||
|
||||
// If the time difference is more than a month, show full date
|
||||
let mut rel_time = if time_delta > Duration::days(30) {
|
||||
let rel_time = if time_delta > Duration::days(30) {
|
||||
time.format(format_description!("[month repr:short] [day] '[year repr:last_two]")).unwrap_or_default()
|
||||
// Otherwise, show relative date/time
|
||||
} else if time_delta.whole_days() > 0 {
|
||||
format!("{}d", time_delta.whole_days())
|
||||
format!("{}d ago", time_delta.whole_days())
|
||||
} else if time_delta.whole_hours() > 0 {
|
||||
format!("{}h", time_delta.whole_hours())
|
||||
format!("{}h ago", time_delta.whole_hours())
|
||||
} else {
|
||||
format!("{}m", time_delta.whole_minutes())
|
||||
format!("{}m ago", time_delta.whole_minutes())
|
||||
};
|
||||
|
||||
if time_delta <= Duration::days(30) {
|
||||
if now < time {
|
||||
rel_time += " left";
|
||||
} else {
|
||||
rel_time += " ago";
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
rel_time,
|
||||
time
|
||||
|
@ -982,21 +885,11 @@ pub fn sfw_only() -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
// Determines if a request shoud redirect to a nsfw landing gate.
|
||||
pub fn should_be_nsfw_gated(req: &Request<Body>, req_url: &str) -> bool {
|
||||
let sfw_instance = sfw_only();
|
||||
let gate_nsfw = (setting(req, "show_nsfw") != "on") || sfw_instance;
|
||||
|
||||
// Nsfw landing gate should not be bypassed on a sfw only instance,
|
||||
let bypass_gate = !sfw_instance && req_url.contains("&bypass_nsfw_landing");
|
||||
|
||||
gate_nsfw && !bypass_gate
|
||||
}
|
||||
|
||||
/// Renders the landing page for NSFW content when the user has not enabled
|
||||
/// "show NSFW posts" in settings.
|
||||
pub async fn nsfw_landing(req: Request<Body>, req_url: String) -> Result<Response<Body>, String> {
|
||||
pub async fn nsfw_landing(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
let res_type: ResourceType;
|
||||
let url = req.uri().to_string();
|
||||
|
||||
// Determine from the request URL if the resource is a subreddit, a user
|
||||
// page, or a post.
|
||||
|
@ -1015,7 +908,7 @@ pub async fn nsfw_landing(req: Request<Body>, req_url: String) -> Result<Respons
|
|||
res,
|
||||
res_type,
|
||||
prefs: Preferences::new(&req),
|
||||
url: req_url,
|
||||
url,
|
||||
}
|
||||
.render()
|
||||
.unwrap_or_default();
|
||||
|
|
116
static/style.css
116
static/style.css
|
@ -26,8 +26,6 @@
|
|||
--popup-goback-background: var(--popup-red);
|
||||
--popup-goback-text: #222;
|
||||
--popup-border: 1px solid var(--popup-red);
|
||||
|
||||
--footer-height: 30px;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
|
@ -101,9 +99,6 @@ body {
|
|||
background: var(--background);
|
||||
font-size: 15px;
|
||||
padding-top: 60px;
|
||||
padding-bottom: var(--footer-height);
|
||||
min-height: calc(100vh - 60px);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
nav {
|
||||
|
@ -147,6 +142,12 @@ nav #links svg {
|
|||
display: none;
|
||||
}
|
||||
|
||||
nav #version {
|
||||
opacity: 50%;
|
||||
vertical-align: -2px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
nav #libreddit {
|
||||
vertical-align: -2px;
|
||||
}
|
||||
|
@ -269,7 +270,6 @@ main {
|
|||
max-width: 1000px;
|
||||
padding: 10px 20px;
|
||||
margin: 0 auto;
|
||||
padding-bottom: 4em;
|
||||
}
|
||||
|
||||
.wide main {
|
||||
|
@ -292,22 +292,22 @@ main {
|
|||
body > footer {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
background: var(--post);
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.footer-button {
|
||||
.info-button {
|
||||
align-items: center;
|
||||
border-radius: .25rem;
|
||||
box-sizing: border-box;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
padding-left: 1em;
|
||||
opacity: 0.8;
|
||||
font-size: 150%;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.info-button > a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* / Body footer. */
|
||||
|
@ -329,7 +329,6 @@ button {
|
|||
background: none;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
hr {
|
||||
|
@ -380,17 +379,13 @@ aside {
|
|||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#subreddit, #sidebar { min-width: 350px; }
|
||||
|
||||
#user *, #subreddit * { text-align: center; }
|
||||
|
||||
#user, #sub_meta, #sidebar_contents { padding: 20px; }
|
||||
|
||||
#sidebar, #sidebar_contents { margin-top: 10px; }
|
||||
#sidebar_label, #subreddit_label {
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
}
|
||||
#sidebar_label { padding: 10px; }
|
||||
|
||||
#user_icon, #sub_icon {
|
||||
width: 100px;
|
||||
|
@ -402,6 +397,7 @@ aside {
|
|||
}
|
||||
|
||||
#user_title, #sub_title {
|
||||
margin: 0 20px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
@ -545,7 +541,6 @@ select, #search, #sort_options, #listing_options, #inside, #searchbox > *, #sort
|
|||
select {
|
||||
background: var(--outside);
|
||||
transition: 0.2s background;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
select, #search {
|
||||
|
@ -558,10 +553,6 @@ select, #search {
|
|||
border-radius: 5px 0px 0px 5px;
|
||||
}
|
||||
|
||||
.commentQuery {
|
||||
background: var(--post);
|
||||
}
|
||||
|
||||
#searchbox {
|
||||
grid-area: searchbox;
|
||||
display: flex;
|
||||
|
@ -639,15 +630,6 @@ button.submit:hover > svg { stroke: var(--accent); }
|
|||
background: transparent;
|
||||
}
|
||||
|
||||
#commentQueryForms {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#allCommentsLink {
|
||||
color: var(--green);
|
||||
}
|
||||
|
||||
#sort, #search_sort {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
@ -771,7 +753,6 @@ a.search_subreddit:hover {
|
|||
"post_score post_title post_thumbnail" 1fr
|
||||
"post_score post_media post_thumbnail" auto
|
||||
"post_score post_body post_thumbnail" auto
|
||||
"post_score post_poll post_thumbnail" auto
|
||||
"post_score post_notification post_thumbnail" auto
|
||||
"post_score post_footer post_thumbnail" auto
|
||||
/ minmax(40px, auto) minmax(0, 1fr) fit-content(min(20%, 152px));
|
||||
|
@ -972,44 +953,6 @@ a.search_subreddit:hover {
|
|||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.post_poll {
|
||||
grid-area: post_poll;
|
||||
padding: 5px 15px 5px 12px;
|
||||
}
|
||||
|
||||
.poll_option {
|
||||
position: relative;
|
||||
margin-right: 15px;
|
||||
margin-top: 14px;
|
||||
z-index: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.poll_chart {
|
||||
padding: 14px 0;
|
||||
background-color: var(--accent);
|
||||
opacity: 0.2;
|
||||
border-radius: 5px;
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.poll_option span {
|
||||
margin-left: 8px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.poll_option span:nth-of-type(1) {
|
||||
min-width: 10%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.most_voted {
|
||||
opacity: 0.45;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Used only for text post preview */
|
||||
.post_preview {
|
||||
-webkit-mask-image: linear-gradient(180deg,#000 60%,transparent);;
|
||||
|
@ -1566,10 +1509,7 @@ td, th {
|
|||
/* Mobile */
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
body {
|
||||
padding-top: 120px;
|
||||
padding-bottom: var(--footer-height);
|
||||
}
|
||||
body { padding-top: 120px }
|
||||
|
||||
main {
|
||||
flex-direction: column-reverse;
|
||||
|
@ -1608,21 +1548,17 @@ td, th {
|
|||
#user, #sidebar { margin: 20px 0; }
|
||||
#logo, #links { margin-bottom: 5px; }
|
||||
#searchbox { width: calc(100vw - 35px); }
|
||||
|
||||
}
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
body {
|
||||
padding-top: 100px;
|
||||
padding-bottom: var(--footer-height);
|
||||
}
|
||||
body { padding-top: 100px; }
|
||||
#version { display: none; }
|
||||
|
||||
.post {
|
||||
grid-template: "post_header post_header post_thumbnail" auto
|
||||
"post_title post_title post_thumbnail" 1fr
|
||||
"post_media post_media post_thumbnail" auto
|
||||
"post_body post_body post_thumbnail" auto
|
||||
"post_poll post_poll post_thumbnail" auto
|
||||
"post_notification post_notification post_thumbnail" auto
|
||||
"post_score post_footer post_thumbnail" auto
|
||||
/ auto 1fr fit-content(min(20%, 152px));
|
||||
|
@ -1632,10 +1568,6 @@ td, th {
|
|||
margin: 5px 0px 20px 15px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.post_poll {
|
||||
padding: 5px 15px 10px 12px;
|
||||
}
|
||||
|
||||
.compact .post_score { padding: 0; }
|
||||
|
||||
|
@ -1682,14 +1614,10 @@ td, th {
|
|||
|
||||
.popup {
|
||||
width: auto;
|
||||
bottom: 10vh;
|
||||
}
|
||||
|
||||
.popup-inner {
|
||||
max-width: 80%;
|
||||
.popup-inner > a, h1, p, img {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#commentQueryForms {
|
||||
display: initial;
|
||||
justify-content: initial;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
<nav>
|
||||
<div id="logo">
|
||||
<a id="libreddit" href="/"><span id="lib">lib</span><span id="reddit">reddit.</span></a>
|
||||
<span id="version">v{{ env!("CARGO_PKG_VERSION") }}</span>
|
||||
{% block subscriptions %}{% endblock %}
|
||||
</div>
|
||||
{% block search %}{% endblock %}
|
||||
<div id="links">
|
||||
<a id="reddit_link" {% if prefs.disable_visit_reddit_confirmation != "on" %}href="#popup"{% else %}href="https://www.reddit.com{{ url }}" rel="nofollow"{% endif %}>
|
||||
<a id="reddit_link" {% if prefs.disable_visit_reddit_confirmation != "on" %}href="#popup"{% else %}href="https://www.reddit.com" rel="nofollow"{{ url }}"{% endif %}>
|
||||
<span>reddit</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M22 2L12 22"/>
|
||||
<path d="M2 6.70587C3.33333 8.07884 3.33333 11.5971 3.33333 11.5971M3.33333 19.647V11.5971M3.33333 11.5971C3.33333 11.5971 5.125 7.47817 8 7.47817C10.875 7.47817 12 8.85114 12 8.85114"/>
|
||||
<path d="M23 12.0737C23 10.7308 21.9222 9.64226 20.5926 9.64226C19.9435 9.64226 19.3557 9.90274 18.923 10.3244C17.2772 9.12492 15.0099 8.35046 12.4849 8.26135L13.5814 3.05002L17.1643 3.8195C17.2081 4.73947 17.9539 5.47368 18.8757 5.47368C19.8254 5.47368 20.5951 4.69626 20.5951 3.73684C20.5951 2.77769 19.8254 2 18.8758 2C18.2001 2 17.6214 2.39712 17.3404 2.96952L13.3393 2.11066C13.2279 2.08679 13.1116 2.10858 13.016 2.17125C12.9204 2.23393 12.8533 2.33235 12.8295 2.44491L11.6051 8.25987C9.04278 8.33175 6.73904 9.10729 5.07224 10.3201C4.63988 9.90099 4.05398 9.64226 3.40757 9.64226C2.0781 9.64226 1 10.7308 1 12.0737C1 13.0618 1.58457 13.9105 2.4225 14.2909C2.38466 14.5342 2.36545 14.78 2.36505 15.0263C2.36505 18.7673 6.67626 21.8 11.9945 21.8C17.3131 21.8 21.6243 18.7673 21.6243 15.0263C21.6243 14.7794 21.6043 14.5359 21.5678 14.2957C22.4109 13.9175 23 13.0657 23 12.0737Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% if prefs.disable_visit_reddit_confirmation != "on" %}
|
||||
|
@ -53,6 +53,13 @@
|
|||
<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
|
||||
</svg>
|
||||
</a>
|
||||
<a id="code" href="https://github.com/libreddit/libreddit" target="_blank" rel="noopener noreferrer">
|
||||
<span>code</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<title>code</title>
|
||||
<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
@ -63,16 +70,10 @@
|
|||
{% endblock %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
||||
<!-- FOOTER -->
|
||||
{% block footer %}
|
||||
<footer>
|
||||
<p id="version">v{{ env!("CARGO_PKG_VERSION") }}</p>
|
||||
<div class="footer-button">
|
||||
<a href="/info" title="View instance information">ⓘ View instance info</a>
|
||||
</div>
|
||||
<div class="footer-button">
|
||||
<a href="https://github.com/libreddit/libreddit" title="View code on GitHub"><> Code</a>
|
||||
<div class="info-button">
|
||||
<a href="/info" title="View instance information">ⓘ</a>
|
||||
</div>
|
||||
</footer>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% import "utils.html" as utils %}
|
||||
|
||||
{% if kind == "more" && parent_kind == "t1" %}
|
||||
<a class="deeper_replies" href="{{ post_link }}{{ parent_id }}">→ More replies ({{ more_count }})</a>
|
||||
<a class="deeper_replies" href="{{ post_link }}{{ parent_id }}">→ More replies</a>
|
||||
{% else if kind == "t1" %}
|
||||
<div id="{{ id }}" class="comment">
|
||||
<div class="comment_left">
|
||||
|
@ -35,7 +35,7 @@
|
|||
<div class="comment_body {% if highlighted %}highlighted{% endif %}">{{ body|safe }}</div>
|
||||
{% endif %}
|
||||
<blockquote class="replies">{% for c in replies -%}{{ c.render().unwrap()|safe }}{%- endfor %}
|
||||
</bockquote>
|
||||
</blockquote>
|
||||
</details>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
{% if crate::utils::sfw_only() %}
|
||||
This instance of Libreddit is SFW-only.</p>
|
||||
{% else %}
|
||||
Enable "Show NSFW posts" in <a href="/settings">settings</a> to view this {% if res_type == crate::utils::ResourceType::Subreddit %}subreddit{% else if res_type == crate::utils::ResourceType::User %}user's posts or comments{% else if res_type == crate::utils::ResourceType::Post %}post{% endif %}. <br>
|
||||
{% if res_type == crate::utils::ResourceType::Post %} You can also temporarily bypass this gate and view the post by clicking on this <a href="{{url}}&bypass_nsfw_landing">link</a>.{% endif %}
|
||||
Enable "Show NSFW posts" in <a href="/settings">settings</a> to view this {% if res_type == crate::utils::ResourceType::Subreddit %}subreddit{% else if res_type == crate::utils::ResourceType::User %}user's posts or comments{% else if res_type == crate::utils::ResourceType::Post %}post{% endif %}.
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block footer %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -43,32 +43,18 @@
|
|||
{% call utils::post(post) %}
|
||||
|
||||
<!-- SORT FORM -->
|
||||
<div id="commentQueryForms">
|
||||
<form id="sort">
|
||||
<p id="comment_count">{{post.comments.0}} {% if post.comments.0 == "1" %}comment{% else %}comments{% endif %} <span id="sorted_by">sorted by </span></p>
|
||||
<select name="sort" title="Sort comments by" id="commentSortSelect">
|
||||
<select name="sort" title="Sort comments by">
|
||||
{% call utils::options(sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %}
|
||||
</select>
|
||||
<button id="sort_submit" class="submit">
|
||||
<svg width="15" viewBox="0 0 110 100" fill="none" stroke-width="10" stroke-linecap="round">
|
||||
<path d="M20 50 H100" />
|
||||
<path d="M75 15 L100 50 L75 85" />
|
||||
→
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
<!-- SEARCH FORM -->
|
||||
<form id="sort">
|
||||
<input id="search" class="commentQuery" type="search" name="q" value="{{ comment_query }}" placeholder="Search comments">
|
||||
<input type="hidden" name="type" value="comment">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% if comment_query != "" %}
|
||||
Comments containing "{{ comment_query }}" | <a id="allCommentsLink" href="{{ url_without_query }}">All comments</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</select><button id="sort_submit" class="submit">
|
||||
<svg width="15" viewBox="0 0 110 100" fill="none" stroke-width="10" stroke-linecap="round">
|
||||
<path d="M20 50 H100" />
|
||||
<path d="M75 15 L100 50 L75 85" />
|
||||
→
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- COMMENTS -->
|
||||
{% for c in comments -%}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
→
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
{% if !is_filtered %}
|
||||
{% if subreddits.len() > 0 || params.typed == "sr_user" %}
|
||||
|
@ -99,13 +99,13 @@
|
|||
{% if params.typed != "sr_user" %}
|
||||
<footer>
|
||||
{% if params.before != "" %}
|
||||
<a href="?q={{ params.q|safe }}&restrict_sr={{ params.restrict_sr }}
|
||||
<a href="?q={{ params.q }}&restrict_sr={{ params.restrict_sr }}
|
||||
&sort={{ params.sort }}&t={{ params.t }}
|
||||
&before={{ params.before }}" accesskey="P">PREV</a>
|
||||
{% endif %}
|
||||
|
||||
{% if params.after != "" %}
|
||||
<a href="?q={{ params.q|safe }}&restrict_sr={{ params.restrict_sr }}
|
||||
<a href="?q={{ params.q }}&restrict_sr={{ params.restrict_sr }}
|
||||
&sort={{ params.sort }}&t={{ params.t }}
|
||||
&after={{ params.after }}" accesskey="N">NEXT</a>
|
||||
{% endif %}
|
||||
|
|
|
@ -88,8 +88,7 @@
|
|||
<center>(Content from r/{{ sub.name }} has been filtered)</center>
|
||||
{% endif %}
|
||||
{% if !sub.name.is_empty() && sub.name != "all" && sub.name != "popular" && !sub.name.contains("+") %}
|
||||
<details class="panel" id="subreddit" open>
|
||||
<summary id="subreddit_label">Subreddit</summary>
|
||||
<div class="panel" id="subreddit">
|
||||
{% if sub.wiki %}
|
||||
<div id="top">
|
||||
<div>Posts</div>
|
||||
|
@ -132,7 +131,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<details class="panel" id="sidebar">
|
||||
<summary id="sidebar_label">Sidebar</summary>
|
||||
<div id="sidebar_contents">
|
||||
|
|
|
@ -148,9 +148,6 @@
|
|||
<!-- POST BODY -->
|
||||
<div class="post_body">{{ post.body|safe }}</div>
|
||||
<div class="post_score" title="{{ post.score.1 }}">{{ post.score.0 }}<span class="label"> Upvotes</span></div>
|
||||
|
||||
{% call poll(post) %}
|
||||
|
||||
<div class="post_footer">
|
||||
<ul id="post_links">
|
||||
<li class="desktop_item"><a href="{{ post.permalink }}">permalink</a></li>
|
||||
|
@ -275,9 +272,6 @@
|
|||
<div class="post_body post_preview">
|
||||
{{ post.body|safe }}
|
||||
</div>
|
||||
|
||||
{% call poll(post) %}
|
||||
|
||||
<div class="post_footer">
|
||||
<a href="{{ post.permalink }}" class="post_comments" title="{{ post.comments.1 }} {% if post.comments.1 == "1" %}comment{% else %}comments{% endif %}">{{ post.comments.0 }} {% if post.comments.1 == "1" %}comment{% else %}comments{% endif %}</a>
|
||||
</div>
|
||||
|
@ -305,34 +299,3 @@
|
|||
</div>
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro poll(post) -%}
|
||||
{% match post.poll %}
|
||||
{% when Some with (poll) %}
|
||||
{% let widest = poll.most_votes() %}
|
||||
<div class="post_poll">
|
||||
<span>{{ poll.total_vote_count }} votes,</span>
|
||||
<span title="{{ poll.voting_end_timestamp.1 }}">{{ poll.voting_end_timestamp.0 }}</span>
|
||||
{% for option in poll.poll_options %}
|
||||
<div class="poll_option">
|
||||
{# Posts without vote_count (all open polls) will show up without votes.
|
||||
This is an issue with Reddit API, it doesn't work on Old Reddit either. #}
|
||||
{% match option.vote_count %}
|
||||
{% when Some with (vote_count) %}
|
||||
{% if vote_count.eq(widest) || widest == 0 %}
|
||||
<div class="poll_chart most_voted"></div>
|
||||
{% else %}
|
||||
<div class="poll_chart" style="width: {{ (vote_count * 100) / widest }}%"></div>
|
||||
{% endif %}
|
||||
<span>{{ vote_count }}</span>
|
||||
{% when None %}
|
||||
<div class="poll_chart most_voted"></div>
|
||||
<span></span>
|
||||
{% endmatch %}
|
||||
<span>{{ option.text }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% when None %}
|
||||
{% endmatch %}
|
||||
{%- endmacro %}
|
||||
|
|
Loading…
Add table
Reference in a new issue