Skip to content

Commit

Permalink
fix: 优化代码及修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Sep 8, 2024
1 parent 74ce5e7 commit e4c7df7
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/main/kotlin/subit/ForumBackend.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package subit

import io.ktor.server.application.*
import io.ktor.server.config.*
import io.ktor.server.config.ConfigLoader.Companion.load
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import net.mamoe.yamlkt.Yaml
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/subit/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import subit.database.sqlImpl.SqlDatabaseImpl
import subit.logger.ForumLogger
import subit.utils.Power.shutdown
import kotlin.reflect.KClass
import kotlin.reflect.KType

val databaseImpls: List<IDatabase> = listOf(
SqlDatabaseImpl,
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/subit/database/memoryImpl/PostVersionsImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.datetime.Instant
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import subit.dataClasses.*
import subit.database.PostVersions
import subit.database.Posts
import subit.dataClasses.Slice.Companion.asSlice
import subit.utils.toInstant

class PostVersionsImpl: PostVersions, KoinComponent
{
private val posts: Posts by inject()

private val lock = Mutex()
internal val list: MutableList<PostVersionInfo> = mutableListOf()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/subit/database/memoryImpl/PostsImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PostsImpl: Posts, KoinComponent
block: BlockId,
parent: PostId?,
top: Boolean
): PostId?
): PostId
{
val id = (map.size + 1).toPostId()
map[id] = PostInfo(
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.koin.core.module.dsl.singleOf
import org.koin.core.qualifier.named
import org.koin.dsl.bind
import org.koin.dsl.module
import org.koin.ktor.ext.get
import subit.console.AnsiStyle.Companion.RESET
import subit.console.SimpleAnsiColor.Companion.CYAN
import subit.console.SimpleAnsiColor.Companion.GREEN
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/subit/plugin/RateLimit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package subit.plugin
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.ratelimit.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import subit.dataClasses.PostId.Companion.toPostId
import subit.dataClasses.PostId.Companion.toPostIdOrNull
import subit.utils.HttpStatus
import subit.utils.respond
import java.util.*
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/router/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

package subit.router.home

import io.github.smiley4.ktorswaggerui.dsl.routing.*
import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.route
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.ratelimit.*
Expand All @@ -13,7 +14,6 @@ import subit.JWTAuth.getLoginUser
import subit.dataClasses.*
import subit.database.Blocks
import subit.database.Posts
import subit.database.Users
import subit.database.receiveAndCheckBody
import subit.plugin.RateLimit
import subit.router.*
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/subit/router/Posts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package subit.router.posts
import io.github.smiley4.ktorswaggerui.dsl.routing.*
import io.ktor.server.application.*
import io.ktor.server.plugins.ratelimit.*
import io.ktor.server.request.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
import subit.JWTAuth.getLoginUser
Expand Down Expand Up @@ -332,6 +331,8 @@ private suspend fun Context.editPost()
content = newContent.toString()
)

markings.map { it.copy(postVersion = newVersion) }

//////////////////////////// 以下为对划词评论的处理 ////////////////////////////

val pre = IntArray(oldVersionInfo.content.length + 1)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/subit/router/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private suspend fun Context.getUserInfo()
{
val user = SSO.getBasicUserInfo(id) ?: return call.respond(HttpStatus.NotFound)
// 这里需要判断类型并转换再返回, 因为respond的返回体类型是编译时确定的
if (user is UserFull) return call.respond(HttpStatus.OK, user as UserFull)
if (user is UserFull) return call.respond<UserFull>(HttpStatus.OK, user)
return call.respond(HttpStatus.OK, user as BasicUserInfo)
}
}
Expand Down

0 comments on commit e4c7df7

Please sign in to comment.