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)
| 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 |
| 103 | func 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 | |
| 116 | var publicShareHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { |
| 117 | file := d.raw.(*files.FileInfo) |