import java.nio.ByteBuffer
import java.nio.file.FileAlreadyExistsException
import java.nio.file.Files
-import java.nio.file.LinkOption
-import java.nio.file.attribute.BasicFileAttributeView
import java.nio.file.attribute.BasicFileAttributes
import java.time.Instant
import kotlin.String
import kotlin.time.Duration.Companion.hours
+fun StoragePath.getContentType(): ContentType {
+ val extension = elements.last().substringAfter('.', "")
+ return if (extension.isEmpty()) ContentType.Text.Plain else ContentType.defaultForFileExtension(extension)
+}
+
suspend fun ApplicationCall.respondStoredFile(path: StoragePath) {
val content = FileStorage.instance.readFile(path) ?: return respond(HttpStatusCode.NotFound)
- val extension = path.elements.last().substringAfter('.', "")
- val type = if (extension.isEmpty()) ContentType.Text.Plain else ContentType.defaultForFileExtension(extension)
+ val type = path.getContentType()
attributes.put(StoragePathAttributeKey, path)
respondBytes(content, type)
import io.ktor.util.*
import kotlinx.html.*
import kotlinx.html.org.w3c.dom.events.Event
-import kotlinx.html.stream.appendHTML
+import kotlinx.html.stream.createHTML
import kotlinx.serialization.json.JsonPrimitive
import kotlin.text.toCharArray
context(T)
operator fun <T : Tag> (TagConsumer<*>.() -> Any?).unaryPlus() = with(HtmlLexerTagConsumer(consumer)) { this@unaryPlus() }
-fun (TagConsumer<*>.() -> Any?).toFragment() = StringBuilder()
- .appendHTML()
- .also { builder ->
- with(HtmlLexerTagConsumer(builder)) { this@toFragment() }
- }
- .finalize()
- .toString()
+fun (TagConsumer<*>.() -> Any?).toFragment() = createHTML().also { builder ->
+ with(HtmlLexerTagConsumer(builder)) { this@toFragment() }
+}.finalize()
class HtmlLexerTagConsumer private constructor(private val downstream: TagConsumer<*>) : TagConsumer<Unit> {
override fun onTagStart(tag: Tag) {