diff options
Diffstat (limited to 'go/weed/weed.go')
| -rw-r--r-- | go/weed/weed.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/go/weed/weed.go b/go/weed/weed.go index 3d4beac88..26a009b4b 100644 --- a/go/weed/weed.go +++ b/go/weed/weed.go @@ -10,6 +10,7 @@ import ( "net" "net/http" "os" + "path/filepath" "strings" "sync" "text/template" @@ -244,3 +245,36 @@ func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request)) writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host}) } } + +func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly bool) { + switch strings.Count(path, "/") { + case 3: + parts := strings.Split(path, "/") + vid, fid, filename = parts[1], parts[2], parts[3] + ext = filepath.Ext(filename) + case 2: + parts := strings.Split(path, "/") + vid, fid = parts[1], parts[2] + dotIndex := strings.LastIndex(fid, ".") + if dotIndex > 0 { + ext = fid[dotIndex:] + fid = fid[0:dotIndex] + } + default: + sepIndex := strings.LastIndex(path, "/") + commaIndex := strings.LastIndex(path[sepIndex:], ",") + if commaIndex <= 0 { + vid, isVolumeIdOnly = path[sepIndex+1:], true + return + } + dotIndex := strings.LastIndex(path[sepIndex:], ".") + vid = path[sepIndex+1 : commaIndex] + fid = path[commaIndex+1:] + ext = "" + if dotIndex > 0 { + fid = path[commaIndex+1 : dotIndex] + ext = path[dotIndex:] + } + } + return +} |
