aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2019-04-17 00:10:53 +0200
committerMarvin Borner2019-04-17 00:10:53 +0200
commitfe6af31f05f59ed1ef162bc16ffc99600df51ad7 (patch)
tree043847a6d66295fd6692b3d7a8053d4bf72269f1 /src
parentcdd6fa1981ebf8d96e4849167805c471451e5d6d (diff)
Fixed viewing of PDFs and other binary files
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/App.kt8
-rw-r--r--src/main/kotlin/FileController.kt19
2 files changed, 16 insertions, 11 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index ac9127b..bb69db2 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -127,14 +127,6 @@ fun roleManager(handler: Handler, ctx: Context, permittedRoles: Set<Role>) {
}
}
-/*
-fun indexAllFiles(ctx: Context) {
- Files.list(Paths.get("$fileHome/${getVerifiedUserId(ctx)}").forEach {
- // TODO: Add file indexing function
- }
-}
-*/
-
/**
* Declares the roles in which a user can be in
*/
diff --git a/src/main/kotlin/FileController.kt b/src/main/kotlin/FileController.kt
index 08f0763..528df3a 100644
--- a/src/main/kotlin/FileController.kt
+++ b/src/main/kotlin/FileController.kt
@@ -57,7 +57,10 @@ class FileController {
"extension", File("$usersFileHome/${ctx.splats()[0]}").extension
)
)
- else -> ctx.result(FileInputStream(File("$usersFileHome/${ctx.splats()[0]}")))
+ else -> {
+ ctx.contentType(Files.probeContentType(Paths.get("$usersFileHome/${ctx.splats()[0]}")))
+ ctx.result(FileInputStream(File("$usersFileHome/${ctx.splats()[0]}")))
+ }
}
} catch (_: Exception) {
throw NotFoundResponse("Error: File or directory does not exist.")
@@ -114,6 +117,14 @@ class FileController {
}
}
+ /*
+ fun indexAll(ctx: Context) {
+ Files.list(Paths.get("$fileHome/${getVerifiedUserId(ctx)}").forEach {
+ // TODO: Add file indexing function
+ }
+ }
+ */
+
/**
* Deletes the requested file
*/
@@ -156,10 +167,12 @@ class FileController {
"extension", File(sharedFileLocation).extension
)
)
- } else ctx.result(FileInputStream(File(sharedFileLocation))) // TODO: other file types
+ } else {
+ ctx.contentType(Files.probeContentType(Paths.get(sharedFileLocation)))
+ ctx.result(FileInputStream(File(sharedFileLocation)))
+ }
} else {
log.info("Unknown file!")
}
}
-
}