From 225380b7d9d3dbb09222270cd8ced4da4ff6c60d Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 4 Dec 2022 10:57:19 -0800 Subject: [PATCH 1/6] Fix workflow to push to new Libreddit Docker repo --- .github/workflows/docker-arm.yml | 2 +- .github/workflows/docker-armv7.yml | 2 +- .github/workflows/docker.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-arm.yml b/.github/workflows/docker-arm.yml index 6e34e79..251e325 100644 --- a/.github/workflows/docker-arm.yml +++ b/.github/workflows/docker-arm.yml @@ -33,6 +33,6 @@ jobs: file: ./Dockerfile.arm platforms: linux/arm64 push: true - tags: spikecodes/libreddit:arm + tags: libreddit/libreddit:arm cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-armv7.yml b/.github/workflows/docker-armv7.yml index 7c51db2..d2817d8 100644 --- a/.github/workflows/docker-armv7.yml +++ b/.github/workflows/docker-armv7.yml @@ -36,6 +36,6 @@ jobs: file: ./Dockerfile.armv7 platforms: linux/arm/v7 push: true - tags: spikecodes/libreddit:armv7 + tags: libreddit/libreddit:armv7 cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ed1bf73..d9c9c5b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,6 +33,6 @@ jobs: file: ./Dockerfile platforms: linux/amd64 push: true - tags: spikecodes/libreddit:latest + tags: libreddit/libreddit:latest cache-from: type=gha cache-to: type=gha,mode=max From dc06ae3b29a18ddb0d0e13b0654afa8543a5365f Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 4 Dec 2022 11:01:28 -0800 Subject: [PATCH 2/6] Automatically-update Docker Repo description --- .github/workflows/docker.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d9c9c5b..0f25fae 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,6 +26,12 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Docker Hub Description + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: libreddit/libreddit - name: Build and push uses: docker/build-push-action@v2 with: From 87729d0daafb25b545c70157e037d3a3dd027bee Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 4 Dec 2022 11:05:19 -0800 Subject: [PATCH 3/6] Use new libreddit org for GitLab and Docker links --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ed7aa30..891e6c9 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Both files are part of the [libreddit-instances](https://github.com/libreddit/li # About -Find Libreddit on 💬 [Matrix](https://matrix.to/#/#libreddit:kde.org), 🐋 [Docker](https://hub.docker.com/r/spikecodes/libreddit), :octocat: [GitHub](https://github.com/libreddit/libreddit), and 🦊 [GitLab](https://gitlab.com/spikecodes/libreddit). +Find Libreddit on 💬 [Matrix](https://matrix.to/#/#libreddit:kde.org), 🐋 [Docker](https://hub.docker.com/r/libreddit/libreddit), :octocat: [GitHub](https://github.com/libreddit/libreddit), and 🦊 [GitLab](https://gitlab.com/libreddit/libreddit). ## Built with @@ -136,21 +136,21 @@ cargo install libreddit ## 2) Docker -Deploy the [Docker image](https://hub.docker.com/r/spikecodes/libreddit) of Libreddit: +Deploy the [Docker image](https://hub.docker.com/r/libreddit/libreddit) of Libreddit: ``` -docker pull spikecodes/libreddit -docker run -d --name libreddit -p 8080:8080 spikecodes/libreddit +docker pull libreddit/libreddit +docker run -d --name libreddit -p 8080:8080 libreddit/libreddit ``` Deploy using a different port (in this case, port 80): ``` -docker pull spikecodes/libreddit -docker run -d --name libreddit -p 80:8080 spikecodes/libreddit +docker pull libreddit/libreddit +docker run -d --name libreddit -p 80:8080 libreddit/libreddit ``` -To deploy on `arm64` platforms, simply replace `spikecodes/libreddit` in the commands above with `spikecodes/libreddit:arm`. +To deploy on `arm64` platforms, simply replace `libreddit/libreddit` in the commands above with `libreddit/libreddit:arm`. -To deploy on `armv7` platforms, simply replace `spikecodes/libreddit` in the commands above with `spikecodes/libreddit:armv7`. +To deploy on `armv7` platforms, simply replace `libreddit/libreddit` in the commands above with `libreddit/libreddit:armv7`. ## 3) AUR From 7e752b3d819ea0cd2b10be55832d75f52f2539c8 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 4 Dec 2022 11:07:18 -0800 Subject: [PATCH 4/6] Fix Docker credential secrets --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0f25fae..c90bd4d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,8 +29,8 @@ jobs: - name: Docker Hub Description uses: peter-evans/dockerhub-description@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} repository: libreddit/libreddit - name: Build and push uses: docker/build-push-action@v2 From 5d518cfc1890b64e8b76bfbae931c99a5def5fa5 Mon Sep 17 00:00:00 2001 From: Daniel Valentine Date: Sat, 3 Dec 2022 19:11:31 -0700 Subject: [PATCH 5/6] Cache result of `server::determine_compressor`. --- src/server.rs | 74 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/src/server.rs b/src/server.rs index c277b6b..501b933 100644 --- a/src/server.rs +++ b/src/server.rs @@ -243,7 +243,7 @@ impl Server { match func.await { Ok(mut res) => { res.headers_mut().extend(def_headers); - let _ = compress_response(req_headers, &mut res).await; + let _ = compress_response(&req_headers, &mut res).await; Ok(res) } @@ -282,7 +282,7 @@ async fn new_boilerplate( ) -> Result, String> { match Response::builder().status(status).body(body) { Ok(mut res) => { - let _ = compress_response(req_headers, &mut res).await; + let _ = compress_response(&req_headers, &mut res).await; res.headers_mut().extend(default_headers.clone()); Ok(res) @@ -306,7 +306,8 @@ async fn new_boilerplate( /// Accept-Encoding: gzip, compress, br /// Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1 /// ``` -fn determine_compressor(accept_encoding: &str) -> Option { +#[cached] +fn determine_compressor(accept_encoding: String) -> Option { if accept_encoding.is_empty() { return None; }; @@ -473,7 +474,7 @@ fn determine_compressor(accept_encoding: &str) -> Option { /// /// This function logs errors to stderr, but only in debug mode. No information /// is logged in release builds. -async fn compress_response(req_headers: HeaderMap, res: &mut Response) -> Result<(), String> { +async fn compress_response(req_headers: &HeaderMap, res: &mut Response) -> Result<(), String> { // Check if the data is eligible for compression. if let Some(hdr) = res.headers().get(header::CONTENT_TYPE) { match from_utf8(hdr.as_bytes()) { @@ -503,30 +504,22 @@ async fn compress_response(req_headers: HeaderMap, res: &mu return Ok(()); }; - // Quick and dirty closure for extracting a header from the request and - // returning it as a &str. - let get_req_header = |k: header::HeaderName| -> Option<&str> { - match req_headers.get(k) { - Some(hdr) => match from_utf8(hdr.as_bytes()) { - Ok(val) => Some(val), - - #[cfg(debug_assertions)] - Err(e) => { - dbg_msg!(e); - None - } - - #[cfg(not(debug_assertions))] - Err(_) => None, - }, - None => None, - } - }; - // Check to see which compressor is requested, and if we can use it. - let accept_encoding: &str = match get_req_header(header::ACCEPT_ENCODING) { - Some(val) => val, + let accept_encoding: String = match req_headers.get(header::ACCEPT_ENCODING) { None => return Ok(()), // Client requested no compression. + + Some(hdr) => match String::from_utf8(hdr.as_bytes().into()) { + Ok(val) => val, + + #[cfg(debug_assertions)] + Err(e) => { + dbg_msg!(e); + return Ok(()); + } + + #[cfg(not(debug_assertions))] + Err(_) => return Ok(()), + }, }; let compressor: CompressionType = match determine_compressor(accept_encoding) { @@ -636,18 +629,18 @@ mod tests { #[test] fn test_determine_compressor() { // Single compressor given. - assert_eq!(determine_compressor("unsupported"), None); - assert_eq!(determine_compressor("gzip"), Some(CompressionType::Gzip)); - assert_eq!(determine_compressor("*"), Some(DEFAULT_COMPRESSOR)); + assert_eq!(determine_compressor("unsupported".to_string()), None); + assert_eq!(determine_compressor("gzip".to_string()), Some(CompressionType::Gzip)); + assert_eq!(determine_compressor("*".to_string()), Some(DEFAULT_COMPRESSOR)); // Multiple compressors. - assert_eq!(determine_compressor("gzip, br"), Some(CompressionType::Brotli)); - assert_eq!(determine_compressor("gzip;q=0.8, br;q=0.3"), Some(CompressionType::Gzip)); - assert_eq!(determine_compressor("br, gzip"), Some(CompressionType::Brotli)); - assert_eq!(determine_compressor("br;q=0.3, gzip;q=0.4"), Some(CompressionType::Gzip)); + assert_eq!(determine_compressor("gzip, br".to_string()), Some(CompressionType::Brotli)); + assert_eq!(determine_compressor("gzip;q=0.8, br;q=0.3".to_string()), Some(CompressionType::Gzip)); + assert_eq!(determine_compressor("br, gzip".to_string()), Some(CompressionType::Brotli)); + assert_eq!(determine_compressor("br;q=0.3, gzip;q=0.4".to_string()), Some(CompressionType::Gzip)); // Invalid q-values. - assert_eq!(determine_compressor("gzip;q=NAN"), None); + assert_eq!(determine_compressor("gzip;q=NAN".to_string()), None); } #[test] @@ -672,9 +665,9 @@ mod tests { ] { // Determine what the expected encoding should be based on both the // specific encodings we accept. - let expected_encoding: CompressionType = match determine_compressor(accept_encoding) { + let expected_encoding: CompressionType = match determine_compressor(accept_encoding.to_string()) { Some(s) => s, - None => panic!("determine_compressor(accept_encoding) => None"), + None => panic!("determine_compressor(accept_encoding.to_string()) => None"), }; // Build headers with our Accept-Encoding. @@ -691,8 +684,8 @@ mod tests { .unwrap(); // Perform the compression. - if let Err(e) = block_on(compress_response(req_headers, &mut res)) { - panic!("compress_response(req_headers, &mut res) => Err(\"{}\")", e); + if let Err(e) = block_on(compress_response(&req_headers, &mut res)) { + panic!("compress_response(&req_headers, &mut res) => Err(\"{}\")", e); }; // If the content was compressed, we expect the Content-Encoding @@ -739,9 +732,8 @@ mod tests { }; let mut decompressed = Vec::::new(); - match io::copy(&mut decoder, &mut decompressed) { - Ok(_) => {} - Err(e) => panic!("{}", e), + if let Err(e) = io::copy(&mut decoder, &mut decompressed) { + panic!("{}", e); }; assert!(decompressed.eq(&expected_lorem_ipsum)); From 37d1939dc02ecc641636a9ca36e24f15163fd620 Mon Sep 17 00:00:00 2001 From: Daniel Valentine Date: Tue, 13 Dec 2022 21:15:28 -0700 Subject: [PATCH 6/6] Fix #658. Dimensions for embedded video in post are explicitly set only when defined by Reddit. c/o: NKIPSC <15067635+NKIPSC@users.noreply.github.com> --- Cargo.lock | 2 +- Cargo.toml | 2 +- templates/utils.html | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87c1b9a..2865f62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,7 +664,7 @@ dependencies = [ [[package]] name = "libreddit" -version = "0.25.0" +version = "0.25.1" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index 5136235..157ed31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.25.0" +version = "0.25.1" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2021" diff --git a/templates/utils.html b/templates/utils.html index 87d47a3..639b0d8 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -115,7 +115,7 @@ {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %}
-
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}
- +
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %}
-
{% else %}
- +
{% call render_hls_notification(format!("{}%23{}", &self.url[1..].replace("&", "%26").replace("+", "%2B"), post.id)) %} {% endif %}