updates; new file/folder working

This commit is contained in:
Henrique Dias 2016-06-28 21:28:39 +01:00
parent 2882caeedd
commit 2f81648576
5 changed files with 475 additions and 402 deletions

File diff suppressed because it is too large Load Diff

View File

@ -261,7 +261,7 @@ var handleFiles = function(files) {
request.onreadystatechange = function() { request.onreadystatechange = function() {
if (request.readyState == 4) { if (request.readyState == 4) {
if (request.status == 200) { if (request.status == 200) {
location.reload(); history.go(0);
} }
button.changeToDone((request.status != 200), html); button.changeToDone((request.status != 200), html);
@ -406,6 +406,39 @@ document.addEventListener('listing', event => {
// Enables rename button // Enables rename button
document.getElementById("rename").addEventListener("click", renameEvent); document.getElementById("rename").addEventListener("click", renameEvent);
document.getElementById('new').addEventListener('click', event => {
let newdir = document.getElementById('newdir');
newdir.classList.toggle('enabled');
newdir.focus();
});
document.getElementById('newdir').addEventListener('keydown', event => {
if (event.keyCode == 27) {
document.getElementById('newdir').classList.toggle('enabled');
setTimeout(() => {
document.getElementById('newdir').value = '';
}, 200);
}
if (event.keyCode == 13) {
event.preventDefault();
let button = document.getElementById('new');
let html = button.changeToLoading();
let request = new XMLHttpRequest();
request.open("POST", window.location);
request.setRequestHeader('Filename', document.getElementById('newdir').value);
request.send();
request.onreadystatechange = function() {
if (request.readyState == 4) {
button.changeToDone((request.status != 200), html);
history.go(0);
}
}
}
});
// Drag and Drop // Drag and Drop
document.addEventListener("dragover", function(event) { document.addEventListener("dragover", function(event) {
event.preventDefault(); event.preventDefault();

View File

@ -54,7 +54,7 @@
{{ else }} {{ else }}
{{ template "actions" . }} {{ template "actions" . }}
{{ end }} {{ end }}
<div class="action" id="logout"> <div class="action" id="logout">
<i class="material-icons">exit_to_app</i> <i class="material-icons">exit_to_app</i>
</div> </div>
@ -81,14 +81,6 @@
{{ template "content" .Data }} {{ template "content" .Data }}
</main> </main>
{{ if .IsDir }}
<div class="floating">
<div class="action" id="newfolder">
<i class="material-icons">add</i>
</div>
</div>
{{ end }}
<footer> <footer>
Served with Served with
<a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a> <a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a>

View File

@ -31,4 +31,12 @@
</div> </div>
<input style="display:none" type="file" id="upload-input" onchange="handleFiles(this.files)" value="Upload" multiple> <input style="display:none" type="file" id="upload-input" onchange="handleFiles(this.files)" value="Upload" multiple>
<input id="newdir" type="text" placeholder="Name...">
<div class="floating">
<div class="action" id="new">
<i class="material-icons">add</i>
</div>
</div>
{{ end }} {{ end }}

View File

@ -9,6 +9,7 @@ package filemanager
import ( import (
"io" "io"
"io/ioutil"
"log" "log"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -163,9 +164,24 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// newDirectory makes a new directory // newDirectory makes a new directory
func newDirectory(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { func newDirectory(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
path := strings.Replace(r.URL.Path, c.BaseURL, c.PathScope, 1) 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) path = filepath.Clean(path)
err := os.MkdirAll(path, 0755) extension := filepath.Ext(path)
var err error
if extension == "" {
err = os.MkdirAll(path, 0755)
} else {
err = ioutil.WriteFile(path, []byte(""), 0755)
}
if err != nil { if err != nil {
switch { switch {
case os.IsPermission(err): case os.IsPermission(err):