From a7214f243b885f99401f44d829067a8893609f99 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 01:06:05 +0000 Subject: [PATCH 01/34] build(deps): bump github.com/go-chi/chi/v5 from 5.0.7 to 5.0.8 Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.0.7 to 5.0.8. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.0.7...v5.0.8) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7bbb5be..fe26159 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/RoyXiang/plexproxy go 1.17 require ( - github.com/go-chi/chi/v5 v5.0.7 + github.com/go-chi/chi/v5 v5.0.8 github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 diff --git a/go.sum b/go.sum index 97fd108..1c62dfc 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= -github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= +github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= From 2739d7ff35380676d878b5de86da67cd7d63d9be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 01:04:45 +0000 Subject: [PATCH 02/34] build(deps): bump goreleaser/goreleaser-action from 3 to 4 Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 3 to 4. - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/v3...v4) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 4b0aa21..b53699c 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -24,7 +24,7 @@ jobs: go-version: 1.17 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 + uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser version: latest From 3cd9075afe6b4c88d7bffa600a39d2fd1442f038 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 01:03:44 +0000 Subject: [PATCH 03/34] build(deps): bump docker/build-push-action from 3 to 4 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3 to 4. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v3...v4) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 366ccbf..74e35bd 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,7 +36,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: build-args: | VERSION=${{ github.ref_name }} From d3252058f2408d6cebe2710241f739beffa699a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Mar 2023 01:59:29 +0000 Subject: [PATCH 04/34] build(deps): bump actions/setup-go from 3 to 4 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index b53699c..b38f4e3 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -19,7 +19,7 @@ jobs: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version: 1.17 - From d256309d3e3eabed65a9640342d53609252ef52a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jul 2023 01:46:33 +0000 Subject: [PATCH 05/34] build(deps): bump github.com/go-chi/chi/v5 from 5.0.8 to 5.0.10 Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.0.8 to 5.0.10. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.0.8...v5.0.10) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fe26159..df5f4c2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/RoyXiang/plexproxy go 1.17 require ( - github.com/go-chi/chi/v5 v5.0.8 + github.com/go-chi/chi/v5 v5.0.10 github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 diff --git a/go.sum b/go.sum index 1c62dfc..7d1766e 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= -github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= +github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= From 7c701d878498762c282fe7da90c0f294d928ab2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:28:09 +0000 Subject: [PATCH 06/34] build(deps): bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- .github/workflows/goreleaser.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 74e35bd..e1ba0a7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Docker meta id: meta diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index b38f4e3..f40e05c 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - From 6cab4bae859dcf902ea5c500bb77bbc5a01a8b05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 01:20:44 +0000 Subject: [PATCH 07/34] build(deps): bump goreleaser/goreleaser-action from 4 to 5 Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 4 to 5. - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/v4...v5) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index f40e05c..9380c32 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -24,7 +24,7 @@ jobs: go-version: 1.17 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest From f25e8a1bdc612efe30e6250759a1eed734aa2dd8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 01:52:56 +0000 Subject: [PATCH 08/34] build(deps): bump docker/metadata-action from 4 to 5 Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 4 to 5. - [Release notes](https://github.com/docker/metadata-action/releases) - [Upgrade guide](https://github.com/docker/metadata-action/blob/master/UPGRADE.md) - [Commits](https://github.com/docker/metadata-action/compare/v4...v5) --- updated-dependencies: - dependency-name: docker/metadata-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e1ba0a7..640fec7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,7 +15,7 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: | ghcr.io/royxiang/plexproxy From 3e6016efd5a919e983aa87e0c23e85ec670b217f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 01:53:02 +0000 Subject: [PATCH 09/34] build(deps): bump docker/login-action from 2 to 3 Bumps [docker/login-action](https://github.com/docker/login-action) from 2 to 3. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e1ba0a7..e11ef11 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,7 +29,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} From fea568cd36360879b55da9b385aeb1b0b081f96c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 01:53:08 +0000 Subject: [PATCH 10/34] build(deps): bump docker/build-push-action from 4 to 5 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v4...v5) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e1ba0a7..9a7e961 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,7 +36,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: build-args: | VERSION=${{ github.ref_name }} From e108eca9c828916a9ded8f18e1034ebbe7406f64 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 01:53:13 +0000 Subject: [PATCH 11/34] build(deps): bump docker/setup-qemu-action from 2 to 3 Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-qemu-action/releases) - [Commits](https://github.com/docker/setup-qemu-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-qemu-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e1ba0a7..f10ab6b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,7 +23,7 @@ jobs: type=semver,pattern={{version}} - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 From 2768f2c7bc0f3181545f3b709247bd262e0f606b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Sep 2023 15:33:52 +0000 Subject: [PATCH 12/34] build(deps): bump docker/setup-buildx-action from 2 to 3 Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 768e3ca..3d4fa47 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,7 +26,7 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry uses: docker/login-action@v3 From 0dbdf37e3eefad9bde6a83449fe662c7885fcfb5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:19:59 +0000 Subject: [PATCH 13/34] build(deps): bump github.com/gorilla/handlers from 1.5.1 to 1.5.2 Bumps [github.com/gorilla/handlers](https://github.com/gorilla/handlers) from 1.5.1 to 1.5.2. - [Release notes](https://github.com/gorilla/handlers/releases) - [Commits](https://github.com/gorilla/handlers/compare/v1.5.1...v1.5.2) --- updated-dependencies: - dependency-name: github.com/gorilla/handlers dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index df5f4c2..e9f29a2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/go-chi/chi/v5 v5.0.10 github.com/go-redis/redis/v8 v8.11.5 - github.com/gorilla/handlers v1.5.1 + github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.0 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa github.com/xanderstrike/plexhooks v0.0.0-20200926011736-c63bcd35fe3e @@ -14,7 +14,7 @@ require ( require ( github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/felixge/httpsnoop v1.0.1 // indirect + github.com/felixge/httpsnoop v1.0.3 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect ) diff --git a/go.sum b/go.sum index 7d1766e..62753d7 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= -github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -59,8 +59,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= +github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= +github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= From b0a3bf3cdbc4ea16fb0751174db07ebf3b418bb2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 01:37:21 +0000 Subject: [PATCH 14/34] build(deps): bump actions/setup-go from 4 to 5 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 9380c32..207b120 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -19,7 +19,7 @@ jobs: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: 1.17 - From 940ff65fb915d26d9668031caba91591ae2c5410 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 00:57:32 +0000 Subject: [PATCH 15/34] build(deps): bump github.com/gorilla/mux from 1.8.0 to 1.8.1 Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.8.0 to 1.8.1. - [Release notes](https://github.com/gorilla/mux/releases) - [Commits](https://github.com/gorilla/mux/compare/v1.8.0...v1.8.1) --- updated-dependencies: - dependency-name: github.com/gorilla/mux dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e9f29a2..440a304 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/go-chi/chi/v5 v5.0.10 github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/handlers v1.5.2 - github.com/gorilla/mux v1.8.0 + github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa github.com/xanderstrike/plexhooks v0.0.0-20200926011736-c63bcd35fe3e ) diff --git a/go.sum b/go.sum index 62753d7..e9232cc 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= From 43d7a1efccc18dc3396a5ae8c8a25a7a577d5c89 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 14 Dec 2023 15:44:34 +0800 Subject: [PATCH 16/34] feat: use in-memory cache instead of Redis --- README.md | 4 ---- go.mod | 6 +++--- go.sum | 9 ++------ handler/main.go | 48 +++++++++++++++---------------------------- handler/middleware.go | 25 +++++++++++----------- handler/plex.go | 40 +++++++----------------------------- handler/utils.go | 10 --------- 7 files changed, 41 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index 3355321..2a08f42 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,11 @@ env CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" github.com/RoyXiang/plex 1. Configure environment variables in your preferred way - `PLEX_BASEURL` (Required, e.g. `http://127.0.0.1:32400`) - - `REDIS_URL` (Optional, e.g. `redis://127.0.0.1:6379`) - * If you need a cache layer, set a value for it - `PLAXT_URL` (Optional, e.g. `https://plaxt.astandke.com/api?id=generate-your-own-silly`) * `PLEX_TOKEN` is required * Set it if you run an instance of [Plaxt](https://github.com/XanderStrike/goplaxt) * Or, you can set it to [the official one](https://plaxt.astandke.com/) - `PLEX_TOKEN` (Optional, if you need it, see [here](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)) - - `STATIC_CACHE_TTL` (Optional, default: `1h`, which controls the cache TTL of static files) - - `DYNAMIC_CACHE_TTL` (Optional, default: `1s`, which controls the cache TTL of dynamic requests) - `REDIRECT_WEB_APP` (Optional, default: `true`) - `DISABLE_TRANSCODE` (Optional, default: `true`) - `NO_REQUEST_LOGS` (Optional, default: `false`) diff --git a/go.mod b/go.mod index 440a304..e8239cb 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/RoyXiang/plexproxy go 1.17 require ( + github.com/bluele/gcache v0.0.2 github.com/go-chi/chi/v5 v5.0.10 - github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa @@ -12,11 +12,11 @@ require ( ) require ( - github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect + github.com/onsi/gomega v1.18.1 // indirect ) replace github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa => github.com/RoyXiang/go-plex-client v0.0.0-20220313053419-e24ff7ada173 diff --git a/go.sum b/go.sum index e9232cc..a2591e9 100644 --- a/go.sum +++ b/go.sum @@ -4,11 +4,10 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/RoyXiang/go-plex-client v0.0.0-20220313053419-e24ff7ada173 h1:/GJ+g7nvyg3HjY+J4p5Ag+TUoWjIrJxpHWzdbA4Phzw= github.com/RoyXiang/go-plex-client v0.0.0-20220313053419-e24ff7ada173/go.mod h1:twidbPLE4eUk3CgDno5uCzpnPRboBTElH+iJrQO7S4w= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/bluele/gcache v0.0.2 h1:WcbfdXICg7G/DGBh1PFfcirkWOQV+v077yF1pSy3DGw= +github.com/bluele/gcache v0.0.2/go.mod h1:m15KV+ECjptwSPxKhOhQoAFQVtUFjTVkc3H8o0t/fp0= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -22,8 +21,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M= github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= @@ -32,8 +29,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= -github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= diff --git a/handler/main.go b/handler/main.go index 7f10fc9..0bb2fc1 100644 --- a/handler/main.go +++ b/handler/main.go @@ -6,14 +6,12 @@ import ( "os" "github.com/go-chi/chi/v5/middleware" - "github.com/go-redis/redis/v8" "github.com/gorilla/handlers" "github.com/gorilla/mux" ) var ( - plexClient *PlexClient - redisClient *redis.Client + plexClient *PlexClient emptyStruct = struct{}{} ) @@ -23,8 +21,6 @@ func init() { BaseUrl: os.Getenv("PLEX_BASEURL"), Token: os.Getenv("PLEX_TOKEN"), PlaxtUrl: os.Getenv("PLAXT_URL"), - StaticCacheTtl: os.Getenv("STATIC_CACHE_TTL"), - DynamicCacheTtl: os.Getenv("DYNAMIC_CACHE_TTL"), RedirectWebApp: os.Getenv("REDIRECT_WEB_APP"), DisableTranscode: os.Getenv("DISABLE_TRANSCODE"), NoRequestLogs: os.Getenv("NO_REQUEST_LOGS"), @@ -32,14 +28,6 @@ func init() { if plexClient == nil { log.Fatalln("Please configure PLEX_BASEURL as a valid URL at first") } - - redisUrl := os.Getenv("REDIS_URL") - if redisUrl != "" { - options, err := redis.ParseURL(redisUrl) - if err == nil { - redisClient = redis.NewClient(options) - } - } } func NewRouter() http.Handler { @@ -50,24 +38,22 @@ func NewRouter() http.Handler { } r.Use(wrapMiddleware, middleware.Recoverer, trafficMiddleware) - if redisClient != nil { - // bypass cache - r.PathPrefix("/:/").Handler(plexClient) - r.PathPrefix("/library/parts/").Handler(plexClient) - - staticRouter := r.Methods(http.MethodGet).Subrouter() - staticRouter.Use(staticMiddleware) - staticRouter.Path("/library/media/{key}/chapterImages/{id}").Handler(plexClient) - staticRouter.Path("/library/metadata/{key}/art/{id}").Handler(plexClient) - staticRouter.Path("/library/metadata/{key}/thumb/{id}").Handler(plexClient) - staticRouter.Path("/photo/:/transcode").Handler(plexClient) - staticRouter.PathPrefix("/web/js/").Handler(plexClient) - staticRouter.PathPrefix("/web/static/").Handler(plexClient) - - dynamicRouter := r.Methods(http.MethodGet).Subrouter() - dynamicRouter.Use(dynamicMiddleware) - dynamicRouter.PathPrefix("/").Handler(plexClient) - } + // bypass cache + r.PathPrefix("/:/").Handler(plexClient) + r.PathPrefix("/library/parts/").Handler(plexClient) + + staticRouter := r.Methods(http.MethodGet).Subrouter() + staticRouter.Use(staticMiddleware) + staticRouter.Path("/library/media/{key}/chapterImages/{id}").Handler(plexClient) + staticRouter.Path("/library/metadata/{key}/art/{id}").Handler(plexClient) + staticRouter.Path("/library/metadata/{key}/thumb/{id}").Handler(plexClient) + staticRouter.Path("/photo/:/transcode").Handler(plexClient) + staticRouter.PathPrefix("/web/js/").Handler(plexClient) + staticRouter.PathPrefix("/web/static/").Handler(plexClient) + + dynamicRouter := r.Methods(http.MethodGet).Subrouter() + dynamicRouter.Use(dynamicMiddleware) + dynamicRouter.PathPrefix("/").Handler(plexClient) r.PathPrefix("/").Handler(plexClient) return r diff --git a/handler/middleware.go b/handler/middleware.go index 1ac9d87..bd20253 100644 --- a/handler/middleware.go +++ b/handler/middleware.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/http/httptest" + "net/http/httputil" "net/url" "path/filepath" "strconv" @@ -15,6 +16,7 @@ import ( "time" "github.com/RoyXiang/plexproxy/common" + "github.com/bluele/gcache" ) var ( @@ -111,7 +113,6 @@ func staticMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ Prefix: cachePrefixStatic, - Ttl: plexClient.staticCacheTtl, }) r = r.WithContext(ctx) cacheMiddleware(next).ServeHTTP(w, r) @@ -125,7 +126,6 @@ func dynamicMiddleware(next http.Handler) http.Handler { case ".css", ".ico", ".jpeg", ".jpg", ".webp": ctx = context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ Prefix: cachePrefixStatic, - Ttl: plexClient.staticCacheTtl, }) case ".m3u8", ".ts": ctx = r.Context() @@ -136,7 +136,6 @@ func dynamicMiddleware(next http.Handler) http.Handler { } ctx = context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ Prefix: cachePrefixDynamic, - Ttl: plexClient.dynamicCacheTtl, }) } cacheMiddleware(next).ServeHTTP(w, r.WithContext(ctx)) @@ -151,8 +150,8 @@ func cacheMiddleware(next http.Handler) http.Handler { return } + var cache gcache.Cache var cacheKey string - ctx := context.Background() info := ctxValue.(*cacheInfo) defer func() { @@ -161,9 +160,8 @@ func cacheMiddleware(next http.Handler) http.Handler { return } var resp *http.Response - b, err := redisClient.Get(ctx, cacheKey).Bytes() - if err == nil { - reader := bufio.NewReader(bytes.NewReader(b)) + if cacheVal, err := cache.Get(cacheKey); err == nil { + reader := bufio.NewReader(bytes.NewReader(cacheVal.([]byte))) resp, _ = http.ReadResponse(reader, r) } if resp == nil { @@ -174,8 +172,11 @@ func cacheMiddleware(next http.Handler) http.Handler { w.Header().Set(headerCacheStatus, "MISS") w.WriteHeader(resp.StatusCode) _, _ = w.Write(nw.Unwrap().(*httptest.ResponseRecorder).Body.Bytes()) - if resp.StatusCode == http.StatusOK { - writeToCache(cacheKey, resp, info.Ttl) + if resp.StatusCode != http.StatusOK { + return + } + if b, err := httputil.DumpResponse(resp, true); err == nil { + cache.Set(cacheKey, b) } }() } else { @@ -183,9 +184,6 @@ func cacheMiddleware(next http.Handler) http.Handler { w.Header().Set(headerCacheStatus, "HIT") w.WriteHeader(resp.StatusCode) _, _ = io.Copy(w, resp.Body) - if info.Prefix == cachePrefixStatic { - writeToCache(cacheKey, resp, info.Ttl) - } }() } for k, v := range resp.Header { @@ -195,7 +193,7 @@ func cacheMiddleware(next http.Handler) http.Handler { params := r.URL.Query() switch info.Prefix { case cachePrefixStatic: - break + cache = plexClient.staticCache case cachePrefixDynamic: if user := r.Context().Value(userCtxKey); user != nil { params.Set(headerUserId, strconv.Itoa(user.(*plexUser).Id)) @@ -205,6 +203,7 @@ func cacheMiddleware(next http.Handler) http.Handler { } else { return } + cache = plexClient.dynamicCache default: // invalid prefix return diff --git a/handler/plex.go b/handler/plex.go index b8682a0..f873382 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -2,7 +2,6 @@ package handler import ( "bytes" - "context" "crypto/tls" "encoding/json" "fmt" @@ -16,6 +15,7 @@ import ( "time" "github.com/RoyXiang/plexproxy/common" + "github.com/bluele/gcache" "github.com/jrudio/go-plex-client" "github.com/xanderstrike/plexhooks" ) @@ -35,8 +35,8 @@ type PlexClient struct { proxy *httputil.ReverseProxy client *plex.Plex - staticCacheTtl time.Duration - dynamicCacheTtl time.Duration + staticCache gcache.Cache + dynamicCache gcache.Cache plaxtUrl string redirectWebApp bool @@ -78,14 +78,8 @@ func NewPlexClient(config PlexConfig) *PlexClient { plaxtUrl = u.String() } - staticCacheTtl, err := time.ParseDuration(config.StaticCacheTtl) - if err != nil { - staticCacheTtl = time.Hour - } - dynamicCacheTtl, err := time.ParseDuration(config.DynamicCacheTtl) - if err != nil { - dynamicCacheTtl = time.Second - } + staticCache := gcache.New(1000).LFU().Build() + dynamicCache := gcache.New(100).LRU().Expiration(time.Second).Build() var redirectWebApp, disableTranscode, noRequestLogs bool if b, err := strconv.ParseBool(config.RedirectWebApp); err == nil { @@ -108,8 +102,8 @@ func NewPlexClient(config PlexConfig) *PlexClient { proxy: proxy, client: client, plaxtUrl: plaxtUrl, - staticCacheTtl: staticCacheTtl, - dynamicCacheTtl: dynamicCacheTtl, + staticCache: staticCache, + dynamicCache: dynamicCache, redirectWebApp: redirectWebApp, disableTranscode: disableTranscode, NoRequestLogs: noRequestLogs, @@ -192,28 +186,12 @@ func (c *PlexClient) fetchUsers(token string) { c.MulLock.Lock(lockKeyUsers) defer c.MulLock.Unlock(lockKeyUsers) - ctx := context.Background() - cacheKey := fmt.Sprintf("%s:token:%s", cachePrefixPlex, token) - isCacheEnabled := redisClient != nil - - if isCacheEnabled { - var user plexUser - err := redisClient.Get(ctx, cacheKey).Scan(&user) - if err == nil { - c.users[token] = &user - return - } - } - userInfo := c.GetAccountInfo(token) if userInfo.ID > 0 { user := plexUser{ Id: userInfo.ID, Username: userInfo.Username, } - if isCacheEnabled { - redisClient.Set(ctx, cacheKey, &user, 0).Val() - } c.users[token] = &user return } @@ -225,10 +203,6 @@ func (c *PlexClient) fetchUsers(token string) { Id: friend.UserId, Username: friend.Username, } - if isCacheEnabled { - cacheKey = fmt.Sprintf("%s:token:%s", cachePrefixPlex, friend.AccessToken) - redisClient.Set(ctx, cacheKey, &user, 0).Val() - } c.users[friend.AccessToken] = &user } } diff --git a/handler/utils.go b/handler/utils.go index a0941ce..6590b93 100644 --- a/handler/utils.go +++ b/handler/utils.go @@ -3,11 +3,9 @@ package handler import ( "context" "net/http" - "net/http/httputil" "net/url" "runtime/debug" "strings" - "time" "github.com/go-chi/chi/v5/middleware" ) @@ -89,11 +87,3 @@ func getAcceptContentType(r *http.Request) string { } return contentTypeXml } - -func writeToCache(key string, resp *http.Response, ttl time.Duration) { - b, err := httputil.DumpResponse(resp, true) - if err != nil { - return - } - redisClient.Set(context.Background(), key, b, ttl) -} From cc457254d8cecfd4907543c5b2bcb90fef7e054d Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 14 Dec 2023 15:47:13 +0800 Subject: [PATCH 17/34] refactor: minor optimization --- handler/plex.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/handler/plex.go b/handler/plex.go index f873382..f9fb447 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -127,10 +127,7 @@ func (a sessionData) Check(b sessionData) bool { return true } if a.progress != b.progress { - if a.status == sessionPlaying { - return false - } - return true + return a.status != sessionPlaying } return false } From 21a6b2f416097d57ae8a4755820634950ca408e2 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 14 Dec 2023 15:48:49 +0800 Subject: [PATCH 18/34] ci: build with the latest version of golang --- .github/workflows/goreleaser.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 207b120..7458bcc 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -21,7 +21,7 @@ jobs: name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: 1.21 - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 diff --git a/Dockerfile b/Dockerfile index 4b26685..8b399d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17 AS builder +FROM golang:1.21 AS builder ARG VERSION From 502ff293f13d7013ed30162ed9aed431c55c0cb9 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 14 Dec 2023 16:26:38 +0800 Subject: [PATCH 19/34] ci(goreleaser): ignore pull requests on changelog --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index e7adaff..fb7fc35 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,4 +20,5 @@ changelog: exclude: - "^build\\(deps\\)" - "^Merge branch" + - "^Merge pull request" - "^Revert" From 6dad12909c2c67cfcb939fb75d11bfafd810b4cf Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Sun, 17 Dec 2023 12:40:54 +0800 Subject: [PATCH 20/34] feat: make the cache size of static files configurable --- README.md | 1 + handler/main.go | 1 + handler/middleware.go | 3 +++ handler/plex.go | 10 +++++++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2a08f42..20e31fb 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ env CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" github.com/RoyXiang/plex * Set it if you run an instance of [Plaxt](https://github.com/XanderStrike/goplaxt) * Or, you can set it to [the official one](https://plaxt.astandke.com/) - `PLEX_TOKEN` (Optional, if you need it, see [here](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)) + - `STATIC_CACHE_SIZE` (Optional, the cache size of static files, e.g. CSS files, images, default: `1000`) - `REDIRECT_WEB_APP` (Optional, default: `true`) - `DISABLE_TRANSCODE` (Optional, default: `true`) - `NO_REQUEST_LOGS` (Optional, default: `false`) diff --git a/handler/main.go b/handler/main.go index 0bb2fc1..a346f88 100644 --- a/handler/main.go +++ b/handler/main.go @@ -21,6 +21,7 @@ func init() { BaseUrl: os.Getenv("PLEX_BASEURL"), Token: os.Getenv("PLEX_TOKEN"), PlaxtUrl: os.Getenv("PLAXT_URL"), + StaticCacheSize: os.Getenv("STATIC_CACHE_SIZE"), RedirectWebApp: os.Getenv("REDIRECT_WEB_APP"), DisableTranscode: os.Getenv("DISABLE_TRANSCODE"), NoRequestLogs: os.Getenv("NO_REQUEST_LOGS"), diff --git a/handler/middleware.go b/handler/middleware.go index bd20253..b735b34 100644 --- a/handler/middleware.go +++ b/handler/middleware.go @@ -193,6 +193,9 @@ func cacheMiddleware(next http.Handler) http.Handler { params := r.URL.Query() switch info.Prefix { case cachePrefixStatic: + if plexClient.staticCache == nil { + return + } cache = plexClient.staticCache case cachePrefixDynamic: if user := r.Context().Value(userCtxKey); user != nil { diff --git a/handler/plex.go b/handler/plex.go index f9fb447..7747983 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -24,8 +24,7 @@ type PlexConfig struct { BaseUrl string Token string PlaxtUrl string - StaticCacheTtl string - DynamicCacheTtl string + StaticCacheSize string RedirectWebApp string DisableTranscode string NoRequestLogs string @@ -78,7 +77,12 @@ func NewPlexClient(config PlexConfig) *PlexClient { plaxtUrl = u.String() } - staticCache := gcache.New(1000).LFU().Build() + var staticCache gcache.Cache + if config.StaticCacheSize == "" { + staticCache = gcache.New(1000).LFU().Build() + } else if staticCacheSize, err := strconv.Atoi(config.StaticCacheSize); err == nil && staticCacheSize > 0 { + staticCache = gcache.New(staticCacheSize).LFU().Build() + } dynamicCache := gcache.New(100).LRU().Expiration(time.Second).Build() var redirectWebApp, disableTranscode, noRequestLogs bool From bbf8846f7c96942b7b507f6d3a8879931dc6284e Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Sun, 17 Dec 2023 12:55:12 +0800 Subject: [PATCH 21/34] feat: skip traffic control on streaming requests --- handler/main.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/handler/main.go b/handler/main.go index a346f88..95017f8 100644 --- a/handler/main.go +++ b/handler/main.go @@ -37,13 +37,17 @@ func NewRouter() http.Handler { if !plexClient.NoRequestLogs { r.Use(middleware.Logger) } - r.Use(wrapMiddleware, middleware.Recoverer, trafficMiddleware) + r.Use(wrapMiddleware, middleware.Recoverer) - // bypass cache - r.PathPrefix("/:/").Handler(plexClient) - r.PathPrefix("/library/parts/").Handler(plexClient) + streamingRouter := r.NewRoute().Subrouter() + streamingRouter.PathPrefix("/library/parts/").Handler(plexClient) + streamingRouter.PathPrefix("/video/:/transcode/").Handler(plexClient) - staticRouter := r.Methods(http.MethodGet).Subrouter() + getRouter := r.Methods(http.MethodGet).Subrouter() + getRouter.Use(trafficMiddleware) + getRouter.PathPrefix("/:/").Handler(plexClient) + + staticRouter := getRouter.NewRoute().Subrouter() staticRouter.Use(staticMiddleware) staticRouter.Path("/library/media/{key}/chapterImages/{id}").Handler(plexClient) staticRouter.Path("/library/metadata/{key}/art/{id}").Handler(plexClient) @@ -52,7 +56,7 @@ func NewRouter() http.Handler { staticRouter.PathPrefix("/web/js/").Handler(plexClient) staticRouter.PathPrefix("/web/static/").Handler(plexClient) - dynamicRouter := r.Methods(http.MethodGet).Subrouter() + dynamicRouter := getRouter.NewRoute().Subrouter() dynamicRouter.Use(dynamicMiddleware) dynamicRouter.PathPrefix("/").Handler(plexClient) From 7b3e490b5516f6862ce7bd73e98ec62beb9d0480 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 01:37:15 +0000 Subject: [PATCH 22/34] build(deps): bump github.com/go-chi/chi/v5 from 5.0.10 to 5.0.11 Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.0.10 to 5.0.11. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.0.10...v5.0.11) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e8239cb..c85bbce 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/bluele/gcache v0.0.2 - github.com/go-chi/chi/v5 v5.0.10 + github.com/go-chi/chi/v5 v5.0.11 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa diff --git a/go.sum b/go.sum index a2591e9..887077a 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= +github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= From ad93d4847cd0fec2cb4d875695d90e2e87217644 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Sun, 24 Dec 2023 16:35:34 +0800 Subject: [PATCH 23/34] feat: disable client-side cache of some requests by setting response headers --- handler/main.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/handler/main.go b/handler/main.go index 95017f8..3d7e3e5 100644 --- a/handler/main.go +++ b/handler/main.go @@ -37,17 +37,15 @@ func NewRouter() http.Handler { if !plexClient.NoRequestLogs { r.Use(middleware.Logger) } - r.Use(wrapMiddleware, middleware.Recoverer) + r.Use(wrapMiddleware, middleware.Recoverer, trafficMiddleware) - streamingRouter := r.NewRoute().Subrouter() - streamingRouter.PathPrefix("/library/parts/").Handler(plexClient) - streamingRouter.PathPrefix("/video/:/transcode/").Handler(plexClient) + noCacheRouter := r.Methods(http.MethodGet).Subrouter() + noCacheRouter.Use(middleware.NoCache) + noCacheRouter.PathPrefix("/:/").Handler(plexClient) + noCacheRouter.PathPrefix("/library/parts/").Handler(plexClient) + noCacheRouter.PathPrefix("/video/:/transcode/").Handler(plexClient) - getRouter := r.Methods(http.MethodGet).Subrouter() - getRouter.Use(trafficMiddleware) - getRouter.PathPrefix("/:/").Handler(plexClient) - - staticRouter := getRouter.NewRoute().Subrouter() + staticRouter := r.Methods(http.MethodGet).Subrouter() staticRouter.Use(staticMiddleware) staticRouter.Path("/library/media/{key}/chapterImages/{id}").Handler(plexClient) staticRouter.Path("/library/metadata/{key}/art/{id}").Handler(plexClient) @@ -56,7 +54,7 @@ func NewRouter() http.Handler { staticRouter.PathPrefix("/web/js/").Handler(plexClient) staticRouter.PathPrefix("/web/static/").Handler(plexClient) - dynamicRouter := getRouter.NewRoute().Subrouter() + dynamicRouter := r.Methods(http.MethodGet).Subrouter() dynamicRouter.Use(dynamicMiddleware) dynamicRouter.PathPrefix("/").Handler(plexClient) From f8565b3625f1584debbadef465cf0df532bdda8b Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Mon, 25 Dec 2023 12:58:00 +0800 Subject: [PATCH 24/34] refactor: remove github.com/gorilla/handlers --- go.mod | 2 -- go.sum | 4 ---- handler/const.go | 6 ++++++ handler/main.go | 3 +-- handler/utils.go | 28 ++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index c85bbce..92fc5b3 100644 --- a/go.mod +++ b/go.mod @@ -5,14 +5,12 @@ go 1.17 require ( github.com/bluele/gcache v0.0.2 github.com/go-chi/chi/v5 v5.0.11 - github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa github.com/xanderstrike/plexhooks v0.0.0-20200926011736-c63bcd35fe3e ) require ( - github.com/felixge/httpsnoop v1.0.3 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/onsi/ginkgo v1.16.5 // indirect diff --git a/go.sum b/go.sum index 887077a..bdb1351 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,6 @@ github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= -github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -54,8 +52,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= -github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= diff --git a/handler/const.go b/handler/const.go index 0494caa..e4fde35 100644 --- a/handler/const.go +++ b/handler/const.go @@ -9,6 +9,7 @@ const ( headerPageStart = "X-Plex-Container-Start" headerToken = "X-Plex-Token" headerUserId = "X-Plex-User-Id" + headerAccept = "Accept" headerAcceptLanguage = "Accept-Language" headerCacheControl = "Cache-Control" @@ -16,6 +17,11 @@ const ( headerRange = "Range" headerVary = "Vary" + headerForwardedFor = "X-Forwarded-For" + headerRealIP = "X-Real-IP" + headerForwardedProto = "X-Forwarded-Proto" + headerForwardedScheme = "X-Forwarded-Scheme" + cachePrefixDynamic = "dynamic" cachePrefixStatic = "static" cachePrefixPlex = "plex" diff --git a/handler/main.go b/handler/main.go index 3d7e3e5..fec84cf 100644 --- a/handler/main.go +++ b/handler/main.go @@ -6,7 +6,6 @@ import ( "os" "github.com/go-chi/chi/v5/middleware" - "github.com/gorilla/handlers" "github.com/gorilla/mux" ) @@ -33,7 +32,7 @@ func init() { func NewRouter() http.Handler { r := mux.NewRouter() - r.Use(handlers.ProxyHeaders, normalizeMiddleware) + r.Use(normalizeMiddleware) if !plexClient.NoRequestLogs { r.Use(middleware.Logger) } diff --git a/handler/utils.go b/handler/utils.go index 6590b93..084b005 100644 --- a/handler/utils.go +++ b/handler/utils.go @@ -65,9 +65,37 @@ func cloneRequest(r *http.Request, headers http.Header, query url.Values) *http. nr.URL.RawQuery = query.Encode() nr.RequestURI = nr.URL.RequestURI() } + if fwd := getIP(headers); fwd != "" { + nr.RemoteAddr = fwd + } + if scheme := getScheme(headers); scheme != "" { + nr.URL.Scheme = scheme + } return nr } +func getIP(headers http.Header) (addr string) { + if fwd := headers.Get(headerForwardedFor); fwd != "" { + s := strings.Index(fwd, ", ") + if s == -1 { + s = len(fwd) + } + addr = fwd[:s] + } else if fwd = headers.Get(headerRealIP); fwd != "" { + addr = fwd + } + return +} + +func getScheme(headers http.Header) (scheme string) { + if proto := headers.Get(headerForwardedProto); proto != "" { + scheme = strings.ToLower(proto) + } else if proto = headers.Get(headerForwardedScheme); proto != "" { + scheme = strings.ToLower(proto) + } + return +} + func getAcceptContentType(r *http.Request) string { accept := r.Header.Get(headerAccept) if accept == "" { From ccf3a4ea161b2aa2f4699b58dd335d0efc658ff6 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Mon, 25 Dec 2023 13:26:52 +0800 Subject: [PATCH 25/34] feat: only enable browser cache for some content types --- handler/main.go | 6 ------ handler/utils.go | 23 ++++++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/handler/main.go b/handler/main.go index fec84cf..dcfc2a0 100644 --- a/handler/main.go +++ b/handler/main.go @@ -38,12 +38,6 @@ func NewRouter() http.Handler { } r.Use(wrapMiddleware, middleware.Recoverer, trafficMiddleware) - noCacheRouter := r.Methods(http.MethodGet).Subrouter() - noCacheRouter.Use(middleware.NoCache) - noCacheRouter.PathPrefix("/:/").Handler(plexClient) - noCacheRouter.PathPrefix("/library/parts/").Handler(plexClient) - noCacheRouter.PathPrefix("/video/:/transcode/").Handler(plexClient) - staticRouter := r.Methods(http.MethodGet).Subrouter() staticRouter.Use(staticMiddleware) staticRouter.Path("/library/media/{key}/chapterImages/{id}").Handler(plexClient) diff --git a/handler/utils.go b/handler/utils.go index 084b005..0debb5c 100644 --- a/handler/utils.go +++ b/handler/utils.go @@ -2,6 +2,7 @@ package handler import ( "context" + "mime" "net/http" "net/url" "runtime/debug" @@ -18,22 +19,18 @@ func wrapResponseWriter(w http.ResponseWriter, protoMajor int) middleware.WrapRe } func modifyResponse(resp *http.Response) error { - contentType := resp.Header.Get(headerContentType) - if contentType == "" { - return nil + var mediaType string + if contentType := resp.Header.Get(headerContentType); contentType != "" { + mediaType, _, _ = mime.ParseMediaType(contentType) } - pieces := strings.Split(contentType, "/") - if len(pieces) == 0 { - return nil - } - switch pieces[0] { - case "audio", "video": - resp.Header.Set(headerCacheControl, "no-cache") - resp.Header.Set(headerVary, "*") - case "image": + switch { + case mediaType == "text/css", + mediaType == "text/javascript", + strings.HasPrefix(mediaType, "image/"), + strings.HasPrefix(mediaType, "font/"): resp.Header.Set(headerCacheControl, "public, max-age=86400, s-maxage=259200") default: - resp.Header.Set(headerCacheControl, "no-cache") + resp.Header.Set(headerCacheControl, "no-cache, no-store, no-transform, must-revalidate, private, max-age=0, s-maxage=0") } return nil } From c69ee80ae8ec056752c1791065e4cd7584630471 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 28 Dec 2023 21:37:02 +0800 Subject: [PATCH 26/34] fix(handler): do not cache websocket connections --- handler/const.go | 1 + handler/middleware.go | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/handler/const.go b/handler/const.go index e4fde35..e2facfc 100644 --- a/handler/const.go +++ b/handler/const.go @@ -16,6 +16,7 @@ const ( headerContentType = "Content-Type" headerRange = "Range" headerVary = "Vary" + headerUpgrade = "Upgrade" headerForwardedFor = "X-Forwarded-For" headerRealIP = "X-Real-IP" diff --git a/handler/middleware.go b/handler/middleware.go index b735b34..ea603ba 100644 --- a/handler/middleware.go +++ b/handler/middleware.go @@ -121,24 +121,27 @@ func staticMiddleware(next http.Handler) http.Handler { func dynamicMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var ctx context.Context + nr := r switch filepath.Ext(r.URL.EscapedPath()) { - case ".css", ".ico", ".jpeg", ".jpg", ".webp": - ctx = context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ + case ".css", ".ico", ".jpeg", ".jpg", ".js", ".webp": + ctx := context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ Prefix: cachePrefixStatic, }) + nr = r.WithContext(ctx) case ".m3u8", ".ts": - ctx = r.Context() + break default: if rh := r.Header.Get(headerRange); rh != "" { - ctx = r.Context() + break + } else if upgrade := r.Header.Get(headerUpgrade); upgrade == "websocket" { break } - ctx = context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ + ctx := context.WithValue(r.Context(), cacheInfoCtxKey, &cacheInfo{ Prefix: cachePrefixDynamic, }) + nr = r.WithContext(ctx) } - cacheMiddleware(next).ServeHTTP(w, r.WithContext(ctx)) + cacheMiddleware(next).ServeHTTP(w, nr) }) } From c189db5cce57843f0ffd4b85059e71fd7becc564 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Sun, 7 Jan 2024 00:13:24 +0800 Subject: [PATCH 27/34] feat: try to alter some direct play settings --- handler/plex.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/handler/plex.go b/handler/plex.go index 7747983..287f632 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -511,13 +511,10 @@ func (c *PlexClient) disableTranscoding(r *http.Request) *http.Request { query.Set("directStreamAudio", "1") query.Set("videoQuality", "100") query.Set("videoResolution", "4096x2160") - - protocol := query.Get("protocol") - switch protocol { - case "http": - query.Set("copyts", "0") - query.Set("hasMDE", "0") - } + query.Set("protocol", "hls") + query.Set("copyts", "1") + query.Set("hasMDE", "1") + query.Set("fastSeek", "1") headers := r.Header if extraProfile := headers.Get(headerExtraProfile); extraProfile != "" { From f1a68ebb0f7c71129f1b202ccd88bc9d279f5004 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Sun, 7 Jan 2024 09:19:22 +0800 Subject: [PATCH 28/34] Revert "feat: try to alter some direct play settings" This reverts commit c189db5cce57843f0ffd4b85059e71fd7becc564. --- handler/plex.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/handler/plex.go b/handler/plex.go index 287f632..7747983 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -511,10 +511,13 @@ func (c *PlexClient) disableTranscoding(r *http.Request) *http.Request { query.Set("directStreamAudio", "1") query.Set("videoQuality", "100") query.Set("videoResolution", "4096x2160") - query.Set("protocol", "hls") - query.Set("copyts", "1") - query.Set("hasMDE", "1") - query.Set("fastSeek", "1") + + protocol := query.Get("protocol") + switch protocol { + case "http": + query.Set("copyts", "0") + query.Set("hasMDE", "0") + } headers := r.Header if extraProfile := headers.Get(headerExtraProfile); extraProfile != "" { From 0cd6d011d889f3672399276f5786bab59d9fe6cd Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Thu, 25 Jan 2024 11:22:12 +0800 Subject: [PATCH 29/34] feat: set a default TTL for the cache of static files --- README.md | 1 + handler/main.go | 1 + handler/plex.go | 16 +++++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 20e31fb..a6d23aa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ env CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" github.com/RoyXiang/plex * Or, you can set it to [the official one](https://plaxt.astandke.com/) - `PLEX_TOKEN` (Optional, if you need it, see [here](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)) - `STATIC_CACHE_SIZE` (Optional, the cache size of static files, e.g. CSS files, images, default: `1000`) + - `STATIC_CACHE_TTL` (Optional, the cache TTL of static files, default: `72h`) - `REDIRECT_WEB_APP` (Optional, default: `true`) - `DISABLE_TRANSCODE` (Optional, default: `true`) - `NO_REQUEST_LOGS` (Optional, default: `false`) diff --git a/handler/main.go b/handler/main.go index dcfc2a0..74986dd 100644 --- a/handler/main.go +++ b/handler/main.go @@ -21,6 +21,7 @@ func init() { Token: os.Getenv("PLEX_TOKEN"), PlaxtUrl: os.Getenv("PLAXT_URL"), StaticCacheSize: os.Getenv("STATIC_CACHE_SIZE"), + StaticCacheTtl: os.Getenv("STATIC_CACHE_TTL"), RedirectWebApp: os.Getenv("REDIRECT_WEB_APP"), DisableTranscode: os.Getenv("DISABLE_TRANSCODE"), NoRequestLogs: os.Getenv("NO_REQUEST_LOGS"), diff --git a/handler/plex.go b/handler/plex.go index 7747983..4ce2ff0 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -25,6 +25,7 @@ type PlexConfig struct { Token string PlaxtUrl string StaticCacheSize string + StaticCacheTtl string RedirectWebApp string DisableTranscode string NoRequestLogs string @@ -77,12 +78,17 @@ func NewPlexClient(config PlexConfig) *PlexClient { plaxtUrl = u.String() } - var staticCache gcache.Cache - if config.StaticCacheSize == "" { - staticCache = gcache.New(1000).LFU().Build() - } else if staticCacheSize, err := strconv.Atoi(config.StaticCacheSize); err == nil && staticCacheSize > 0 { - staticCache = gcache.New(staticCacheSize).LFU().Build() + var ( + staticCacheSize int + staticCacheTtl time.Duration + ) + if staticCacheSize, err = strconv.Atoi(config.StaticCacheSize); err != nil || staticCacheSize <= 0 { + staticCacheSize = 1000 } + if staticCacheTtl, err = time.ParseDuration(config.StaticCacheTtl); err != nil { + staticCacheTtl = time.Hour * 24 * 3 + } + staticCache := gcache.New(staticCacheSize).LFU().Expiration(staticCacheTtl).Build() dynamicCache := gcache.New(100).LRU().Expiration(time.Second).Build() var redirectWebApp, disableTranscode, noRequestLogs bool From d1697ced5b347d51afeac5b6464a04b75cab3d91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 01:50:19 +0000 Subject: [PATCH 30/34] build(deps): bump github.com/go-chi/chi/v5 from 5.0.11 to 5.0.12 Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.0.11 to 5.0.12. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.0.11...v5.0.12) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 92fc5b3..0e8dc7b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/bluele/gcache v0.0.2 - github.com/go-chi/chi/v5 v5.0.11 + github.com/go-chi/chi/v5 v5.0.12 github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa github.com/xanderstrike/plexhooks v0.0.0-20200926011736-c63bcd35fe3e diff --git a/go.sum b/go.sum index bdb1351..c5de490 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= -github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= +github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= From 5c0a8308ceea057fc994bb06fcee5a116e428596 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 01:05:01 +0000 Subject: [PATCH 31/34] build(deps): bump github.com/go-chi/chi/v5 from 5.0.12 to 5.1.0 Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.0.12 to 5.1.0. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.0.12...v5.1.0) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0e8dc7b..c749a29 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/bluele/gcache v0.0.2 - github.com/go-chi/chi/v5 v5.0.12 + github.com/go-chi/chi/v5 v5.1.0 github.com/gorilla/mux v1.8.1 github.com/jrudio/go-plex-client v0.0.0-20220106065909-9e1d590b99aa github.com/xanderstrike/plexhooks v0.0.0-20200926011736-c63bcd35fe3e diff --git a/go.sum b/go.sum index c5de490..e405687 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= -github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= From aab88e496a8e40c0e32010409a1d1a1665b76a91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 01:37:17 +0000 Subject: [PATCH 32/34] build(deps): bump docker/build-push-action from 5 to 6 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5...v6) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3d4fa47..d140282 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,7 +36,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: build-args: | VERSION=${{ github.ref_name }} From d7a91660bcc878731b2956a9b3278b19772fc3fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 01:37:19 +0000 Subject: [PATCH 33/34] build(deps): bump goreleaser/goreleaser-action from 5 to 6 Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 5 to 6. - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/v5...v6) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 7458bcc..565fed0 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -24,7 +24,7 @@ jobs: go-version: 1.21 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest From c627fa348146499d8ed425b13b269e4f4941b117 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Wed, 14 Aug 2024 11:20:24 +0800 Subject: [PATCH 34/34] build: use a fixed version of goreleaser and unify the version of Golang --- .github/workflows/goreleaser.yml | 4 ++-- go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 565fed0..6c3b00e 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -27,7 +27,7 @@ jobs: uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser - version: latest - args: release --rm-dist + version: '~> v1' + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/go.mod b/go.mod index c749a29..eec962b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/RoyXiang/plexproxy -go 1.17 +go 1.21 require ( github.com/bluele/gcache v0.0.2