Skip to content

Commit

Permalink
fix: Account for baseURL when deleting files (site.unload). #1557 (#1558
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mturoci authored Aug 3, 2022
1 parent 20f74be commit 00a6e92
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions file_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

if err := fs.deleteFile(r.URL.Path); err != nil {
if err := fs.deleteFile(r.URL.Path, fs.baseURL); err != nil {
echo(Log{"t": "file_unload", "path": r.URL.Path, "error": err.Error()})
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
echo(Log{"t": "file_unload", "path": r.URL.Path})
Expand Down Expand Up @@ -172,8 +173,10 @@ func (fs *FileServer) acceptFiles(r *http.Request) ([]string, error) {
return uploadPaths, nil
}

func (fs *FileServer) deleteFile(url string) error {
tokens := strings.Split(path.Clean(url), "/")
func (fs *FileServer) deleteFile(url, baseURL string) error {
// Remove baseURL portion if specified.
cleanURL := strings.Replace(path.Clean(url), baseURL, "/_f", 1)
tokens := strings.Split(cleanURL, "/")
if len(tokens) != 4 { // /_f/uuid/file.ext
return errInvalidUnloadPath
}
Expand Down

0 comments on commit 00a6e92

Please sign in to comment.