MCPcopy
hub / github.com/filebrowser/filebrowser / ifPathWithName

Function ifPathWithName

http/public.go:103–114  ·  view source on GitHub ↗

ref to https://github.com/filebrowser/filebrowser/pull/727 `/api/public/dl/MEEuZK-v/file-name.txt` for old browsers to save file with correct name

(r *http.Request)

Source from the content-addressed store, hash-verified

101// ref to https://github.com/filebrowser/filebrowser/pull/727
102// `/api/public/dl/MEEuZK-v/file-name.txt` for old browsers to save file with correct name
103func ifPathWithName(r *http.Request) (id, filePath string) {
104 pathElements := strings.Split(r.URL.Path, "/")
105 // prevent maliciously constructed parameters like `/api/public/dl/XZzCDnK2_not_exists_hash_name`
106 // len(pathElements) will be 1, and golang will panic `runtime error: index out of range`
107
108 switch len(pathElements) {
109 case 1:
110 return r.URL.Path, "/"
111 default:
112 return pathElements[0], path.Join("/", path.Join(pathElements[1:]...))
113 }
114}
115
116var publicShareHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
117 file := d.raw.(*files.FileInfo)

Callers 1

public.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected