Handle failure to extract id from url
This commit is contained in:
parent
f27c9fd439
commit
e6f8969399
|
@ -254,7 +254,11 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request)
|
||||||
// HeadFile returns the length and offset for the HEAD request
|
// HeadFile returns the length and offset for the HEAD request
|
||||||
func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) {
|
func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
id := extractIDFromPath(r.URL.Path)
|
id, err := extractIDFromPath(r.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
handler.sendError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
info, err := handler.dataStore.GetInfo(id)
|
info, err := handler.dataStore.GetInfo(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.sendError(w, r, err)
|
handler.sendError(w, r, err)
|
||||||
|
@ -301,7 +305,11 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id := extractIDFromPath(r.URL.Path)
|
id, err := extractIDFromPath(r.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
handler.sendError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
if _, ok := handler.locks[id]; ok {
|
if _, ok := handler.locks[id]; ok {
|
||||||
|
@ -373,7 +381,11 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
||||||
// GetFile handles requests to download a file using a GET request. This is not
|
// GetFile handles requests to download a file using a GET request. This is not
|
||||||
// part of the specification.
|
// part of the specification.
|
||||||
func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) {
|
func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) {
|
||||||
id := extractIDFromPath(r.URL.Path)
|
id, err := extractIDFromPath(r.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
handler.sendError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
if _, ok := handler.locks[id]; ok {
|
if _, ok := handler.locks[id]; ok {
|
||||||
|
@ -420,7 +432,11 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
// DelFile terminates an upload permanently.
|
// DelFile terminates an upload permanently.
|
||||||
func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request) {
|
func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request) {
|
||||||
id := extractIDFromPath(r.URL.Path)
|
id, err := extractIDFromPath(r.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
handler.sendError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
if _, ok := handler.locks[id]; ok {
|
if _, ok := handler.locks[id]; ok {
|
||||||
|
@ -436,7 +452,7 @@ func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request)
|
||||||
delete(handler.locks, id)
|
delete(handler.locks, id)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := handler.dataStore.Terminate(id)
|
err = handler.dataStore.Terminate(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.sendError(w, r, err)
|
handler.sendError(w, r, err)
|
||||||
return
|
return
|
||||||
|
@ -597,9 +613,9 @@ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
id := extractIDFromPath(value)
|
id, extractErr := extractIDFromPath(value)
|
||||||
if id == "" {
|
if extractErr != nil {
|
||||||
err = ErrInvalidConcat
|
err = extractErr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,10 +633,10 @@ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractIDFromPath pulls the last segment from the url provided
|
// extractIDFromPath pulls the last segment from the url provided
|
||||||
func extractIDFromPath(url string) string {
|
func extractIDFromPath(url string) (string, error) {
|
||||||
result := reExtractFileID.FindStringSubmatch(url)
|
result := reExtractFileID.FindStringSubmatch(url)
|
||||||
if len(result) != 2 {
|
if len(result) != 2 {
|
||||||
return ""
|
return "", ErrNotFound
|
||||||
}
|
}
|
||||||
return result[1]
|
return result[1], nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue