mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-19 14:12:01 +08:00
refactor(router): improve remote address construction logic
This commit is contained in:
parent
b7d9419408
commit
2a61cc9247
@ -106,12 +106,18 @@ func Convert(c *fiber.Ctx) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建正确的远程地址
|
targetHostName := targetUrl.Host
|
||||||
remoteAddr := strings.TrimRight(targetUrl.String(), "/")
|
targetHost := targetUrl.Scheme + "://" + targetUrl.Host
|
||||||
relativePath := strings.TrimLeft(strings.TrimPrefix(reqURI, matchedPrefix), "/")
|
|
||||||
remoteAddr = remoteAddr + "/" + relativePath
|
|
||||||
|
|
||||||
rawImageAbs, isNewDownload, err = fetchRemoteImg(remoteAddr, targetUrl.Host)
|
// 保留查询参数
|
||||||
|
reqURIwithQuery := strings.Replace(reqURIwithQuery, matchedPrefix, targetUrl.Path, 1)
|
||||||
|
if strings.HasSuffix(targetUrl.Path, "/") {
|
||||||
|
reqURIwithQuery = strings.TrimPrefix(reqURIwithQuery, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
realRemoteAddr := targetHost + reqURIwithQuery
|
||||||
|
|
||||||
|
rawImageAbs, isNewDownload, err = fetchRemoteImg(realRemoteAddr, targetHostName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
processErr = fmt.Errorf("获取远程图像失败")
|
processErr = fmt.Errorf("获取远程图像失败")
|
||||||
log.Errorf("%s: %v", processErr, err)
|
log.Errorf("%s: %v", processErr, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user