Skip to content

Commit

Permalink
fix: 修复主配置文件的错误, 修复命名
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Oct 5, 2024
1 parent eba36c7 commit 1d9ed29
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Subit ForumBackendKtor Artifact
name: Subit YouthWriteBackend Artifact
path: build/libs/*.jar
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ForumBackendKtor
# YouthWriteBackend

新一代论坛后端,完全使用ktor和Kotlin/Jvm
北大附中创意写作选修课官网后端

开源协议: [AGPL-3.0](https://www.gnu.org/licenses/agpl-3.0.html)

Expand All @@ -9,7 +9,7 @@
1. 确保您的电脑上安装了JDK 17或更高版本
2. 克隆本仓库
3. 运行`./gradlew clean build`构建项目
4.`build/libs`目录下找到`ForumBackendKtor-all.jar`文件
4.`build/libs`目录下找到`YouthWriteBackend.jar`文件
## 运行
请先确保您的电脑上拥有JRE 17或更高版本, 在命令行中输入以下内容以检查是否安装了JRE及其版本
```shell
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ group = "subit"
version = "0.0.1"

application {
mainClass.set("subit.ForumBackendKt")
mainClass.set("subit.YouthWriteKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.ktor.server.netty.*
import net.mamoe.yamlkt.Yaml
import subit.console.command.CommandSet.startCommandThread
import subit.database.loadDatabaseImpl
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.plugin.apiDoc.installApiDoc
import subit.plugin.authentication.installAuthentication
import subit.plugin.autoHead.installAutoHead
Expand Down Expand Up @@ -88,7 +88,7 @@ fun main(args: Array<String>)
?.readAllBytes()
?.let(configFile::writeBytes)
?: error("default_config.yaml not found")
ForumLogger.getLogger().severe(
YouthWriteLogger.getLogger().severe(
"config.yaml not found, the default config has been created, " +
"please modify it and restart the program"
)
Expand Down Expand Up @@ -123,8 +123,8 @@ fun Application.init()

Loader.getResource("logo/SubIT-logo.txt")
?.bufferedReader()
?.use { it.readText().split("\n").forEach(ForumLogger.globalLogger::info) }
?: ForumLogger.globalLogger.warning("SubIT-logo.txt not found")
?.use { it.readText().split("\n").forEach(YouthWriteLogger.globalLogger::info) }
?: YouthWriteLogger.globalLogger.warning("SubIT-logo.txt not found")

startCommandThread()

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.serialization.serializer
import net.mamoe.yamlkt.Yaml
import net.mamoe.yamlkt.YamlElement
import net.mamoe.yamlkt.YamlMap
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.workDir
import java.io.File
import java.lang.ref.WeakReference
Expand Down Expand Up @@ -62,7 +62,7 @@ class ConfigLoader<T: Any> private constructor(
@Suppress("unused", "MemberVisibilityCanBePrivate")
companion object
{
private val logger by lazy { ForumLogger.getLogger() }
private val logger by lazy { YouthWriteLogger.getLogger() }
fun init() // 初始化所有配置
{
apiDocsConfig
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/subit/config/LoggerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package subit.config
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.builtins.serializer
import net.mamoe.yamlkt.Comment
import subit.console.ColorDisplayMode
import subit.console.Console
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.logger.ToFileHandler
import java.util.logging.Level
import java.util.logging.LogRecord
Expand Down Expand Up @@ -47,7 +46,7 @@ var loggerConfig: LoggerConfig by config(
"logger.yml",
LoggerConfig(listOf(), true, "INFO", false, ColorDisplayMode.RGB, true, 7.days),
{ _, new ->
ForumLogger.globalLogger.logger.setLevel(new.level)
YouthWriteLogger.globalLogger.logger.setLevel(new.level)
Console.ansiEffectMode =
if (new.effect) subit.console.EffectDisplayMode.ON
else subit.console.EffectDisplayMode.OFF
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/subit/console/Console.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.jline.widget.AutopairWidgets
import org.jline.widget.AutosuggestionWidgets
import subit.console.command.CommandSet
import subit.dataDir
import subit.logger.ForumLogger.nativeOut
import subit.logger.YouthWriteLogger.nativeOut
import subit.utils.Power
import sun.misc.Signal
import java.io.File
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/subit/console/command/About.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object About: Command

override suspend fun execute(sender: CommandSet.CommandSender, args: List<String>): Boolean
{
sender.out("SubIT Forum Backend")
sender.out("SubIT Youth Write Backend")
sender.out("Version: $version")
sender.out("Author: SubIT Team")
sender.out("Github: https://github.com/subitlab")
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/subit/console/command/CommandSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import subit.console.AnsiStyle.Companion.RESET
import subit.console.AnsiStyle.Companion.ansi
import subit.console.Console
import subit.console.SimpleAnsiColor
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.utils.Power.shutdown

/**
Expand All @@ -29,7 +29,7 @@ object CommandSet: TreeCommand(
TestDatabase,
)
{
private val logger = ForumLogger.getLogger()
private val logger = YouthWriteLogger.getLogger()

/**
* 上一次命令是否成功
Expand All @@ -41,7 +41,7 @@ object CommandSet: TreeCommand(
/**
* 命令提示符, 上一次成功为青色, 失败为红色
*/
private val prompt: String get() = parsePrompt("FORUM > ")
private val prompt: String get() = parsePrompt("YouthWrite > ")
private val rightPrompt: String get() = parsePrompt("<| POWERED BY SUBIT |>")

