update travis and some stuff

pull/144/head
Henrique Dias 2017-01-03 17:06:04 +00:00
parent b39126fdd9
commit 7b81b0828f
5 changed files with 314 additions and 310 deletions

View File

@ -5,20 +5,14 @@ root = true
# Unix-style newlines with a newline ending every file # Unix-style newlines with a newline ending every file
[*] [*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,go}]
charset = utf-8
# 4 space indentation # 4 space indentation
[*.go] [*.go]
indent_style = tab indent_style = tab
indent_size = 2 indent_size = 4
# Indentation override for all JS under lib directory
[*.js]
indent_style = space
indent_size = 2

View File

@ -1,13 +1,18 @@
language: go language: go
go: go:
- tip - tip
sudo: false
install: install:
- go generate - go generate
- go get -u -v $(go list -f '{{join .Imports "\n"}}' ./... | sort | uniq | grep -v caddy-filemanager) - go get -u -v $(go list -f '{{join .Imports "\n"}}' ./... | sort | uniq | grep -v caddy-filemanager)
- go get -u -v github.com/mholt/caddy/caddyhttp - go get -u -v github.com/mholt/caddy/caddyhttp
- go get -u -v github.com/caddyserver/caddydev - go get -u -v github.com/caddyserver/caddydev
- go install github.com/caddyserver/caddydev - go install github.com/caddyserver/caddydev
- go get github.com/gordonklaus/ineffassign
script: script:
- sed -i 's/\_ \"github.com\/mholt\/caddy\/caddyhttp\"/\_ \"github.com\/mholt\/caddy\/caddyhttp\"\n\_ \"github.com\/hacdias\/caddy-filemanager\"/g' $GOPATH/src/github.com/mholt/caddy/caddy/caddymain/run.go - sed -i 's/\_ \"github.com\/mholt\/caddy\/caddyhttp\"/\_ \"github.com\/mholt\/caddy\/caddyhttp\"\n\_ \"github.com\/hacdias\/caddy-filemanager\"/g' $GOPATH/src/github.com/mholt/caddy/caddy/caddymain/run.go
- go build github.com/mholt/caddy/caddy - go build github.com/mholt/caddy/caddy
- diff <(echo -n) <(gofmt -s -d .)
- ineffassign .

View File

