style: コードを整形

This commit is contained in:
usbharu 2023-04-26 17:55:45 +09:00
parent 5e11b70d22
commit cabecd4fce
26 changed files with 73 additions and 68 deletions

View File

@ -29,7 +29,7 @@ data class Post(
data class PostEntity( data class PostEntity(
val id: Long, val id: Long,
val userId:Long, val userId: Long,
val overview: String? = null, val overview: String? = null,
val text: String, val text: String,
val createdAt: Long, val createdAt: Long,
@ -39,7 +39,7 @@ data class PostEntity(
val replyId: Long? = null val replyId: Long? = null
) )
fun ResultRow.toPost():PostEntity{ fun ResultRow.toPost(): PostEntity {
return PostEntity( return PostEntity(
id = this[Posts.id], id = this[Posts.id],
userId = this[Posts.userId], userId = this[Posts.userId],

View File

@ -6,6 +6,7 @@ import org.jetbrains.exposed.dao.id.LongIdTable
object UsersFollowers : LongIdTable("users_followers") { object UsersFollowers : LongIdTable("users_followers") {
val userId = long("user_id").references(Users.id).index() val userId = long("user_id").references(Users.id).index()
val followerId = long("follower_id").references(Users.id) val followerId = long("follower_id").references(Users.id)
init { init {
uniqueIndex(userId, followerId) uniqueIndex(userId, followerId)
} }

View File

@ -1,15 +1,16 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Accept : Object { open class Accept : Object {
public var `object`: Object? = null var `object`: Object? = null
public var actor:String? = null var actor: String? = null
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, name: String,
`object`: Object?, `object`: Object?,
actor: String? actor: String?
) : super(add(type,"Accept"), name) { ) : super(add(type, "Accept"), name) {
this.`object` = `object` this.`object` = `object`
this.actor = actor this.actor = actor
} }

View File

@ -1,10 +1,10 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Create : Object { open class Create : Object {
var `object` : Object? = null var `object`: Object? = null
protected constructor() : super() protected constructor() : super()
constructor(type: List<String> = emptyList(), name: String, `object`: Object?) : super(add(type,"Create"), name) { constructor(type: List<String> = emptyList(), name: String, `object`: Object?) : super(add(type, "Create"), name) {
this.`object` = `object` this.`object` = `object`
} }

View File

@ -1,15 +1,16 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Follow : Object { open class Follow : Object {
public var `object`:String? = null var `object`: String? = null
public var actor:String? = null var actor: String? = null
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, name: String,
`object`: String?, `object`: String?,
actor: String? actor: String?
) : super(add(type,"Follow"), name) { ) : super(add(type, "Follow"), name) {
this.`object` = `object` this.`object` = `object`
this.actor = actor this.actor = actor
} }

View File

@ -6,7 +6,7 @@ open class Image : Object {
protected constructor() : super() protected constructor() : super()
constructor(type: List<String> = emptyList(), name: String, mediaType: String?, url: String?) : super( constructor(type: List<String> = emptyList(), name: String, mediaType: String?, url: String?) : super(
add(type,"Image"), add(type, "Image"),
name name
) { ) {
this.mediaType = mediaType this.mediaType = mediaType

View File

@ -16,10 +16,10 @@ open class JsonLd {
@JsonProperty("@context") @JsonProperty("@context")
@JsonDeserialize(contentUsing = ContextDeserializer::class) @JsonDeserialize(contentUsing = ContextDeserializer::class)
@JsonSerialize(using = ContextSerializer::class) @JsonSerialize(using = ContextSerializer::class)
var context:List<String> = emptyList() var context: List<String> = emptyList()
@JsonCreator @JsonCreator
constructor(context:List<String>){ constructor(context: List<String>) {
this.context = context this.context = context
} }
@ -43,9 +43,12 @@ open class JsonLd {
} }
public class ContextDeserializer : JsonDeserializer<String>() { class ContextDeserializer : JsonDeserializer<String>() {
override fun deserialize(p0: com.fasterxml.jackson.core.JsonParser?, p1: com.fasterxml.jackson.databind.DeserializationContext?): String { override fun deserialize(
val readTree : JsonNode = p0?.codec?.readTree(p0) ?: return "" p0: com.fasterxml.jackson.core.JsonParser?,
p1: com.fasterxml.jackson.databind.DeserializationContext?
): String {
val readTree: JsonNode = p0?.codec?.readTree(p0) ?: return ""
if (readTree.isObject) { if (readTree.isObject) {
return "" return ""
} }
@ -53,17 +56,17 @@ public class ContextDeserializer : JsonDeserializer<String>() {
} }
} }
public class ContextSerializer : JsonSerializer<List<String>>() { class ContextSerializer : JsonSerializer<List<String>>() {
override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) { override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) {
if (value.isNullOrEmpty()) { if (value.isNullOrEmpty()) {
gen?.writeNull() gen?.writeNull()
return return
} }
if (value?.size == 1) { if (value.size == 1) {
gen?.writeString(value[0]) gen?.writeString(value[0])
} else { } else {
gen?.writeStartArray() gen?.writeStartArray()
value?.forEach { value.forEach {
gen?.writeString(it) gen?.writeString(it)
} }
gen?.writeEndArray() gen?.writeEndArray()

View File

@ -1,9 +1,10 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Key : Object { open class Key : Object {
var id:String? = null var id: String? = null
var owner:String? = null var owner: String? = null
var publicKeyPem:String? = null var publicKeyPem: String? = null
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String>, type: List<String>,
@ -11,7 +12,7 @@ open class Key : Object {
id: String?, id: String?,
owner: String?, owner: String?,
publicKeyPem: String? publicKeyPem: String?
) : super(add(type,"Key"), name) { ) : super(add(type, "Key"), name) {
this.id = id this.id = id
this.owner = owner this.owner = owner
this.publicKeyPem = publicKeyPem this.publicKeyPem = publicKeyPem

View File

@ -1,11 +1,12 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Note : Object { open class Note : Object {
var id:String? = null var id: String? = null
var attributedTo:String? = null var attributedTo: String? = null
var content:String? = null var content: String? = null
var published:String? = null var published: String? = null
var to:List<String> = emptyList() var to: List<String> = emptyList()
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
@ -15,7 +16,7 @@ open class Note : Object {
content: String?, content: String?,
published: String?, published: String?,
to: List<String> = emptyList() to: List<String> = emptyList()
) : super(add(type,"Note"), name) { ) : super(add(type, "Note"), name) {
this.id = id this.id = id
this.attributedTo = attributedTo this.attributedTo = attributedTo
this.content = content this.content = content

View File

@ -18,7 +18,7 @@ open class Object : JsonLd {
companion object { companion object {
@JvmStatic @JvmStatic
protected fun add(list:List<String>,type:String):List<String> { protected fun add(list: List<String>, type: String): List<String> {
val toMutableList = list.toMutableList() val toMutableList = list.toMutableList()
toMutableList.add(type) toMutableList.add(type)
return toMutableList.distinct() return toMutableList.distinct()
@ -46,7 +46,7 @@ open class Object : JsonLd {
} }
public class TypeSerializer : JsonSerializer<List<String>>() { class TypeSerializer : JsonSerializer<List<String>>() {
override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) { override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) {
println(value) println(value)
if (value?.size == 1) { if (value?.size == 1) {

View File

@ -1,14 +1,15 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
open class Person : Object { open class Person : Object {
private var id:String? = null private var id: String? = null
var preferredUsername:String? = null var preferredUsername: String? = null
var summary:String? = null var summary: String? = null
var inbox:String? = null var inbox: String? = null
var outbox:String? = null var outbox: String? = null
private var url:String? = null private var url: String? = null
private var icon: Image? = null private var icon: Image? = null
var publicKey: Key? = null var publicKey: Key? = null
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
@ -21,7 +22,7 @@ open class Person : Object {
url: String?, url: String?,
icon: Image?, icon: Image?,
publicKey: Key? publicKey: Key?
) : super(add(type,"Person"), name) { ) : super(add(type, "Person"), name) {
this.id = id this.id = id
this.preferredUsername = preferredUsername this.preferredUsername = preferredUsername
this.summary = summary this.summary = summary
@ -29,7 +30,7 @@ open class Person : Object {
this.outbox = outbox this.outbox = outbox
this.url = url this.url = url
this.icon = icon this.icon = icon
this.publicKey = publicKey this.publicKey = publicKey
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {

View File

@ -1,6 +1,6 @@
package dev.usbharu.hideout.domain.model.api package dev.usbharu.hideout.domain.model.api
data class StatusForPost( data class StatusForPost(
val status:String, val status: String,
val userId:Long val userId: Long
) )

View File

@ -4,13 +4,13 @@ import kjob.core.Job
sealed class HideoutJob(name: String = "") : Job(name) sealed class HideoutJob(name: String = "") : Job(name)
object ReceiveFollowJob : HideoutJob("ReceiveFollowJob"){ object ReceiveFollowJob : HideoutJob("ReceiveFollowJob") {
val actor = string("actor") val actor = string("actor")
val follow = string("follow") val follow = string("follow")
val targetActor = string("targetActor") val targetActor = string("targetActor")
} }
object DeliverPostJob : HideoutJob("DeliverPostJob"){ object DeliverPostJob : HideoutJob("DeliverPostJob") {
val post = string("post") val post = string("post")
val actor = string("actor") val actor = string("actor")
val inbox = string("inbox") val inbox = string("inbox")

View File

@ -1,5 +1,5 @@
package dev.usbharu.hideout.domain.model.wellknown package dev.usbharu.hideout.domain.model.wellknown
data class WebFinger(val subject:String,val links:List<Link>){ data class WebFinger(val subject: String, val links: List<Link>) {
data class Link(val rel:String,val type:String,val href:String) data class Link(val rel: String, val type: String, val href: String)
} }

View File

@ -63,8 +63,8 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo
println("Digest !!") println("Digest !!")
// UserAuthService.sha256.reset() // UserAuthService.sha256.reset()
val digest = val digest =
Base64.getEncoder().encodeToString(UserAuthService.sha256.digest(body.toByteArray(Charsets.UTF_8))) Base64.getEncoder().encodeToString(UserAuthService.sha256.digest(body.toByteArray(Charsets.UTF_8)))
request.headers.append("Digest", "sha-256="+digest) request.headers.append("Digest", "sha-256=" + digest)
} }
if (request.headers.contains("Signature")) { if (request.headers.contains("Signature")) {
@ -126,7 +126,7 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo
override fun addHeader(name: String?, value: String?) { override fun addHeader(name: String?, value: String?) {
val split = value?.split("=").orEmpty() val split = value?.split("=").orEmpty()
name?.let { request.header(it, split.get(0)+"=\""+split.get(1).trim('"')+"\"") } name?.let { request.header(it, split.get(0) + "=\"" + split.get(1).trim('"') + "\"") }
} }
override fun method(): String { override fun method(): String {

View File

@ -1,10 +1,10 @@
package dev.usbharu.hideout.plugins package dev.usbharu.hideout.plugins
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.cors.routing.* import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.plugins.defaultheaders.* import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.plugins.forwardedheaders.* import io.ktor.server.plugins.forwardedheaders.*
import io.ktor.server.application.*
fun Application.configureHTTP() { fun Application.configureHTTP() {
install(CORS) { install(CORS) {

View File

@ -1,9 +1,8 @@
package dev.usbharu.hideout.plugins package dev.usbharu.hideout.plugins
import io.ktor.server.plugins.callloging.*
import org.slf4j.event.*
import io.ktor.server.request.*
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.plugins.callloging.*
import org.slf4j.event.Level
fun Application.configureMonitoring() { fun Application.configureMonitoring() {
install(CallLogging) { install(CallLogging) {

View File

@ -25,7 +25,7 @@ fun Application.configureRouting(
routing { routing {
inbox(httpSignatureVerifyService, activityPubService) inbox(httpSignatureVerifyService, activityPubService)
outbox() outbox()
usersAP(activityPubUserService,userService) usersAP(activityPubUserService, userService)
webfinger(userService) webfinger(userService)
route("/api/v1") { route("/api/v1") {

View File

@ -3,8 +3,6 @@ package dev.usbharu.hideout.plugins
import dev.usbharu.hideout.service.IUserAuthService import dev.usbharu.hideout.service.IUserAuthService
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.auth.* import io.ktor.server.auth.*
import io.ktor.server.sessions.*
import kotlin.collections.set
data class UserSession(val username: String) : Principal data class UserSession(val username: String) : Principal

View File

@ -4,13 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonSetter import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls import com.fasterxml.jackson.annotation.Nulls
import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.DeserializationFeature
import dev.usbharu.hideout.util.HttpUtil.Activity
import io.ktor.http.*
import io.ktor.serialization.jackson.* import io.ktor.serialization.jackson.*
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.* import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Application.configureSerialization() { fun Application.configureSerialization() {
install(ContentNegotiation) { install(ContentNegotiation) {

View File

@ -33,7 +33,7 @@ class ActivityPubServiceImpl(
return ActivityType.values().first { it.name.equals(type.asText(), true) } return ActivityType.values().first { it.name.equals(type.asText(), true) }
} }
override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse? { override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse {
return when (type) { return when (type) {
ActivityType.Accept -> TODO() ActivityType.Accept -> TODO()
ActivityType.Add -> TODO() ActivityType.Add -> TODO()

View File

@ -10,7 +10,7 @@ import tech.barbero.http.message.signing.SignatureHeaderVerifier
class HttpSignatureVerifyServiceImpl(private val userAuthService: IUserRepository) : HttpSignatureVerifyService { class HttpSignatureVerifyServiceImpl(private val userAuthService: IUserRepository) : HttpSignatureVerifyService {
override fun verify(headers: Headers): Boolean { override fun verify(headers: Headers): Boolean {
val build = SignatureHeaderVerifier.builder().keyMap(KtorKeyMap(userAuthService)).build() val build = SignatureHeaderVerifier.builder().keyMap(KtorKeyMap(userAuthService)).build()
return true; return true
build.verify(object : HttpMessage { build.verify(object : HttpMessage {
override fun headerValues(name: String?): MutableList<String> { override fun headerValues(name: String?): MutableList<String> {
return name?.let { headers.getAll(it) }?.toMutableList() ?: mutableListOf() return name?.let { headers.getAll(it) }?.toMutableList() ?: mutableListOf()

View File

@ -30,6 +30,10 @@ object HttpUtil {
get() = ContentType("application", "activity+json") get() = ContentType("application", "activity+json")
val ContentType.Application.JsonLd: ContentType val ContentType.Application.JsonLd: ContentType
get() = ContentType("application", "ld+json", listOf(HeaderValueParam("profile", "https://www.w3.org/ns/activitystreams"))) get() = ContentType(
"application",
"ld+json",
listOf(HeaderValueParam("profile", "https://www.w3.org/ns/activitystreams"))
)
// fun // fun
} }

View File

@ -14,7 +14,6 @@ import org.jetbrains.exposed.dao.id.LongIdTable
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull
import org.jetbrains.exposed.sql.SqlExpressionBuilder.plus import org.jetbrains.exposed.sql.SqlExpressionBuilder.plus
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction

View File

@ -1,5 +1,5 @@
import {Component} from "solid-js"; import {Component} from "solid-js";
export const App:Component = () => { export const App: Component = () => {
return (<p>aaa</p>) return (<p>aaa</p>)
} }

View File

@ -1,10 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta name="theme-color" content="#000000" /> <meta content="#000000" name="theme-color"/>
<title>Solid App</title> <title>Solid App</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>