Skip to content

Commit

Permalink
feat: replace imgproxy with thumbor
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 16, 2024
1 parent 3272678 commit af2ac45
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
24 changes: 14 additions & 10 deletions docker-compose.deps.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
version: "3.7"
services:
imgproxy:
image: darthsim/imgproxy:latest
container_name: rere-imgproxy
thumbor:
image: mvhirsch/thumbor:latest
container_name: thumbor
restart: always
ports:
- 2873:8080
- 2873:8888
environment:
- IMGPROXY_ENABLE_WEBP_DETECTION=true
- IMGPROXY_ENABLE_AVIF_DETECTION=true
- IMGPROXY_READ_TIMEOUT=30
- IMGPROXY_DOWNLOAD_TIMEOUT=30
- IMGPROXY_TRUSTED_SIGNATURES=follow
- IMGPROXY_IGNORE_SSL_VERIFICATION=true
- HTTP_LOADER_FORWARD_HEADERS_WHITELIST=["Referer"]
- AUTO_WEBP=True
- HTTP_LOADER_CONNECT_TIMEOUT=10
- HTTP_LOADER_REQUEST_TIMEOUT=30
- RESULT_STORAGE_STORES_UNSAFE=True
volumes:
- thumbor:/usr/local/thumbor/result_storage

volumes:
thumbor:
22 changes: 18 additions & 4 deletions src/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,27 @@ export function createWindow(): void {
]
mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
(details, callback) => {
const refererMatch = refererMatchs.find((item) =>
item.url.test(details.url),
)
let trueUrl
if (
process.env["VITE_IMGPROXY_URL"] &&
details.url.startsWith(process.env["VITE_IMGPROXY_URL"])
) {
trueUrl = decodeURIComponent(
details.url.replace(
new RegExp(
`^${process.env["VITE_IMGPROXY_URL"]}/unsafe/\\d+x\\d+\/`,
),
"",
),
)
} else {
trueUrl = details.url
}
const refererMatch = refererMatchs.find((item) => item.url.test(trueUrl))
callback({
requestHeaders: {
...details.requestHeaders,
Referer: refererMatch?.referer || details.url,
Referer: refererMatch?.referer || trueUrl,
},
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/lib/img-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const getProxyUrl = ({
width: number
height: number
}) => {
return `${import.meta.env.VITE_IMGPROXY_URL}/follow/rs:fill:${width}:${height}/plain/${url}`
return `${import.meta.env.VITE_IMGPROXY_URL}/unsafe/${width}x${height}/${encodeURIComponent(url)}`
}

0 comments on commit af2ac45

Please sign in to comment.