@ -15,7 +15,7 @@
"end_with_newline": false, // End output with newline "end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character "indent_char": " ", // Indentation character
"indent_level": 0, // Initial indentation level "indent_level": 0, // Initial indentation level
"indent_size": 4, // Indentation size "indent_size": 2, // Indentation size
"indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char` "indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char`
"jslint_happy": false, // If true, then jslint-stricter mode is enforced "jslint_happy": false, // If true, then jslint-stricter mode is enforced
"keep_array_indentation": false, // Preserve array indentation "keep_array_indentation": false, // Preserve array indentation

View File

@ -121,7 +121,6 @@ function getCSSRule(rules) {
* * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * */
// TODO: here, we should create an abstraction layer from the webdav. // TODO: here, we should create an abstraction layer from the webdav.
// We must create functions that do the requests to the webdav backend. // We must create functions that do the requests to the webdav backend.
// this functions will contain a 'callback' to be used withing the other function.
webdav.move = function(oldLink, newLink) { webdav.move = function(oldLink, newLink) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -140,6 +139,22 @@ webdav.move = function(oldLink, newLink) {
}); });
} }
webdav.put = function(link, body) {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest();
request.open('PUT', toWebDavURL(link), true);
request.onload = () => {
if (request.status == 201) {
resolve(request.response);
} else {
reject(request.statusText);
}
}
request.onerror = () => reject(request.statusText);
request.send(body);
});
}
/* * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * *
* * * *
@ -614,4 +629,4 @@ document.addEventListener("DOMContentLoaded", function(event) {
setupSearch(); setupSearch();
return false; return false;
}); });

View File

@ -1,430 +1,420 @@
'use strict'; 'use strict';
var listing = { var listing = {
selectMultiple: false selectMultiple: false
}; };
listing.reload = function(callback) { listing.reload = function(callback) {
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
request.open('GET', window.location); request.open('GET', window.location);
request.setRequestHeader('Minimal', 'true'); request.setRequestHeader('Minimal', 'true');
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 == 200) {
document.querySelector('body main').innerHTML = request.responseText; document.querySelector('body main').innerHTML = request.responseText;
listing.addDoubleTapEvent(); listing.addDoubleTapEvent();
if (typeof callback == 'function') { if (typeof callback == 'function') {
callback(); callback();
}
}
} }
}
} }
}
} }
listing.itemDragStart = function(event) { listing.itemDragStart = function(event) {
let el = event.target; let el = event.target;
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
if (!el.classList.contains('item')) { if (!el.classList.contains('item')) {
el = el.parentElement; el = el.parentElement;
}
} }
}
event.dataTransfer.setData("id", el.id); event.dataTransfer.setData("id", el.id);
event.dataTransfer.setData("name", el.querySelector('.name').innerHTML); event.dataTransfer.setData("name", el.querySelector('.name').innerHTML);
} }
listing.itemDragOver = function(event) { listing.itemDragOver = function(event) {
event.preventDefault(); event.preventDefault();
let el = event.target; let el = event.target;
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
if (!el.classList.contains('item')) { if (!el.classList.contains('item')) {
el = el.parentElement; el = el.parentElement;
}
} }
}
el.style.opacity = 1; el.style.opacity = 1;
} }
listing.itemDrop = function(e) { listing.itemDrop = function(e) {
e.preventDefault(); e.preventDefault();
let el = e.target, let el = e.target,
id = e.dataTransfer.getData("id"), id = e.dataTransfer.getData("id"),
name = e.dataTransfer.getData("name"); name = e.dataTransfer.getData("name");
if (id == "" || name == "") return; if (id == "" || name == "") return;
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
if (!el.classList.contains('item')) { if (!el.classList.contains('item')) {
el = el.parentElement; el = el.parentElement;
}
} }
}
if (el.id === id) return; if (el.id === id) return;
let oldLink = toWebDavURL(document.getElementById(id).dataset.url), let oldLink = document.getElementById(id).dataset.url,
newLink = toWebDavURL(el.dataset.url + name), newLink = el.dataset.url + name;
request = new XMLHttpRequest();
request.open('MOVE', oldLink); webdav.move(oldLink, newLink)
request.setRequestHeader('Destination', newLink); .then(() => listing.reload())
request.send(); .catch(e => console.log(e));
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 201 || request.status == 204) {
listing.reload();
}
}
}
} }
listing.documentDrop = function(event) { listing.documentDrop = function(event) {
event.preventDefault(); event.preventDefault();
let dt = event.dataTransfer, let dt = event.dataTransfer,
files = dt.files, files = dt.files,
el = event.target, el = event.target,
items = document.getElementsByClassName('item'); items = document.getElementsByClassName('item');
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
if (el != null && !el.classList.contains('item')) { if (el != null && !el.classList.contains('item')) {
el = el.parentElement; el = el.parentElement;
} }
}
if (files.length > 0) {
if (el != null && el.classList.contains('item') && el.dataset.dir == "true") {
listing.handleFiles(files, el.querySelector('.name').innerHTML + "/");
return;
} }
if (files.length > 0) { listing.handleFiles(files, "");
if (el != null && el.classList.contains('item') && el.dataset.dir == "true") { } else {
listing.handleFiles(files, el.querySelector('.name').innerHTML + "/"); Array.from(items).forEach(file => {
return; file.style.opacity = 1;
} });
}
listing.handleFiles(files, "");
} else {
Array.from(items).forEach(file => {
file.style.opacity = 1;
});
}
} }
listing.rename = function(event) { listing.rename = function(event) {
if (!selectedItems.length || selectedItems.length > 1) { if (!selectedItems.length || selectedItems.length > 1) {
return false; return false;
} }
let item = document.getElementById(selectedItems[0]); let item = document.getElementById(selectedItems[0]);
if (item.classList.contains('disabled')) { if (item.classList.contains('disabled')) {
return false; return false;
} }
let link = item.dataset.url, let link = item.dataset.url,
name = item.querySelector('.name').innerHTML; field = item.querySelector('.name'),
name = field.innerHTML;
let submit = (event) => { let submit = (event) => {
event.preventDefault(); event.preventDefault();
let newName = event.currentTarget.querySelector('input').value, let newName = event.currentTarget.querySelector('input').value,
newLink = removeLastDirectoryPartOf(link) + "/" + newName, newLink = removeLastDirectoryPartOf(link) + "/" + newName,
html = buttons.rename.querySelector('i').changeToLoading(); html = buttons.rename.querySelector('i').changeToLoading();
closePrompt(event); closePrompt(event);
webdav.move(link, newLink) webdav.move(link, newLink).then(() => {
.then(data => { listing.reload(() => {
listing.reload(() => { newName = btoa(newName);
newName = btoa(newName); selectedItems = [newName];
selectedItems = [newName]; document.getElementById(newName).setAttribute("aria-selected", true);
document.getElementById(newName).setAttribute("aria-selected", true); listing.handleSelectionChange();
listing.handleSelectionChange(); });
});
buttons.rename.querySelector('i').changeToDone(false, html); buttons.rename.querySelector('i').changeToDone(false, html);
}) }).catch(error => {
.catch(error => { field.innerHTML = name;
item.querySelector('.name').innerHTML = name; buttons.rename.querySelector('i').changeToDone(true, html);
buttons.rename.querySelector('i').changeToDone(true, html);
});
return false;
}
let clone = document.importNode(templates.question.content, true); console.log(error);
clone.querySelector('h3').innerHTML = 'Rename'; });
clone.querySelector('input').value = name;
clone.querySelector('.ok').innerHTML = 'Rename';
clone.querySelector('form').addEventListener('submit', submit);
document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active');
return false; return false;
}
let clone = document.importNode(templates.question.content, true);
clone.querySelector('h3').innerHTML = 'Rename';
clone.querySelector('input').value = name;
clone.querySelector('.ok').innerHTML = 'Rename';
clone.querySelector('form').addEventListener('submit', submit);
document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active');
return false;
} }
listing.handleFiles = function(files, base) { listing.handleFiles = function(files, base) {
let button = document.getElementById("upload"), let html = buttons.upload.querySelector('i').changeToLoading(),
html = button.querySelector('i').changeToLoading(); promises = [];
for (let i = 0; i < files.length; i++) { for (let file of files) {
let request = new XMLHttpRequest(); promises.push(webdav.put(window.location.pathname + base + file.name, file));
request.open('PUT', toWebDavURL(window.location.pathname + base + files[i].name)); }
request.send(files[i]); Promise.all(promises)
request.onreadystatechange = function() { .then(() => {
if (request.readyState == 4) { listing.reload();
if (request.status == 201) { buttons.upload.querySelector('i').changeToDone(false, html);
listing.reload(); })
} .catch(e => {
console.log(e);
buttons.upload.querySelector('i').changeToDone(true, html);
})
button.querySelector('i').changeToDone((request.status != 201), html); return false;
}
}
}
return false;
} }
listing.unselectAll = function() { listing.unselectAll = function() {
let items = document.getElementsByClassName('item'); let items = document.getElementsByClassName('item');
Array.from(items).forEach(link => { Array.from(items).forEach(link => {
link.setAttribute("aria-selected", false); link.setAttribute("aria-selected", false);
}); });
selectedItems = []; selectedItems = [];
listing.handleSelectionChange(); listing.handleSelectionChange();
return false; return false;
} }
listing.handleSelectionChange = function(event) { listing.handleSelectionChange = function(event) {
listing.redefineDownloadURLs(); listing.redefineDownloadURLs();
let selectedNumber = selectedItems.length, let selectedNumber = selectedItems.length,
fileAction = document.getElementById("file-only"); fileAction = document.getElementById("file-only");
if (selectedNumber) { if (selectedNumber) {
fileAction.classList.remove("disabled"); fileAction.classList.remove("disabled");
if (selectedNumber > 1) { if (selectedNumber > 1) {
buttons.open.classList.add("disabled"); buttons.open.classList.add("disabled");
buttons.rename.classList.add("disabled"); buttons.rename.classList.add("disabled");
} }
if (selectedNumber == 1) { if (selectedNumber == 1) {
if (document.getElementById(selectedItems[0]).dataset.dir == "true") { if (document.getElementById(selectedItems[0]).dataset.dir == "true") {
buttons.open.classList.add("disabled"); buttons.open.classList.add("disabled");
} else { } else {
buttons.open.classList.remove("disabled"); buttons.open.classList.remove("disabled");
} }
buttons.rename.classList.remove("disabled"); buttons.rename.classList.remove("disabled");
}
return false;
} }
fileAction.classList.add("disabled");
return false; return false;
}
fileAction.classList.add("disabled");
return false;
} }
listing.redefineDownloadURLs = function() { listing.redefineDownloadURLs = function() {
let files = ""; let files = "";
for (let i = 0; i < selectedItems.length; i++) { for (let i = 0; i < selectedItems.length; i++) {
let url = document.getElementById(selectedItems[i]).dataset.url; let url = document.getElementById(selectedItems[i]).dataset.url;
files += url.replace(window.location.pathname, "") + ","; files += url.replace(window.location.pathname, "") + ",";
} }
files = files.substring(0, files.length - 1); files = files.substring(0, files.length - 1);
files = encodeURIComponent(files); files = encodeURIComponent(files);
let links = document.querySelectorAll("#download ul a"); let links = document.querySelectorAll("#download ul a");
Array.from(links).forEach(link => { Array.from(links).forEach(link => {
link.href = "?download=" + link.dataset.format + "&files=" + files; link.href = "?download=" + link.dataset.format + "&files=" + files;
}); });
} }
listing.openItem = function(event) { listing.openItem = function(event) {
window.location = event.currentTarget.dataset.url; window.location = event.currentTarget.dataset.url;
} }
listing.selectItem = function(event) { listing.selectItem = function(event) {
let el = event.currentTarget; let el = event.currentTarget;
if (selectedItems.length != 0) event.preventDefault(); if (selectedItems.length != 0) event.preventDefault();
if (selectedItems.indexOf(el.id) == -1) { if (selectedItems.indexOf(el.id) == -1) {
if (!event.ctrlKey && !listing.selectMultiple) listing.unselectAll(); if (!event.ctrlKey && !listing.selectMultiple) listing.unselectAll();
el.setAttribute("aria-selected", true); el.setAttribute("aria-selected", true);
selectedItems.push(el.id); selectedItems.push(el.id);
} else { } else {
el.setAttribute("aria-selected", false); el.setAttribute("aria-selected", false);
selectedItems.removeElement(el.id); selectedItems.removeElement(el.id);
} }
listing.handleSelectionChange(); listing.handleSelectionChange();
return false; return false;
} }
listing.newFileButton = function(event) { listing.newFileButton = function(event) {
event.preventDefault(); event.preventDefault();
let clone = document.importNode(templates.question.content, true); let clone = document.importNode(templates.question.content, true);
clone.querySelector('h3').innerHTML = 'New file'; clone.querySelector('h3').innerHTML = 'New file';
clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir.'; clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir.';
clone.querySelector('.ok').innerHTML = 'Create'; clone.querySelector('.ok').innerHTML = 'Create';
clone.querySelector('form').addEventListener('submit', listing.newFilePrompt); clone.querySelector('form').addEventListener('submit', listing.newFilePrompt);
document.querySelector('body').appendChild(clone) document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active'); document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active'); document.querySelector('.prompt').classList.add('active');
} }
listing.newFilePrompt = function(event) { listing.newFilePrompt = function(event) {
event.preventDefault(); event.preventDefault();
let button = document.getElementById('new'), let button = document.getElementById('new'),
html = button.querySelector('i').changeToLoading(), html = button.querySelector('i').changeToLoading(),
request = new XMLHttpRequest(), request = new XMLHttpRequest(),
name = event.currentTarget.querySelector('input').value; name = event.currentTarget.querySelector('input').value;
request.open((name.endsWith("/") ? "MKCOL" : "PUT"), toWebDavURL(window.location.pathname + name)); request.open((name.endsWith("/") ? "MKCOL" : "PUT"), toWebDavURL(window.location.pathname + name));
request.send(); request.send();
request.onreadystatechange = function() { request.onreadystatechange = function() {
if (request.readyState == 4) { if (request.readyState == 4) {
button.querySelector('i').changeToDone((request.status != 201), html); button.querySelector('i').changeToDone((request.status != 201), html);
listing.reload(); listing.reload();
}
} }
}
closePrompt(event); closePrompt(event);
return false; return false;
} }
listing.updateColumns = function(event) { listing.updateColumns = function(event) {
let columns = Math.floor(document.getElementById('listing').offsetWidth / 300), let columns = Math.floor(document.getElementById('listing').offsetWidth / 300),
items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']); items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']);
items.style.width = `calc(${100/columns}% - 1em)`; items.style.width = `calc(${100/columns}% - 1em)`;
} }
listing.addDoubleTapEvent = function() { listing.addDoubleTapEvent = function() {
let items = document.getElementsByClassName('item'), let items = document.getElementsByClassName('item'),
touches = { touches = {
id: '', id: '',
count: 0 count: 0
}; };
Array.from(items).forEach(file => { Array.from(items).forEach(file => {
file.addEventListener('touchstart', event => { file.addEventListener('touchstart', event => {
console.log("hey") if (touches.id != file.id) {
if (touches.id != file.id) { touches.id = file.id;
touches.id = file.id; touches.count = 1;
touches.count = 1;
setTimeout(() => { setTimeout(() => {
touches.count = 0; touches.count = 0;
}, 500) }, 500)
return; return;
} }
touches.count++; touches.count++;
if (touches.count > 1) { if (touches.count > 1) {
window.location = file.dataset.url; window.location = file.dataset.url;
} }
});
}); });
});
} }
// Keydown events // Keydown events
window.addEventListener('keydown', (event) => { window.addEventListener('keydown', (event) => {
if (event.keyCode == 27) { if (event.keyCode == 27) {
listing.unselectAll(); listing.unselectAll();
if (document.querySelectorAll('.prompt').length) { if (document.querySelectorAll('.prompt').length) {
closePrompt(event); closePrompt(event);
}
} }
}
if (event.keyCode == 113) { if (event.keyCode == 113) {
listing.rename(); listing.rename();
} }
if (event.ctrlKey || event.metaKey) { if (event.ctrlKey || event.metaKey) {
console.log("hey") console.log("hey")
switch (String.fromCharCode(event.which).toLowerCase()) { switch (String.fromCharCode(event.which).toLowerCase()) {
case 's': case 's':
event.preventDefault(); event.preventDefault();
window.location = "?download=true" window.location = "?download=true"
}
} }
}
}); });
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
listing.updateColumns(); listing.updateColumns();
}); });
document.addEventListener('DOMContentLoaded', event => { document.addEventListener('DOMContentLoaded', event => {
listing.updateColumns(); listing.updateColumns();
listing.addDoubleTapEvent(); listing.addDoubleTapEvent();
buttons.rename = document.getElementById("rename"); buttons.rename = document.getElementById("rename");
buttons.upload = document.getElementById("upload"); buttons.upload = document.getElementById("upload");
buttons.new = document.getElementById('new'); buttons.new = document.getElementById('new');
buttons.download = document.getElementById('download'); buttons.download = document.getElementById('download');
document.getElementById('multiple-selection-activate').addEventListener('click', event => { document.getElementById('multiple-selection-activate').addEventListener('click', event => {
listing.selectMultiple = true; listing.selectMultiple = true;
clickOverlay.click(); clickOverlay.click();
document.getElementById('multiple-selection').classList.add('active'); document.getElementById('multiple-selection').classList.add('active');
document.querySelector('body').style.paddingBottom = "4em"; document.querySelector('body').style.paddingBottom = "4em";
}) })
document.getElementById('multiple-selection-cancel').addEventListener('click', event => { document.getElementById('multiple-selection-cancel').addEventListener('click', event => {
listing.selectMultiple = false; listing.selectMultiple = false;
document.querySelector('body').style.paddingBottom = "0"; document.querySelector('body').style.paddingBottom = "0";
document.getElementById('multiple-selection').classList.remove('active'); document.getElementById('multiple-selection').classList.remove('active');
}) })
if (user.AllowEdit) { if (user.AllowEdit) {
buttons.rename.addEventListener("click", listing.rename); buttons.rename.addEventListener("click", listing.rename);
} }
let items = document.getElementsByClassName('item'); let items = document.getElementsByClassName('item');
if (user.AllowNew) { if (user.AllowNew) {
buttons.upload.addEventListener("click", (event) => { buttons.upload.addEventListener("click", (event) => {
document.getElementById("upload-input").click(); document.getElementById("upload-input").click();
}); });
buttons.new.addEventListener('click', listing.newFileButton); buttons.new.addEventListener('click', listing.newFileButton);
// Drag and Drop // Drag and Drop
document.addEventListener("dragover", function(event) { document.addEventListener("dragover", function(event) {
event.preventDefault(); event.preventDefault();
}, false); }, false);
document.addEventListener("dragenter", (event) => { document.addEventListener("dragenter", (event) => {
Array.from(items).forEach(file => { Array.from(items).forEach(file => {
file.style.opacity = 0.5; file.style.opacity = 0.5;
}); });
}, false); }, false);
document.addEventListener("dragend", (event) => { document.addEventListener("dragend", (event) => {
Array.from(items).forEach(file => { Array.from(items).forEach(file => {
file.style.opacity = 1; file.style.opacity = 1;
}); });
}, false); }, false);
document.addEventListener("drop", listing.documentDrop, false); document.addEventListener("drop", listing.documentDrop, false);
} }
}); });