mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-10 11:08:52 -06:00
Apply ktlint to uhabits-server
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.sync
|
||||
|
||||
import com.fasterxml.jackson.databind.*
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
|
||||
data class SyncData(
|
||||
val version: Long,
|
||||
@@ -32,4 +32,4 @@ data class GetDataVersionResponse(val version: Long)
|
||||
|
||||
val defaultMapper = ObjectMapper()
|
||||
fun SyncData.toJson(): String = defaultMapper.writeValueAsString(this)
|
||||
fun GetDataVersionResponse.toJson(): String = defaultMapper.writeValueAsString(this)
|
||||
fun GetDataVersionResponse.toJson(): String = defaultMapper.writeValueAsString(this)
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.sync
|
||||
|
||||
open class SyncException: RuntimeException()
|
||||
open class SyncException : RuntimeException()
|
||||
|
||||
class KeyNotFoundException: SyncException()
|
||||
class KeyNotFoundException : SyncException()
|
||||
|
||||
class ServiceUnavailable: SyncException()
|
||||
class ServiceUnavailable : SyncException()
|
||||
|
||||
class EditConflictException: SyncException()
|
||||
class EditConflictException : SyncException()
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import io.prometheus.client.*
|
||||
import io.prometheus.client.exporter.common.*
|
||||
import io.prometheus.client.hotspot.*
|
||||
import java.io.*
|
||||
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.get
|
||||
import io.prometheus.client.CollectorRegistry
|
||||
import io.prometheus.client.exporter.common.TextFormat
|
||||
import io.prometheus.client.hotspot.DefaultExports
|
||||
import java.io.StringWriter
|
||||
|
||||
fun Routing.metrics(app: SyncApplication) {
|
||||
// Register JVM metrics
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.post
|
||||
import org.isoron.uhabits.sync.RegisterReponse
|
||||
import org.isoron.uhabits.sync.ServiceUnavailable
|
||||
|
||||
fun Routing.registration(app: SyncApplication) {
|
||||
post("/register") {
|
||||
|
||||
@@ -19,12 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.request.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.request.receive
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.routing.put
|
||||
import io.ktor.routing.route
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.GetDataVersionResponse
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
|
||||
fun Routing.storage(app: SyncApplication) {
|
||||
route("/db/{key}") {
|
||||
@@ -33,7 +39,7 @@ fun Routing.storage(app: SyncApplication) {
|
||||
try {
|
||||
val data = app.server.getData(key)
|
||||
call.respond(HttpStatusCode.OK, data)
|
||||
} catch(e: KeyNotFoundException) {
|
||||
} catch (e: KeyNotFoundException) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
@@ -54,9 +60,9 @@ fun Routing.storage(app: SyncApplication) {
|
||||
try {
|
||||
val version = app.server.getDataVersion(key)
|
||||
call.respond(HttpStatusCode.OK, GetDataVersionResponse(version))
|
||||
} catch(e: KeyNotFoundException) {
|
||||
} catch (e: KeyNotFoundException) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.features.*
|
||||
import io.ktor.jackson.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.repository.*
|
||||
import org.isoron.uhabits.sync.server.*
|
||||
import java.nio.file.*
|
||||
import io.ktor.application.Application
|
||||
import io.ktor.application.install
|
||||
import io.ktor.features.CallLogging
|
||||
import io.ktor.features.ContentNegotiation
|
||||
import io.ktor.features.DefaultHeaders
|
||||
import io.ktor.jackson.jackson
|
||||
import io.ktor.routing.routing
|
||||
import org.isoron.uhabits.sync.repository.FileRepository
|
||||
import org.isoron.uhabits.sync.server.AbstractSyncServer
|
||||
import org.isoron.uhabits.sync.server.RepositorySyncServer
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
fun Application.main() = SyncApplication().apply { main() }
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.sync.links
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.utils.*
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.utils.randomString
|
||||
|
||||
class LinkManager(
|
||||
private val timeoutInMillis: Long = 900_000,
|
||||
@@ -46,4 +46,4 @@ class LinkManager(
|
||||
}
|
||||
return link
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.sync.repository
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import java.io.*
|
||||
import java.nio.file.*
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import java.io.PrintWriter
|
||||
import java.nio.file.Path
|
||||
|
||||
class FileRepository(
|
||||
private val basepath: Path,
|
||||
@@ -70,4 +71,4 @@ class FileRepository(
|
||||
private fun String.toDataPath(): Path {
|
||||
return basepath.resolve("${this[0]}/${this[1]}/${this[2]}/${this[3]}/$this")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,3 @@ interface Repository {
|
||||
*/
|
||||
suspend fun contains(key: String): Boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
|
||||
package org.isoron.uhabits.sync.server
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.links.*
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.ServiceUnavailable
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.links.Link
|
||||
|
||||
interface AbstractSyncServer {
|
||||
/**
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
|
||||
package org.isoron.uhabits.sync.server
|
||||
|
||||
import io.prometheus.client.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.links.*
|
||||
import org.isoron.uhabits.sync.repository.*
|
||||
import org.isoron.uhabits.sync.utils.*
|
||||
import io.prometheus.client.Counter
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.links.Link
|
||||
import org.isoron.uhabits.sync.links.LinkManager
|
||||
import org.isoron.uhabits.sync.repository.Repository
|
||||
import org.isoron.uhabits.sync.utils.randomString
|
||||
|
||||
/**
|
||||
* An AbstractSyncServer that stores all data in a [Repository].
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.sync.utils
|
||||
|
||||
import java.util.*
|
||||
import kotlin.streams.*
|
||||
import java.util.Random
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
fun randomString(length: Long): String {
|
||||
val chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -28,4 +28,4 @@ fun randomString(length: Long): String {
|
||||
.asSequence()
|
||||
.map(chars::get)
|
||||
.joinToString("")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user