style: スタイルを修正

This commit is contained in:
usbharu 2023-05-02 16:21:12 +09:00
parent 95e47a0e9b
commit 2f1df0bcfd
24 changed files with 50 additions and 47 deletions

View File

@ -38,7 +38,7 @@ val Application.property: Application.(propertyName: String) -> String
}
// application.conf references the main function. This annotation prevents the IDE from marking it as unused.
@Suppress("unused")
@Suppress("unused", "LongMethod")
fun Application.parent() {
Config.configData = ConfigData(
url = property("hideout.url"),

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit
const val TOKEN_AUTH = "jwt-auth"
@Suppress("MagicNumber")
fun Application.configureSecurity(
userAuthService: IUserAuthService,
metaService: IMetaService,
@ -39,7 +40,6 @@ fun Application.configureSecurity(
jwt(TOKEN_AUTH) {
verifier(jwkProvider, issuer) {
acceptLeeway(3)
}
validate { jwtCredential ->
if (jwtCredential.payload.getClaim("username").asString().isNotEmpty()) {

View File

@ -22,6 +22,7 @@ class JwtRefreshTokenRepositoryImpl(
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T =
newSuspendedTransaction(Dispatchers.IO) { block() }

View File

@ -16,6 +16,7 @@ class MetaRepositoryImpl(private val database: Database) : IMetaRepository {
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T =
newSuspendedTransaction(Dispatchers.IO) { block() }

View File

@ -20,6 +20,7 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T =
newSuspendedTransaction(Dispatchers.IO) { block() }

View File

@ -21,6 +21,7 @@ class UserRepository(private val database: Database, private val idGenerateServi
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T =
newSuspendedTransaction(Dispatchers.IO) { block() }

View File

@ -7,7 +7,6 @@ import io.ktor.server.auth.jwt.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Routing.authTestRouting() {
authenticate(TOKEN_AUTH) {
get("/auth-check") {

View File

@ -4,5 +4,4 @@ import dev.usbharu.hideout.service.IUserAuthService
import io.ktor.server.routing.*
fun Routing.login(userAuthService: IUserAuthService) {
}

View File

@ -18,6 +18,7 @@ import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*
@Suppress("InjectDispatcher")
class JwtServiceImpl(
private val metaService: IMetaService,
private val refreshTokenRepository: IJwtRefreshTokenRepository,
@ -42,6 +43,7 @@ class JwtServiceImpl(
}
}
@Suppress("MagicNumber")
override suspend fun createToken(user: User): JwtToken {
val now = Instant.now()
val token = JWT.create()

View File

@ -4,16 +4,16 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Jwt
import dev.usbharu.hideout.domain.model.hideout.entity.Meta
import dev.usbharu.hideout.repository.IMetaRepository
import dev.usbharu.hideout.util.ServerUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.security.KeyPairGenerator
import java.util.*
class ServerInitialiseServiceImpl(private val metaRepository: IMetaRepository) : IServerInitialiseService {
val logger = LoggerFactory.getLogger(ServerInitialiseServiceImpl::class.java)
val logger: Logger = LoggerFactory.getLogger(ServerInitialiseServiceImpl::class.java)
override suspend fun init() {
val savedMeta = metaRepository.get()
val implementationVersion = ServerUtil.getImplementationVersion()
if (wasInitialised(savedMeta).not()) {
@ -27,7 +27,6 @@ class ServerInitialiseServiceImpl(private val metaRepository: IMetaRepository) :
logger.info("Version changed!! (${savedMeta.version} -> $implementationVersion)")
updateVersion(savedMeta, implementationVersion)
}
}
private fun wasInitialised(meta: Meta?): Boolean {

View File

@ -77,7 +77,7 @@ class ActivityPubUserServiceImpl(
publicKeyPem = userEntity.publicKey
)
)
} catch (e: UserNotFoundException) {
} catch (ignore: UserNotFoundException) {
val httpResponse = if (targetActor != null) {
httpClient.getAp(url, "$targetActor#pubkey")
} else {

View File

@ -6,5 +6,4 @@ object Base64Util {
fun decode(str: String): ByteArray = Base64.getDecoder().decode(str)
fun encode(bytes: ByteArray): String = Base64.getEncoder().encodeToString(bytes)
}

View File

@ -21,9 +21,7 @@ object JsonWebKeyUtil {
}
private fun encodeBase64UInt(bigInteger: BigInteger, minLength: Int = -1): String {
if(bigInteger.signum() < 0){
throw IllegalArgumentException("Cannot encode negative numbers")
}
require(bigInteger.signum() >= 0) { "Cannot encode negative numbers" }
var bytes = bigInteger.toByteArray()
if (bigInteger.bitLength() % 8 == 0 && (bytes[0] == 0.toByte()) && bytes.size > 1) {

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.util
object ServerUtil {
fun getImplementationVersion():String = ServerUtil.javaClass.`package`.implementationVersion ?: "DEVELOPMENT-VERSION"
fun getImplementationVersion(): String =
ServerUtil.javaClass.`package`.implementationVersion ?: "DEVELOPMENT-VERSION"
}

View File

@ -54,6 +54,7 @@ class ExposedJobRepository(
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T = newSuspendedTransaction(Dispatchers.IO) { block() }
override suspend fun completeProgress(id: String): Boolean {
@ -204,7 +205,7 @@ class ExposedJobRepository(
this ?: return emptyMap()
return json.parseToJsonElement(this).jsonObject.mapValues { (_, el) ->
if (el is JsonObject) {
val t = el["t"]?.jsonPrimitive?.content ?: error("Cannot get jsonPrimitive")
val t = el["t"]?.run { jsonPrimitive.content } ?: error("Cannot get jsonPrimitive")
val value = el["v"]?.jsonArray ?: error("Cannot get jsonArray")
when (t) {
"s" -> value.map { it.jsonPrimitive.content }

View File

@ -33,6 +33,7 @@ class ExposedLockRepository(
}
}
@Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T = newSuspendedTransaction(Dispatchers.IO) { block() }
override suspend fun exists(id: UUID): Boolean {