filebrowser/internal/file/dir.go
2016-06-26 16:52:15 +01:00

29 lines
621 B
Go

package file
import (
"net/http"
"os"
"path/filepath"
"strings"
"github.com/hacdias/caddy-filemanager/internal/config"
)
// NewDir makes a new directory
func NewDir(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
path := strings.Replace(r.URL.Path, c.BaseURL, c.PathScope, 1)
path = filepath.Clean(path)
err := os.MkdirAll(path, 0755)
if err != nil {
switch {
case os.IsPermission(err):
return http.StatusForbidden, err
case os.IsExist(err):
return http.StatusConflict, err
default:
return http.StatusInternalServerError, err
}
}
return http.StatusCreated, nil
}