Merge branch 'develop' into mock

This commit is contained in:
usbharu 2024-05-18 15:22:42 +09:00 committed by GitHub
commit 7813cb2cbb
21 changed files with 51 additions and 56 deletions

View File

@ -194,7 +194,7 @@ dependencies {
implementation("dev.usbharu:owl-common-serialize-jackson:0.0.1")
implementation("io.trbl:blurhash:1.0.0")
implementation("software.amazon.awssdk:s3:2.25.54")
implementation("software.amazon.awssdk:s3:2.25.55")
implementation("org.jsoup:jsoup:1.17.2")
implementation("com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1")
implementation("org.postgresql:postgresql:42.7.3")
@ -260,6 +260,14 @@ detekt {
autoCorrect = true
}
configurations.matching { it.name == "detekt" }.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion())
}
}
}
tasks.withType<io.gitlab.arturbosch.detekt.Detekt> {
exclude("**/generated/**")
doFirst {

View File

@ -38,4 +38,4 @@ object Constant {
)
)
)
}
}

View File

@ -41,14 +41,9 @@ open class StringOrObject {
return result
}
override fun toString(): String {
return "StringOrObject(contextString=$contextString, contextObject=$contextObject)"
}
override fun toString(): String = "StringOrObject(contextString=$contextString, contextObject=$contextObject)"
}
class StringOrObjectDeserializer : JsonDeserializer<StringOrObject>() {
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext): StringOrObject {
val readTree: JsonNode = p?.codec?.readTree(p) ?: return StringOrObject("")
@ -64,7 +59,6 @@ class StringOrObjectDeserializer : JsonDeserializer<StringOrObject>() {
StringOrObject("")
}
}
}
class StringORObjectSerializer : JsonSerializer<StringOrObject>() {

View File

@ -47,5 +47,4 @@ class APSendUndoServiceImpl(
owlProducer.publishTask(deliverUndoTask)
}
}

View File

