尝试修复非图片文件的重定向问题,并优化了代码结构。

This commit is contained in:
wood chen 2024-09-29 15:17:45 +08:00
parent 0b494e08ac
commit 585f9a52b8
2 changed files with 45 additions and 49 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.23-bookworm as builder
FROM golang:1.23-bookworm AS builder
ARG IMG_PATH=/opt/pics
ARG EXHAUST_PATH=/opt/exhaust

View File

@ -3,21 +3,19 @@ package handler
import (
"net/http"
"net/url"
"path"
"regexp"
"slices"
"strconv"
"strings"
"webp_server_go/config"
"webp_server_go/encoder"
"webp_server_go/helper"
"slices"
"path"
"strconv"
"github.com/gofiber/fiber/v2"
log "github.com/sirupsen/logrus"
)
func Convert(c *fiber.Ctx) error {
// this function need to do:
// 1. get request path, query string
@ -61,12 +59,10 @@ func Convert(c *fiber.Ctx) error {
log.Debugf("Incoming connection from %s %s %s", c.IP(), reqHostname, reqURIwithQuery)
// 非图片清况下302到源文件
//
//
//
reqURI := c.Path()
filename := path.Base(reqURI)
// 非图片清况下302到源文件
//
//
//
// 处理根路径请求
if reqURI == "/" {
@ -106,8 +102,8 @@ func Convert(c *fiber.Ctx) error {
return c.Redirect(redirectURL, fiber.StatusFound)
}
//
//
//
//
if !helper.CheckAllowedType(filename) {
msg := "File extension not allowed! " + filename