尝试修复

This commit is contained in:
wood chen 2024-09-29 01:37:44 +08:00
parent 77801f29fa
commit 214d189e24

View File

@ -62,25 +62,25 @@ func Convert(c *fiber.Ctx) error {
log.Debugf("Incoming connection from %s %s %s", c.IP(), reqHostname, reqURIwithQuery) log.Debugf("Incoming connection from %s %s %s", c.IP(), reqHostname, reqURIwithQuery)
isRedirect := c.Query("webp_redirect") == "true" isRedirect := c.Query("webp_redirect") == "true"
if !isRedirect { if !isRedirect {
if !isImageFile(filename) { if !isImageFile(filename) {
log.Infof("Non-image file requested: %s, redirecting to original URL", filename) log.Infof("Non-image file requested: %s, redirecting to original URL", filename)
redirectURL := "" var redirectURL string
if proxyMode { if proxyMode {
// 在代理模式下使用原始的远程URL
redirectURL = realRemoteAddr redirectURL = realRemoteAddr
} else { } else {
redirectURL = reqURIwithQuery // 在非代理模式下构造本地文件的URL
} redirectURL = path.Join(config.Config.ImgPath, reqURI)
// 添加标记到重定向 URL
if strings.Contains(redirectURL, "?") {
redirectURL += "&webp_redirect=true"
} else {
redirectURL += "?webp_redirect=true"
} }
// 移除查询参数,因为它们可能是用于图像处理的
redirectURL = strings.Split(redirectURL, "?")[0]
log.Infof("Redirecting to: %s", redirectURL)
return c.Redirect(redirectURL, 302) return c.Redirect(redirectURL, 302)
} }
} }
if !helper.CheckAllowedType(filename) { if !helper.CheckAllowedType(filename) {