Skip to content

Commit

Permalink
feat: adjust response text
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliothmoon committed Jan 11, 2025
1 parent c0e814a commit bbe7c22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/main/kotlin/biz/cdkey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun next(): String {

fun acquireCDK(params: PlanParams): Resp {
with(params) {
(params.expireTime == null || params.expireTime!!.isBefore(LocalDateTime.now())).throwIf("过期时间设置有误")
(params.expireTime == null || params.expireTime!!.isBefore(LocalDateTime.now())).throwIf("The expiration time is incorrectly set")
}

val eTime = params.expireTime!!
Expand All @@ -70,8 +70,8 @@ fun acquireCDK(params: PlanParams): Resp {

fun validateCDK(params: ValidateParams): Resp {
with(params) {
specificationId.isNullOrBlank().throwIf("specificationId不能为空")
cdk.isNullOrBlank().throwIf("CDK不能为空")
specificationId.isNullOrBlank().throwIf("specificationId cannot be empty")
cdk.isNullOrBlank().throwIf("cdk cannot be empty")
}
val cdk = params.cdk!!
val specId = params.specificationId!!
Expand All @@ -87,7 +87,7 @@ fun validateCDK(params: ValidateParams): Resp {
val next = qr.next();
val expireTime = next[CDK.expireTime]!!

expireTime.isBefore(LocalDateTime.now()).throwIf("CDK已过期")
expireTime.isBefore(LocalDateTime.now()).throwIf("The cdk has expired")

val eId = next[CDK.specificationId]
if (eId == null) {
Expand All @@ -96,9 +96,9 @@ fun validateCDK(params: ValidateParams): Resp {
CDK.key eq cdk
}
set(CDK.specificationId, specId)
} > 0).throwIfNot("CDK绑定更新失败")
} > 0).throwIfNot("cdk binding update failed ")
} else {
(eId != specId).throwIf("CDK已被使用")
(eId != specId).throwIf("cdk has been used ")
}

limit(cdk)
Expand All @@ -118,7 +118,7 @@ private fun limit(cdk: String) {
val date = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now())
val key = "limit:${date}:${cdk}"
val cnt = RDS.get().get(key).get()?.toIntOrNull() ?: 0
(cnt > 7).throwIf("您的账号已被限制")
(cnt > 7).throwIf("your account has been restricted for today")

RDS.get().incr(key).get()

Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/biz/devloper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import java.util.*
* @return [Resp]
*/
fun validateToken(token: String?): Resp {
val tk = token.throwIfNullOrEmpty("Token不能为空", 400)
val tk = token.throwIfNullOrEmpty("The Token cannot be empty", 400)
val qr = DB.from(ApplicationToken)
.select(ApplicationToken.status, ApplicationToken.id)
.where {
ApplicationToken.applicationToken eq tk
}
.limit(1)
.iterator()
qr.hasNext().throwIfNot("Token无效")
qr.hasNext().throwIfNot("Invalid Token")

qr.next().apply {
(get(ApplicationToken.status) != 1).throwIf("Token状态不正确")
(get(ApplicationToken.status) != 1).throwIf("The Token status is incorrect")
}

return Resp.success()
Expand All @@ -39,7 +39,7 @@ fun validateToken(token: String?): Resp {
* @return [Resp]
*/
fun createApplication(applicationName: String?): Resp {
applicationName.throwIfNullOrEmpty("应用名不能为空")
applicationName.throwIfNullOrEmpty("The application name cannot be empty")

DB.insertAndGenerateKey(Application) {
set(Application.applicationName, applicationName)
Expand All @@ -53,7 +53,7 @@ fun createApplication(applicationName: String?): Resp {
* @return [Resp]
*/
fun createApplicationToken(applicationId: Int?): Resp {
applicationId.throwIfNullOrEmpty("应用Id不能为空")
applicationId.throwIfNullOrEmpty("The application Id cannot be empty")

val uuid = UUID.randomUUID().toString()
DB.insert(ApplicationToken) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/router/router.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private fun requireJsonParams(ctx: RoutingContext): String? {
val body = ctx.body().asString()
if (body == null || ctx.request().headers().get("content-type") != "application/json") {
ctx.response().setStatusCode(400)
ctx.end(Resp.fail("参数不合法").toJson())
ctx.end(Resp.fail("parameter invalid").toJson())
}
return body

Expand Down

0 comments on commit bbe7c22

Please sign in to comment.