Skip to content

Commit

Permalink
Allow upload ID to contain slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Oct 25, 2023
1 parent 4804209 commit fce3b46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 17 additions & 15 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package handler

import (
"net/http"

"github.com/bmizerany/pat"
)

// Handler is a ready to use handler with routing (using pat)
Expand Down Expand Up @@ -33,21 +31,25 @@ func NewHandler(config Config) (*Handler, error) {
UnroutedHandler: handler,
}

mux := pat.New()
mux := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "POST" && r.URL.Path == "":
handler.PostFile(w, r)
case r.Method == "HEAD" && r.URL.Path != "":
handler.HeadFile(w, r)
case r.Method == "PATCH" && r.URL.Path != "":
handler.PatchFile(w, r)
case r.Method == "GET" && r.URL.Path != "" && !config.DisableDownload:
handler.GetFile(w, r)
case r.Method == "DELETE" && r.URL.Path != "" && config.StoreComposer.UsesTerminater && !config.DisableTermination:
handler.DelFile(w, r)
default:
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`combination of path and method are not recognized`))
}
})

routedHandler.Handler = handler.Middleware(mux)

mux.Post("", http.HandlerFunc(handler.PostFile))
mux.Head(":id", http.HandlerFunc(handler.HeadFile))
mux.Add("PATCH", ":id", http.HandlerFunc(handler.PatchFile))
if !config.DisableDownload {
mux.Get(":id", http.HandlerFunc(handler.GetFile))
}

// Only attach the DELETE handler if the Terminate() method is provided
if config.StoreComposer.UsesTerminater && !config.DisableTermination {
mux.Del(":id", http.HandlerFunc(handler.DelFile))
}

return routedHandler, nil
}
4 changes: 4 additions & 0 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"errors"
"fmt"
"io"
"math"
"mime"
Expand Down Expand Up @@ -1440,6 +1441,9 @@ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []

// extractIDFromPath pulls the last segment from the url provided
func extractIDFromPath(url string) (string, error) {
return url, nil

fmt.Println(">>>>>>>", url)
result := reExtractFileID.FindStringSubmatch(url)
if len(result) != 2 {
return "", ErrNotFound
Expand Down

0 comments on commit fce3b46

Please sign in to comment.