@ -42,7 +42,6 @@ class ActivityPubConfig {
@Bean
@Qualifier("activitypub")
fun objectMapper(): ObjectMapper {
val module = SimpleModule().addSerializer(StringOrObject::class.java, StringORObjectSerializer())
val objectMapper = jacksonObjectMapper()

View File

@ -26,7 +26,6 @@ import com.nimbusds.jose.proc.SecurityContext
import dev.usbharu.hideout.activitypub.domain.model.StringORObjectSerializer
import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
import dev.usbharu.hideout.application.external.Transaction
import dev.usbharu.hideout.application.infrastructure.springframework.RoleHierarchyAuthorizationManagerFactory
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureHeaderChecker
@ -204,7 +203,6 @@ class SecurityConfig {
@Order(5)
fun defaultSecurityFilterChain(
http: HttpSecurity,
rf: RoleHierarchyAuthorizationManagerFactory,
): SecurityFilterChain {
http {
authorizeHttpRequests {

View File

@ -45,7 +45,7 @@ class SpringConfig {
@ConfigurationProperties("hideout")
data class ApplicationConfig(
val url: URL,
val private:Boolean = true
val private: Boolean = true,
)
@ConfigurationProperties("hideout.storage.s3")

View File

@ -204,7 +204,6 @@ data class Post private constructor(
)
return post
}
}
fun isPureRepost(): Boolean =
@ -214,11 +213,7 @@ data class Post private constructor(
this.replyId == null &&
this.repostId != null
fun delete(): Post {
return copy(deleted = true)
}
fun delete(): Post = copy(deleted = true)
fun restore(): Post {
return copy(deleted = false)
}
fun restore(): Post = copy(deleted = false)
}

View File

@ -18,7 +18,7 @@ package dev.usbharu.hideout.core.domain.model.post
import org.springframework.stereotype.Repository
@Suppress("LongParameterList")
@Suppress("LongParameterList", "TooManyFunctions")
@Repository
interface PostRepository {
suspend fun generateId(): Long

View File

@ -25,9 +25,8 @@ data class UpdateActorTask(
val apId: String,
) : Task()
@Component
data object UpdateActorTaskDef : TaskDefinition<UpdateActorTask> {
override val type: Class<UpdateActorTask>
get() = UpdateActorTask::class.java
}
}

View File

@ -26,7 +26,6 @@ import org.springframework.stereotype.Component
@Component
class PostResultRowMapper(private val postBuilder: Post.PostBuilder) : ResultRowMapper<Post> {
override fun map(resultRow: ResultRow): Post {
return postBuilder.of(
id = resultRow[Posts.id],
actorId = resultRow[Posts.actorId],

View File

@ -82,12 +82,12 @@ fun ResultRow.toDeletedActor(): DeletedActor = deletedActor(this)
private fun deletedActor(singleOr: ResultRow): DeletedActor {
return DeletedActor(
singleOr[DeletedActors.id],
singleOr[DeletedActors.name],
singleOr[DeletedActors.domain],
singleOr[DeletedActors.publicKey],
singleOr[DeletedActors.apId],
singleOr[DeletedActors.deletedAt]
id = singleOr[DeletedActors.id],
name = singleOr[DeletedActors.name],
domain = singleOr[DeletedActors.domain],
apiId = singleOr[DeletedActors.publicKey],
publicKey = singleOr[DeletedActors.apId],
deletedAt = singleOr[DeletedActors.deletedAt]
)
}

View File

@ -110,7 +110,8 @@ class PostRepositoryImpl(
override suspend fun saveAll(posts: List<Post>) {
Posts.batchUpsert(
posts, id,
posts,
id,
) {
this[id] = it.id
this[actorId] = it.actorId
@ -128,7 +129,8 @@ class PostRepositoryImpl(
}
val mediaIds = posts.flatMap { post -> post.mediaIds.map { post.id to it } }
PostsMedia.batchUpsert(
mediaIds, PostsMedia.postId
mediaIds,
PostsMedia.postId
) {
this[PostsMedia.postId] = it.first
this[PostsMedia.mediaId] = it.second

View File

@ -41,7 +41,7 @@ class AuthController(
}
@PostMapping("/auth/sign_up")
suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, model: Model): String {
suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm): String {
val registerAccount = authApiService.registerAccount(
RegisterAccountDto(
signUpForm.username,

View File

@ -20,4 +20,4 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor
interface AuthApiService {
suspend fun registerAccount(registerAccountDto: RegisterAccountDto): Actor
}
}

View File

@ -33,20 +33,22 @@ class AuthApiServiceImpl(
private val httpClient: HttpClient,
private val captchaConfig: CaptchaConfig,
private val objectMapper: ObjectMapper,
private val userService: UserService
private val userService: UserService,
) :
AuthApiService {
override suspend fun registerAccount(registerAccountDto: RegisterAccountDto): Actor {
if (captchaConfig.reCaptchaSecretKey != null && captchaConfig.reCaptchaSiteKey != null) {
val get =
httpClient.get("https://www.google.com/recaptcha/api/siteverify?secret=" + captchaConfig.reCaptchaSecretKey + "&response=" + registerAccountDto.recaptchaResponse)
httpClient.get(
"https://www.google.com/recaptcha/api/siteverify?secret=" +
captchaConfig.reCaptchaSecretKey + "&response=" + registerAccountDto.recaptchaResponse
)
val recaptchaResult = objectMapper.readValue<RecaptchaResult>(get.bodyAsText())
logger.debug("reCAPTCHA: {}", recaptchaResult)
require(recaptchaResult.success)
require(!(recaptchaResult.score < 0.5))
}
val createLocalUser = userService.createLocalUser(
UserCreateDto(
registerAccountDto.username,
@ -62,4 +64,4 @@ class AuthApiServiceImpl(
companion object {
private val logger = LoggerFactory.getLogger(AuthApiServiceImpl::class.java)
}
}
}

View File

@ -17,7 +17,7 @@
package dev.usbharu.hideout.core.service.auth
data class RegisterAccountDto(
val username:String,
val password:String,
val recaptchaResponse:String
val username: String,
val password: String,
val recaptchaResponse: String,
)

View File

@ -91,7 +91,6 @@ class PostServiceImpl(
postRepository.findByActorId(actorId).filterNot { it.deleted }.forEach { postRepository.save(it.delete()) }
actorRepository.save(actor.copy(postsCount = 0, lastPostDate = null))
}

View File

@ -156,12 +156,12 @@ class UserServiceImpl(
override suspend fun deleteRemoteActor(actorId: Long) {
val actor = actorRepository.findByIdWithLock(actorId) ?: throw UserNotFoundException.withId(actorId)
val deletedActor = DeletedActor(
actor.id,
actor.name,
actor.domain,
actor.url,
actor.publicKey,
Instant.now()
id = actor.id,
name = actor.name,
domain = actor.domain,
apiId = actor.url,
publicKey = actor.publicKey,
deletedAt = Instant.now()
)
relationshipRepository.deleteByActorIdOrTargetActorId(actorId, actorId)
@ -186,12 +186,12 @@ class UserServiceImpl(
val actor = actorRepository.findByIdWithLock(userId) ?: throw UserNotFoundException.withId(userId)
apSendDeleteService.sendDeleteActor(actor)
val deletedActor = DeletedActor(
actor.id,
actor.name,
actor.domain,
actor.url,
actor.publicKey,
Instant.now()
id = actor.id,
name = actor.name,
domain = actor.domain,
apiId = actor.url,
publicKey = actor.publicKey,
deletedAt = Instant.now()
)
relationshipRepository.deleteByActorIdOrTargetActorId(userId, userId)

View File

@ -18,6 +18,7 @@ package dev.usbharu.hideout.mastodon.domain.exception
import dev.usbharu.hideout.mastodon.domain.model.MastodonApiErrorResponse
@Suppress("UnnecessaryAbstractClass")
abstract class MastodonApiException : RuntimeException {
val response: MastodonApiErrorResponse<*>

View File

@ -151,7 +151,7 @@ class AccountApiServiceImpl(
userService.updateUserStatistics(id)
return@transaction accountService.findById(id)
}
} catch (e: UserNotFoundException) {
} catch (_: UserNotFoundException) {
throw AccountNotFoundException.ofId(id)
}
}