diff options
author | Marvin Borner | 2019-05-01 22:32:25 +0200 |
---|---|---|
committer | Marvin Borner | 2019-05-01 22:32:25 +0200 |
commit | 22797dde022a398b34a91ba24e2bdd89be3f36f8 (patch) | |
tree | 7bc99091aa76ca0ee6a06efd73c495f38fc7710f /src | |
parent | 82afdcd8609342bd7080460e152b6a0e3db5aaff (diff) |
Cleaned up sharing of files
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/FileController.kt | 13 | ||||
-rw-r--r-- | src/main/resources/js/files.js | 31 | ||||
-rw-r--r-- | src/main/resources/views/files.rocker.html | 4 |
3 files changed, 29 insertions, 19 deletions
diff --git a/src/main/kotlin/FileController.kt b/src/main/kotlin/FileController.kt index 9ba520c..9c2ee78 100644 --- a/src/main/kotlin/FileController.kt +++ b/src/main/kotlin/FileController.kt @@ -152,11 +152,10 @@ class FileController { } /** - * Renders the shared file + * Renders a shared file */ fun renderShared(ctx: Context) { - val accessId = ctx.queryParam("id").toString() - val sharedFileData = databaseController.getSharedFile(accessId) + val sharedFileData = databaseController.getSharedFile(ctx.queryParam("id").toString()) val fileLocation = sharedFileData.fileLocation if (sharedFileData.userId > 0 && fileLocation.isNotEmpty()) { val sharedFileLocation = "$fileHome/${sharedFileData.userId}/$fileLocation" @@ -171,7 +170,7 @@ class FileController { val files = ArrayList<Array<String>>() Files.list(Paths.get(sharedFileLocation)).forEach { val filename = it.toString() - .drop(sharedFileLocation.length - 1) + .drop(sharedFileLocation.length) val filePath = "$sharedFileLocation$filename" files.add(addToFileListing(filePath, filename)) } @@ -207,6 +206,9 @@ class FileController { ) } + /** + * Handles the rendering of human readable files + */ private fun handleHumanReadableFile(filePath: String, ctx: Context) { ctx.render( "fileview.rocker.html", model( @@ -226,7 +228,6 @@ class FileController { fun handleSharedFile(ctx: Context) { val filename = ctx.formParam("filename").toString() val accessId = ctx.formParam("accessId").toString() - val returnAccessId = databaseController.getAccessIdOfDirectory(filename, accessId) - ctx.result(returnAccessId) + ctx.result(databaseController.getAccessIdOfDirectory(filename, accessId)) } } diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js index 35a25b4..16b59cb 100644 --- a/src/main/resources/js/files.js +++ b/src/main/resources/js/files.js @@ -108,19 +108,24 @@ function setListeners() { const accessId = location.pathname === '/shared' ? location.search.split('=')[1] : undefined; document.querySelectorAll('[data-path], [data-href]').forEach(element => { element.addEventListener('click', () => { - const request = new XMLHttpRequest(); - const formData = new FormData(); - formData.append('accessId', accessId); - formData.append('filename', element.getAttribute('data-path') || element.getAttribute('data-href')); - request.open('POST', '/share', true); - request.onload = () => { - if (request.status === 200 && request.readyState === 4) { - if (request.responseText) - window.location = `/shared?id=${request.responseText}`; - else alert('File not found!'); - } - }; - request.send(formData) + const filename = '/' + (element.getAttribute('data-path') || element.getAttribute('data-href')); + if (filename !== '/../') { + const request = new XMLHttpRequest(); + const formData = new FormData(); + formData.append('accessId', accessId); + formData.append('filename', filename); + request.open('POST', '/share', true); + request.onload = () => { + if (request.status === 200 && request.readyState === 4) { + if (request.responseText) + window.location = `/shared?id=${request.responseText}`; + else alert('File not found!'); + } + }; + request.send(formData) + } else { + window.location = '../' + } }); }); } else { diff --git a/src/main/resources/views/files.rocker.html b/src/main/resources/views/files.rocker.html index 3fa4a3e..7b2e58b 100644 --- a/src/main/resources/views/files.rocker.html +++ b/src/main/resources/views/files.rocker.html @@ -18,6 +18,7 @@ <div class="drop" id="drop"> <h2 class="navigation"> <i class="icon ion-md-home"></i> + @if (!isShared) { @for (int i = 0; i < path.split("/").length - 1; i++) { <a href='@(new String(new char[path.split("/").length - i - 1]).replace("\0", "../"))'>@path.split("/")[i]</a> <i class='icon ion-ios-arrow-forward'></i> @@ -25,6 +26,9 @@ @if (path.split("/").length > 0) { <a href="">@(path.split("/")[path.split("/").length - 1])</a> } + } else { + <a href="">@(path.split("/")[path.split("/").length - 1])</a> + } </h2> <table id="table"> |