Skip to content

Commit

Permalink
feat: Set route tag as a relative path
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Jan 4, 2024
1 parent fcb1852 commit 797ae3d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/crud/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func (s Service) Create(w http.ResponseWriter, r *http.Request, request provider.Request) {
fibr.SetRouteTag(r.Context(), "PUT mkdir")
fibr.SetRouteTag(r.Context(), "/mkdir")

if !request.CanEdit {
s.error(w, r, request, model.WrapForbidden(ErrNotAuthorized))
Expand Down
3 changes: 0 additions & 3 deletions pkg/crud/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import (
"fmt"
"net/http"

"github.com/ViBiOh/fibr/pkg/fibr"
"github.com/ViBiOh/fibr/pkg/provider"
"github.com/ViBiOh/httputils/v4/pkg/cntxt"
"github.com/ViBiOh/httputils/v4/pkg/model"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
)

func (s Service) Delete(w http.ResponseWriter, r *http.Request, request provider.Request) {
fibr.SetRouteTag(r.Context(), "DELETE")

if !request.CanEdit {
s.error(w, r, request, model.WrapForbidden(ErrNotAuthorized))
return
Expand Down
12 changes: 6 additions & 6 deletions pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,38 @@ func (s Service) handleDir(w http.ResponseWriter, r *http.Request, request provi
}

if query.GetBool(r, "geojson") {
fibr.SetRouteTag(r.Context(), "GET geojson")
fibr.SetRouteTag(r.Context(), "/geojson")
s.serveGeoJSON(w, r, request, item, items)
return renderer.Page{}, nil
}

if query.GetBool(r, "thumbnail") {
fibr.SetRouteTag(r.Context(), "GET thumbnail")
fibr.SetRouteTag(r.Context(), "/thumbnail")
s.thumbnail.List(w, r, item, items)
return renderer.Page{}, nil
}

if query.GetBool(r, "download") {
fibr.SetRouteTag(r.Context(), "GET download")
fibr.SetRouteTag(r.Context(), "/download")
s.Download(w, r, request, items)
return errorReturn(request, err)
}

go s.pushEvent(cntxt.WithoutDeadline(r.Context()), provider.NewAccessEvent(r.Context(), item, r))

if query.GetBool(r, "search") {
fibr.SetRouteTag(r.Context(), "GET search")
fibr.SetRouteTag(r.Context(), "/search")
return s.search(r, request, item, items)
}

provider.SetPrefsCookie(w, request)

if request.IsStory() {
fibr.SetRouteTag(r.Context(), "GET story")
fibr.SetRouteTag(r.Context(), "/story")
return s.story(r, request, item, items)
}

fibr.SetRouteTag(r.Context(), "GET directory")
fibr.SetRouteTag(r.Context(), "/directory")
return s.list(r.Context(), request, message, item, items)
}

Expand Down
14 changes: 6 additions & 8 deletions pkg/crud/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func parseMultipart(r *http.Request) (map[string]string, *multipart.Part, error)
func (s Service) Post(w http.ResponseWriter, r *http.Request, request provider.Request) {
contentType := r.Header.Get("Content-Type")

fibr.SetRouteTag(r.Context(), "POST")

if contentType == "application/x-www-form-urlencoded" {
s.handleFormURLEncoded(w, r, request)
return
Expand All @@ -74,15 +72,15 @@ func (s Service) handleFormURLEncoded(w http.ResponseWriter, r *http.Request, re

switch r.FormValue("type") {
case "share":
fibr.SetRouteTag(r.Context(), "POST share")
fibr.SetRouteTag(r.Context(), "/share")
s.handlePostShare(w, r, request, method)

case "webhook":
fibr.SetRouteTag(r.Context(), "POST webhook")
fibr.SetRouteTag(r.Context(), "/webhook")
s.handlePostWebhook(w, r, request, method)

case "description":
fibr.SetRouteTag(r.Context(), "POST description")
fibr.SetRouteTag(r.Context(), "/description")
s.handlePostDescription(w, r, request)

default:
Expand Down Expand Up @@ -116,14 +114,14 @@ func (s Service) handleMultipart(w http.ResponseWriter, r *http.Request, request

chunkNumber = fmt.Sprintf("%010d", chunkNumberValue)

fibr.SetRouteTag(r.Context(), "POST chunk")
fibr.SetRouteTag(r.Context(), "/chunk")
s.uploadChunk(w, r, request, values["filename"], chunkNumber, file)
} else {
fibr.SetRouteTag(r.Context(), "POST merge")
fibr.SetRouteTag(r.Context(), "/merge")
s.mergeChunk(w, r, request, values)
}
} else {
fibr.SetRouteTag(r.Context(), "POST upload")
fibr.SetRouteTag(r.Context(), "/upload")
s.upload(w, r, request, values, file)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func parseRenameParams(r *http.Request, request provider.Request) (string, strin
}

func (s Service) Rename(w http.ResponseWriter, r *http.Request, request provider.Request) {
fibr.SetRouteTag(r.Context(), "PATCH rename")
fibr.SetRouteTag(r.Context(), "/rename")

if !request.CanEdit {
s.error(w, r, request, model.WrapForbidden(ErrNotAuthorized))
Expand Down

0 comments on commit 797ae3d

Please sign in to comment.