From c056361f5449ae6a4d94b71b0efd2f67493502f7 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 22 Apr 2019 22:07:34 +0200 Subject: Added viewing of files in shared directories Co-authored-by: LarsVomMars --- src/main/kotlin/FileController.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/FileController.kt') diff --git a/src/main/kotlin/FileController.kt b/src/main/kotlin/FileController.kt index 40ca1c9..1d5bada 100644 --- a/src/main/kotlin/FileController.kt +++ b/src/main/kotlin/FileController.kt @@ -48,7 +48,8 @@ class FileController { ctx.render( "files.rocker.html", TemplateUtil.model( "files", files, - "path", (if (firstParam.firstOrNull() == '/') firstParam.drop(1) else firstParam) + "path", (if (firstParam.firstOrNull() == '/') firstParam.drop(1) else firstParam), + "isShared", false ) ) } @@ -194,12 +195,11 @@ class FileController { ) ) } else { - val fileProbe = Files.probeContentType(Paths.get(sharedFileLocation)) // is null if file type is not recognized - ctx.contentType(fileProbe) + // TODO: Fix name of downloaded file ("shared") + ctx.contentType(Files.probeContentType(Paths.get(sharedFileLocation))) ctx.result(FileInputStream(File(sharedFileLocation))) } } else { - // TODO: Add support for accessing files in shared directories // TODO: Combine the two file-crawling-render functions val files = ArrayList>() Files.list(Paths.get(sharedFileLocation)).forEach { @@ -226,7 +226,8 @@ class FileController { "files.rocker.html", TemplateUtil.model( "files", files, "path", - (if (sharedFileData.fileLocation.firstOrNull() == '/') sharedFileData.fileLocation.drop(1) else sharedFileData.fileLocation) + (if (sharedFileData.fileLocation.firstOrNull() == '/') sharedFileData.fileLocation.drop(1) else sharedFileData.fileLocation), + "isShared", true ) ) } @@ -234,4 +235,11 @@ class FileController { log.info("Unknown file!") } } + + 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) + } } -- cgit v1.2.3