aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2019-04-15 19:59:37 +0200
committerMarvin Borner2019-04-15 19:59:37 +0200
commit1ee7bb209d0f3a66b00d34edc57661e31a846e49 (patch)
treec627c8ec0ddf63c6e0cbd5804d8711983e9f8120
parent85654224957a5d6c68e3060d706137cfd02d8a06 (diff)
Added file preview css reset via iframe
-rw-r--r--src/main/kotlin/App.kt8
-rw-r--r--src/main/kotlin/DatabaseController.kt2
-rw-r--r--src/main/resources/css/fileview.css7
-rw-r--r--src/main/resources/css/layout.css9
-rw-r--r--src/main/resources/js/fileview.js7
-rw-r--r--src/main/resources/views/fileview.rocker.html2
6 files changed, 23 insertions, 12 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index 608957d..6abaa4c 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -148,7 +148,7 @@ fun crawlFiles(ctx: Context) {
files.add(
arrayOf(
if (File(filePath).isDirectory) "$fileName/" else fileName,
- humanReadableBytes(File(filePath).length()),
+ humanReadableBytes(File(filePath).length()), // TODO: Fix file size for directories
SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(File(filePath).lastModified()).toString(),
if (File(filePath).isDirectory) "true" else isHumanReadable(filePath).toString()
)
@@ -186,7 +186,7 @@ fun crawlFiles(ctx: Context) {
fun upload(ctx: Context) {
ctx.uploadedFiles("file").forEach { (_, content, name, _) ->
val path = "${ctx.splats()[0]}/$name"
- FileUtil.streamToFile(content, path)
+ FileUtil.streamToFile(content, "$fileHome/${getVerifiedUserId(ctx)}/$path")
databaseController.addFile(path, getVerifiedUserId(ctx))
}
}
@@ -310,8 +310,8 @@ fun setup(ctx: Context) {
fun delete(ctx: Context) {
val userId = getVerifiedUserId(ctx)
if (userId > 0) {
- val path = "$fileHome/$userId/${ctx.splats()[0]}"
- File(path).delete()
+ val path = ctx.splats()[0]
+ File("$fileHome/$userId/$path").delete()
databaseController.deleteFile(path, userId)
}
}
diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt
index c26ba36..305c405 100644
--- a/src/main/kotlin/DatabaseController.kt
+++ b/src/main/kotlin/DatabaseController.kt
@@ -217,7 +217,7 @@ class DatabaseController(dbFileLocation: String = "main.db") {
it[userId] = usersId
it[accessId] = generateRandomString(64)
}
- } catch (_: org.jetbrains.exposed.exceptions.ExposedSQLException) {
+ } catch (err: org.jetbrains.exposed.exceptions.ExposedSQLException) {
log.warning("File already exists!")
}
}
diff --git a/src/main/resources/css/fileview.css b/src/main/resources/css/fileview.css
index 349980b..8341a80 100644
--- a/src/main/resources/css/fileview.css
+++ b/src/main/resources/css/fileview.css
@@ -2,6 +2,11 @@
display: none;
}
-.prettyprint {
+/* TODO: Fix duplicate scrollbars in previews */
+.prettyprint, .preview {
+ position: absolute;
+ min-height: 100%;
+ width: 100%;
border: none !important;
+ overflow: visible;
}
diff --git a/src/main/resources/css/layout.css b/src/main/resources/css/layout.css
index c11ee79..9c03575 100644
--- a/src/main/resources/css/layout.css
+++ b/src/main/resources/css/layout.css
@@ -1,7 +1,12 @@
html, body {
font-family: Arial, Helvetica, sans-serif;
+ color: #424242;
padding: 0;
margin: 0;
- min-width: 100%;
- min-height: 100%;
+ min-width: 100vw !important;
+ min-height: 100vh !important;
+}
+
+button {
+ color: #424242;
}
diff --git a/src/main/resources/js/fileview.js b/src/main/resources/js/fileview.js
index c34ce27..78ed951 100644
--- a/src/main/resources/js/fileview.js
+++ b/src/main/resources/js/fileview.js
@@ -12,9 +12,10 @@ const originalContent = content.innerText;
if (extension === "md" || extension === "html") {
if (extension === "md")
- preview.innerHTML = marked(originalContent);
- else if (extension === "html")
- preview.innerHTML = marked(originalContent);
+ preview.src = "data:text/html;charset=utf-8," + encodeURI(marked(originalContent));
+ else if (extension === "html") {
+ preview.src = "data:text/html;charset=utf-8," + encodeURI(originalContent);
+ }
preview.style.display = "block";
raw.style.display = "block";
diff --git a/src/main/resources/views/fileview.rocker.html b/src/main/resources/views/fileview.rocker.html
index bef1ad0..e92f037 100644
--- a/src/main/resources/views/fileview.rocker.html
+++ b/src/main/resources/views/fileview.rocker.html
@@ -18,5 +18,5 @@
<label for="dark">Dark mode</label><input id="dark" type="checkbox">
</span>
<pre class="prettyprint" id="content"><code class="lang-@extension">@content</code></pre>
-<div class="preview" id="preview"></div>
+<iframe class="preview" id="preview"></iframe>
}