Resolve the issue of returning a 404 if the file name contains a+instead of a space.
This commit is contained in:
11
file.go
11
file.go
@@ -148,12 +148,23 @@ func fileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Construct the complete file path
|
||||
fullFilePath := filepath.Join("./files", filePath)
|
||||
|
||||
// Try replacing '+' with ' ' and check if the file exists
|
||||
tempFilePath := strings.ReplaceAll(fullFilePath, "+", " ")
|
||||
if _, err := os.Stat(tempFilePath); err == nil {
|
||||
fullFilePath = tempFilePath
|
||||
}
|
||||
|
||||
// Get file content
|
||||
fileContent, err := GetFileContent(fullFilePath)
|
||||
if err != nil {
|
||||
// If file not found, try replacing ' ' with '+' and check again
|
||||
tempFilePath = strings.ReplaceAll(fullFilePath, " ", "+")
|
||||
fileContent, err = GetFileContent(tempFilePath)
|
||||
if err != nil {
|
||||
NotFoundHandler(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Set appropriate Content-Type based on file extension
|
||||
ext := filepath.Ext(filePath)
|
||||
|
||||
Reference in New Issue
Block a user