mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
Add isHashed()
This commit is contained in:
parent
cc25dffd15
commit
75c1eae7f2
1 changed files with 9 additions and 5 deletions
14
handlers.go
14
handlers.go
|
@ -17,6 +17,10 @@ type Context struct {
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHashed(dir string) bool {
|
||||||
|
return dir == "data"
|
||||||
|
}
|
||||||
|
|
||||||
// AuthHandler wraps h with a http.HandlerFunc that performs basic authentication against the user/passwords pairs
|
// AuthHandler wraps h with a http.HandlerFunc that performs basic authentication against the user/passwords pairs
|
||||||
// stored in f and returns the http.HandlerFunc.
|
// stored in f and returns the http.HandlerFunc.
|
||||||
func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
|
func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
|
||||||
|
@ -91,7 +95,7 @@ func ListBlobs(c *Context) http.HandlerFunc {
|
||||||
|
|
||||||
var names []string
|
var names []string
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
if dir == "data" {
|
if isHashed(dir) {
|
||||||
subpath := filepath.Join(path, i.Name())
|
subpath := filepath.Join(path, i.Name())
|
||||||
subitems, err := ioutil.ReadDir(subpath)
|
subitems, err := ioutil.ReadDir(subpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,7 +127,7 @@ func CheckBlob(c *Context) http.HandlerFunc {
|
||||||
dir := vars[1]
|
dir := vars[1]
|
||||||
name := vars[2]
|
name := vars[2]
|
||||||
|
|
||||||
if dir == "data" {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
}
|
}
|
||||||
path := filepath.Join(c.path, dir, name)
|
path := filepath.Join(c.path, dir, name)
|
||||||
|
@ -145,7 +149,7 @@ func GetBlob(c *Context) http.HandlerFunc {
|
||||||
dir := vars[1]
|
dir := vars[1]
|
||||||
name := vars[2]
|
name := vars[2]
|
||||||
|
|
||||||
if dir == "data" {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
}
|
}
|
||||||
path := filepath.Join(c.path, dir, name)
|
path := filepath.Join(c.path, dir, name)
|
||||||
|
@ -194,7 +198,7 @@ func SaveBlob(c *Context) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dir == "data" {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
}
|
}
|
||||||
path := filepath.Join(c.path, dir, name)
|
path := filepath.Join(c.path, dir, name)
|
||||||
|
@ -217,7 +221,7 @@ func DeleteBlob(c *Context) http.HandlerFunc {
|
||||||
dir := vars[1]
|
dir := vars[1]
|
||||||
name := vars[2]
|
name := vars[2]
|
||||||
|
|
||||||
if dir == "data" {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
}
|
}
|
||||||
path := filepath.Join(c.path, dir, name)
|
path := filepath.Join(c.path, dir, name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue