如果本地文件存在,直接输出
This commit is contained in:
@@ -490,6 +490,7 @@ func main() {
|
||||
reg := regexp.MustCompile(`^/img/([0-9a-zA-Z]+)-([0-9a-zA-Z]+).(jpg|jpeg|png|webp)$`)
|
||||
matches := reg.FindStringSubmatch(r.URL.Path)
|
||||
if len(matches) != 4 {
|
||||
log.Println("URL 格式错误", r.URL.Path)
|
||||
http.Error(w, "URL 格式错误", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -524,7 +525,7 @@ func main() {
|
||||
|
||||
// 如果本地文件存在,直接输出
|
||||
filePath := filepath.Join("data/webp", r.URL.Path)
|
||||
if _, err := os.Stat(filePath); err != nil {
|
||||
if _, err := os.Stat(filePath); err == nil {
|
||||
http.ServeFile(w, r, filePath)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user