fun Application.startCommandThread() = CoroutineScope(Dispatchers.IO).launch()
Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/subit/console/command/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package subit.console.command

import org.jline.reader.Candidate
import subit.config.loggerConfig
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger

/**
* Logger control.
Expand All @@ -23,13 +23,13 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
{
if (args.isEmpty()) // 没参数就打印当前日志等级
{
sender.out("logger level: ${ForumLogger.globalLogger.logger.level.name}")
sender.out("logger level: ${YouthWriteLogger.globalLogger.logger.level.name}")
}
else try
{
// 有参数就设置日志等级
val level=java.util.logging.Level.parse(args[0])
ForumLogger.setLevel(level)
YouthWriteLogger.setLevel(level)
sender.out("set logger level to ${level.name}")
}
catch (e: IllegalArgumentException) // 输入的日志等级不合法
Expand Down Expand Up @@ -74,7 +74,7 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
sender.err("No filter specified.")
return true
}
ForumLogger.addFilter(args[0])
YouthWriteLogger.addFilter(args[0])
sender.out("Added filter: ${args[0]}")
return true
}
Expand All @@ -99,7 +99,7 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
sender.err("No filter specified.")
return true
}
ForumLogger.removeFilter(args[0])
YouthWriteLogger.removeFilter(args[0])
sender.out("Removed filter: ${args[0]}")
return true
}
Expand All @@ -108,7 +108,7 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
{
if (args.size==1)
{
return ForumLogger.filters().map { Candidate(it) }
return YouthWriteLogger.filters().map { Candidate(it) }
}
return listOf()
}
Expand All @@ -128,7 +128,7 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
): Boolean
{
sender.out("Filters:")
for (filter in ForumLogger.filters())
for (filter in YouthWriteLogger.filters())
{
sender.out("- $filter")
}
Expand Down Expand Up @@ -159,12 +159,12 @@ object Logger : TreeCommand(Level, Filter, ShowLoggerName)
{
"whitelist" ->
{
ForumLogger.setWhiteList(true)
YouthWriteLogger.setWhiteList(true)
sender.out("set filter mode to whitelist")
}
"blacklist" ->
{
ForumLogger.setWhiteList(false)
YouthWriteLogger.setWhiteList(false)
sender.out("set filter mode to blacklist")
}
else ->
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/dataClasses/Slice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package subit.dataClasses

import kotlinx.serialization.Serializable
import subit.dataClasses.Slice.Companion.asSlice
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

Expand All @@ -28,7 +28,7 @@ data class Slice<T>(
@Suppress("unused")
companion object
{
val logger = ForumLogger.getLogger()
val logger = YouthWriteLogger.getLogger()
/**
* 生成一个空切片
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import subit.console.SimpleAnsiColor.Companion.GREEN
import subit.console.SimpleAnsiColor.Companion.RED
import subit.database.memoryImpl.MemoryDatabaseImpl
import subit.database.sqlImpl.SqlDatabaseImpl
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.utils.Power.shutdown
import kotlin.reflect.KClass

Expand All @@ -18,7 +18,7 @@ val databaseImpls: List<IDatabase> = listOf(

fun Application.loadDatabaseImpl()
{
val logger = ForumLogger.getLogger()
val logger = YouthWriteLogger.getLogger()
val impls = databaseImpls.associateBy { it.name }
logger.config("Available database implementations: ${impls.keys.joinToString(", ")}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import subit.console.SimpleAnsiColor.Companion.RED
import subit.console.SimpleAnsiColor.Companion.YELLOW
import subit.database.*
import subit.debug
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.utils.Power

object MemoryDatabaseImpl: IDatabase, KoinComponent
Expand All @@ -20,7 +20,7 @@ object MemoryDatabaseImpl: IDatabase, KoinComponent

override fun Application.init()
{
val logger = ForumLogger.getLogger()
val logger = YouthWriteLogger.getLogger()
logger.info("Init database. impl: $name")

if (!debug)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import subit.console.SimpleAnsiColor.Companion.GREEN
import subit.console.SimpleAnsiColor.Companion.RED
import subit.dataClasses.*
import subit.database.*
import subit.logger.ForumLogger
import subit.logger.YouthWriteLogger
import subit.utils.Power.shutdown
import java.sql.Driver
import kotlin.reflect.KClass
Expand Down Expand Up @@ -54,7 +54,7 @@ object SqlDatabaseImpl: IDatabase, KoinComponent
* 数据库
*/
private lateinit var config: ApplicationConfig
private val logger = ForumLogger.getLogger()
private val logger = YouthWriteLogger.getLogger()
private val drivers:List<Driver> = listOf(
org.postgresql.Driver(),
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/logger/LogbackAppender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.logging.Level
import java.util.logging.LogRecord

/**
* 使用[ForumLogger]接管ktor的logger
* 使用[YouthWriteLogger]接管ktor的logger
*/
class LogbackAppender: AppenderBase<ILoggingEvent>()
{
Expand All @@ -36,7 +36,7 @@ class LogbackAppender: AppenderBase<ILoggingEvent>()
.toArray { size: Int -> arrayOfNulls(size) })
record.thrown = throwable
}
ForumLogger.globalLogger.logger.log(record)
YouthWriteLogger.globalLogger.logger.log(record)
}.onFailure { AnsiConsole.sysOut().println("Failure in LogbackAppender, message: ${it.stackTraceToString()}"); }.run { }

