Skip to content
Permalink
Browse files

Trim document contents on creation

Signed-off-by: Till Kottmann <me@deletescape.ch>
  • Loading branch information
deletescape committed Nov 25, 2019
1 parent 3a088bd commit 3c052d6c91cd5415e7760faeffaf9cad3ff0a950
@@ -186,7 +186,7 @@ private fun Application.initDb(
files.forEach { file ->
if (file.isFile) {
val slug = file.nameWithoutExtension
val content = file.readText()
val content = file.readText().trim()
db.transactional {
XdDocument.findOrNew(slug) {
version = -1
@@ -122,7 +122,7 @@ private suspend fun ApplicationCall.createDocument(
val doc = XdDocument.new {
this.slug = slug
owner = usr
stringContent = dto.content
stringContent = dto.content.trim()
type = if (isUrl) XdDocumentType.URL else XdDocumentType.PASTE
}

@@ -154,7 +154,7 @@ private suspend fun ApplicationCall.createDocument(
)
} else if (doc.userCanEdit(usr)) {
val isUrl = dto.content.isUrl()
doc.stringContent = dto.content
doc.stringContent = dto.content.trim()
doc.type = if (isUrl) XdDocumentType.URL else XdDocumentType.PASTE
val version = doc.version++
val id = doc.xdId
@@ -188,7 +188,7 @@ private suspend fun ApplicationCall.createDocument(
val doc = XdDocument.new {
slug = dto.slug
owner = usr
stringContent = dto.content
stringContent = dto.content.trim()
type = if (isUrl) XdDocumentType.URL else XdDocumentType.PASTE
}

@@ -48,7 +48,7 @@ class MongoMigration(

private fun migrateDocument(document: MongoDocument, slug: String) = xdStore.transactional {
XdDocument.findOrNew(slug) {
stringContent = document.content
stringContent = document.content.trim()
type = if (document.content.isUrl()) XdDocumentType.URL else XdDocumentType.PASTE
version = document.version
viewCount = document.viewCount

0 comments on commit 3c052d6

Please sign in to comment.
You can’t perform that action at this time.