new directory using webdav

pull/144/head
Henrique Dias 2016-10-18 15:55:30 +01:00
parent f49dd8e205
commit 10f7ae1d0d
2 changed files with 3 additions and 39 deletions

View File

@ -430,13 +430,12 @@ var newDirEvent = function(event) {
let button = document.getElementById('new');
let html = button.changeToLoading();
let request = new XMLHttpRequest();
request.open("POST", window.location);
request.open("MKCOL", toWebDavURL(window.location.pathname + document.getElementById('newdir').value + "/"));
request.setRequestHeader('Token', token);
request.setRequestHeader('Filename', document.getElementById('newdir').value);
request.send();
request.onreadystatechange = function() {
if (request.readyState == 4) {
button.changeToDone((request.status != 200), html);
button.changeToDone((request.status != 201), html);
reloadListing(() => {
addNewDirEvents();
});

View File

@ -10,7 +10,6 @@ package filemanager
import (
e "errors"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
@ -179,8 +178,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
return command(w, r, c, user)
}
// Creates a new folder.
return newDirectory(w, r, c)
fallthrough
default:
return http.StatusNotImplemented, nil
}
@ -234,39 +232,6 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
return http.StatusOK, nil
}
// newDirectory makes a new directory
func newDirectory(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
filename := r.Header.Get("Filename")
if filename == "" {
return http.StatusBadRequest, nil
}
path := strings.Replace(r.URL.Path, c.BaseURL, c.PathScope, 1) + filename
path = filepath.Clean(path)
extension := filepath.Ext(path)
var err error
if extension == "" {
err = os.MkdirAll(path, 0775)
} else {
err = ioutil.WriteFile(path, []byte(""), 0775)
}
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
}
// command handles the requests for VCS related commands: git, svn and mercurial
func command(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.User) (int, error) {
command := strings.Split(r.Header.Get("command"), " ")