feat: replace imgproxy with thumbor

This commit is contained in:
DIYgod 2024-05-16 14:30:31 +08:00
parent 3272678dd8
commit af2ac453e0
No known key found for this signature in database
3 changed files with 33 additions and 15 deletions

View File

@ -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:

View File

@ -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,
},
})
},

View File

@ -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)}`
}