private fun fromInt(id: Int): Level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import subit.console.Console
import subit.console.SimpleAnsiColor
import subit.console.SimpleAnsiColor.Companion.CYAN
import subit.console.SimpleAnsiColor.Companion.PURPLE
import subit.logger.ForumLogger.safe
import subit.logger.YouthWriteLogger.safe
import subit.workDir
import java.io.*
import java.text.SimpleDateFormat
Expand All @@ -29,7 +29,7 @@ import kotlin.time.Duration
* logger系统
*/
@Suppress("MemberVisibilityCanBePrivate")
object ForumLogger
object YouthWriteLogger
{
val globalLogger = LoggerUtils(Logger.getLogger(""))
fun getLogger(name: String): LoggerUtils = LoggerUtils(Logger.getLogger(name))
Expand Down Expand Up @@ -178,7 +178,7 @@ object ToConsoleHandler: Handler()
val head = if (loggerConfig.showLoggerName) String.format(
"%s[%s]%s[%s]%s[%s]%s",
PURPLE.bright(),
ForumLogger.loggerDateFormat.format(record.millis),
YouthWriteLogger.loggerDateFormat.format(record.millis),
CYAN.bright(),
record.loggerName,
ansiStyle,
Expand All @@ -188,7 +188,7 @@ object ToConsoleHandler: Handler()
else String.format(
"%s[%s]%s[%s]%s",
PURPLE.bright(),
ForumLogger.loggerDateFormat.format(record.millis),
YouthWriteLogger.loggerDateFormat.format(record.millis),
ansiStyle,
level.name,
RESET,
Expand Down Expand Up @@ -260,13 +260,13 @@ object ToFileHandler: Handler()
val level = record.level
val head = if (loggerConfig.showLoggerName) String.format(
"[%s][%s][%s]",
ForumLogger.loggerDateFormat.format(record.millis),
YouthWriteLogger.loggerDateFormat.format(record.millis),
record.loggerName,
level.name
)
else String.format(
"[%s][%s]",
ForumLogger.loggerDateFormat.format(record.millis),
YouthWriteLogger.loggerDateFormat.format(record.millis),
level.name
)
return messages.joinToString("\n") { "$head $it" }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/subit/plugin/ApiDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fun Application.installApiDoc() = install(SwaggerUI)
{
info()
{
title = "论坛后端API文档"
title = "创意写作官网后端API文档"
version = subit.version
description = "SubIT论坛后端API文档"
description = "SubIT创意写作官网后端API文档"
}
this.ignoredRouteSelectors += RateLimitRouteSelector::class

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/subit/plugin/Authentication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun Application.installAuthentication() = install(Authentication)
}
}

bearer("forum-auth")
bearer("auth")
{
authHeader {
val token = it.request.header(HttpHeaders.Authorization) ?: run {
Expand Down
Loading

0 comments on commit 1d9ed29

Please sign in to comment.