moving to go webdav
parent
efde681a2e
commit
f49dd8e205
|
@ -86,6 +86,11 @@ Element.prototype.changeToDone = function(error, html) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var toWebDavURL = function(url) {
|
||||||
|
url = url.replace("/", "/webdav/")
|
||||||
|
return window.location.origin + url
|
||||||
|
}
|
||||||
|
|
||||||
// Handles the open file button event
|
// Handles the open file button event
|
||||||
var openEvent = function(event) {
|
var openEvent = function(event) {
|
||||||
if (this.classList.contains('disabled')) {
|
if (this.classList.contains('disabled')) {
|
||||||
|
@ -115,12 +120,12 @@ var deleteEvent = function(event) {
|
||||||
let html = document.getElementById("delete").changeToLoading();
|
let html = document.getElementById("delete").changeToLoading();
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
|
|
||||||
request.open('DELETE', link);
|
request.open('DELETE', toWebDavURL(link));
|
||||||
request.setRequestHeader('Token', token);
|
request.setRequestHeader('Token', token);
|
||||||
request.send();
|
request.send();
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState == 4) {
|
if (request.readyState == 4) {
|
||||||
if (request.status == 200) {
|
if (request.status == 204) {
|
||||||
if (single) {
|
if (single) {
|
||||||
window.location.pathname = RemoveLastDirectoryPartOf(window.location.pathname);
|
window.location.pathname = RemoveLastDirectoryPartOf(window.location.pathname);
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,7 +133,7 @@ var deleteEvent = function(event) {
|
||||||
selectedItems.removeElement(link);
|
selectedItems.removeElement(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('delete').changeToDone((request.status != 200), html);
|
document.getElementById('delete').changeToDone((request.status != 204), html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -233,19 +238,22 @@ var renameEvent = function(event) {
|
||||||
let keyDownEvent = (event) => {
|
let keyDownEvent = (event) => {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
let newName = span.innerHTML;
|
let newName = span.innerHTML;
|
||||||
|
let newLink = toWebDavURL(link).replace(name, newName)
|
||||||
let html = document.getElementById('rename').changeToLoading();
|
let html = document.getElementById('rename').changeToLoading();
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open('PATCH', link);
|
request.open('MOVE', toWebDavURL(link));
|
||||||
request.setRequestHeader('Rename-To', newName);
|
request.setRequestHeader('Destination', newLink);
|
||||||
request.setRequestHeader('Token', token);
|
request.setRequestHeader('Token', token);
|
||||||
request.send();
|
request.send();
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
|
// TODO: redirect if it's moved to another folder
|
||||||
|
|
||||||
if (request.readyState == 4) {
|
if (request.readyState == 4) {
|
||||||
if (request.status != 200) {
|
if (request.status != 201 && request.status != 204) {
|
||||||
span.innerHTML = name;
|
span.innerHTML = name;
|
||||||
} else {
|
} else {
|
||||||
let newLink = encodeURI(link.replace(name, newName));
|
let newLink = encodeURI(link.replace(name, newName));
|
||||||
console.log(newLink)
|
console.log(request.body)
|
||||||
reloadListing(() => {
|
reloadListing(() => {
|
||||||
let newLink = encodeURI(link.replace(name, newName));
|
let newLink = encodeURI(link.replace(name, newName));
|
||||||
selectedItems = [newLink];
|
selectedItems = [newLink];
|
||||||
|
@ -255,7 +263,7 @@ var renameEvent = function(event) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('rename').changeToDone((request.status != 200), html);
|
document.getElementById('rename').changeToDone((request.status != 201 && request.status != 204), html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,42 +106,6 @@ func (i Info) HumanModTime(format string) string {
|
||||||
return i.ModTime.Format(format)
|
return i.ModTime.Format(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete handles the delete requests
|
|
||||||
func (i *Info) Delete() (int, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// If it's a directory remove all the contents inside
|
|
||||||
if i.IsDir {
|
|
||||||
err = os.RemoveAll(i.Path)
|
|
||||||
} else {
|
|
||||||
err = os.Remove(i.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return errors.ToHTTPCode(err), err
|
|
||||||
}
|
|
||||||
|
|
||||||
return http.StatusOK, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename function is used tor rename a file or a directory
|
|
||||||
func (i *Info) Rename(w http.ResponseWriter, r *http.Request) (int, error) {
|
|
||||||
newname := r.Header.Get("Rename-To")
|
|
||||||
if newname == "" {
|
|
||||||
return http.StatusBadRequest, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
newpath := filepath.Clean(newname)
|
|
||||||
newpath = strings.Replace(i.Path, i.Name, newname, 1)
|
|
||||||
|
|
||||||
if err := os.Rename(i.Path, newpath); err != nil {
|
|
||||||
return errors.ToHTTPCode(err), err
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Path = newpath
|
|
||||||
return http.StatusOK, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeAsHTML is used to serve single file pages
|
// ServeAsHTML is used to serve single file pages
|
||||||
func (i *Info) ServeAsHTML(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.User) (int, error) {
|
func (i *Info) ServeAsHTML(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.User) (int, error) {
|
||||||
if i.IsDir {
|
if i.IsDir {
|
||||||
|
|
|
@ -58,8 +58,9 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.WebDav && strings.HasPrefix(r.URL.Path, c.WebDavURL) {
|
if c.WebDav && strings.HasPrefix(r.URL.Path, c.WebDavURL) {
|
||||||
url := strings.TrimPrefix(r.URL.Path, c.WebDavURL)
|
//url := strings.TrimPrefix(r.URL.Path, c.WebDavURL)
|
||||||
|
|
||||||
|
/*
|
||||||
if !user.Allowed(url) {
|
if !user.Allowed(url) {
|
||||||
return http.StatusForbidden, nil
|
return http.StatusForbidden, nil
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
if !user.AllowNew {
|
if !user.AllowNew {
|
||||||
return http.StatusForbidden, nil
|
return http.StatusForbidden, nil
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
c.WebDavHandler.ServeHTTP(w, r)
|
c.WebDavHandler.ServeHTTP(w, r)
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
@ -149,7 +150,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !user.AllowEdit {
|
if !user.AllowEdit {
|
||||||
return http.StatusUnauthorized, nil
|
return http.StatusForbidden, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a file.
|
// Update a file.
|
||||||
|
@ -180,20 +181,6 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
|
|
||||||
// Creates a new folder.
|
// Creates a new folder.
|
||||||
return newDirectory(w, r, c)
|
return newDirectory(w, r, c)
|
||||||
case http.MethodDelete:
|
|
||||||
if !user.AllowEdit {
|
|
||||||
return http.StatusUnauthorized, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete a file or a directory
|
|
||||||
return fi.Delete()
|
|
||||||
case http.MethodPatch:
|
|
||||||
if !user.AllowEdit {
|
|
||||||
return http.StatusUnauthorized, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename a file or directory
|
|
||||||
return fi.Rename(w, r)
|
|
||||||
default:
|
default:
|
||||||
return http.StatusNotImplemented, nil
|
return http.StatusNotImplemented, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue