Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Mar 14, 2024
2 parents 2d28735 + 72ca97f commit 1e71dd4
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 367 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,27 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: ts-client
path: ./build/clients/ts-fetch-client/*
path: ./build/clients/ts-fetch-client/*

- name: Checkout maa-copilot-client-ts
uses: actions/checkout@v4
with:
repository: MaaAssistantArknights/maa-copilot-client-ts
path: maa-copilot-client-ts
token: ${{ secrets.TS_CLIENT_PAT }}

- name: Update maa-copilot-client-ts and push to remote
run: |
cp -rf build/clients/ts-fetch-client/* maa-copilot-client-ts/
cd maa-copilot-client-ts
git diff --quiet && exit 0
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "release: ${{ steps.version.outputs.version }}"\
-m "Generated from https://github.com/MaaAssistantArknights/MaaBackendCenter/actions/runs/${{ github.run_id }}"
git tag ${{ steps.version.outputs.version }}
git push
git push --tags
5 changes: 3 additions & 2 deletions client-config/ts-fetch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"npmName": "maa-copilot-client",
"npmVersion": "1.0.0",
"modelPropertyNaming": "camelCase"
}
"modelPropertyNaming": "camelCase",
"supportsES6": true
}
6 changes: 3 additions & 3 deletions src/main/kotlin/plus/maa/backend/common/aop/JsonSchemaAop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import plus.maa.backend.controller.request.copilot.CopilotRatingReq
import plus.maa.backend.controller.response.MaaResultException
import java.io.IOException

private val log = KotlinLogging.logger { }
private val log = KotlinLogging.logger { }

/**
* @author LoMu
Expand Down Expand Up @@ -61,12 +61,12 @@ class JsonSchemaAop(
}
}
}
if (content == null) return
if (schemaJson == null || content == null) return


//获取json schema json路径并验证
try {
ClassPathResource(schemaJson!!).inputStream.use { inputStream ->
ClassPathResource(schemaJson).inputStream.use { inputStream ->
val json = JSONObject(content)
val jsonObject = JSONObject(JSONTokener(inputStream))
val schema = SchemaLoader.load(jsonObject)
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/plus/maa/backend/common/utils/KtExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package plus.maa.backend.common.utils


inline fun <T> T?.requireNotNull(lazyMessage: () -> Any): T = requireNotNull(this, lazyMessage)

This file was deleted.

17 changes: 2 additions & 15 deletions src/main/kotlin/plus/maa/backend/controller/CopilotController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class CopilotController(
@ApiResponse(description = "删除作业结果")
@RequireJwt
@PostMapping("/delete")
fun deleteCopilot(@RequestBody request: CopilotCUDRequest?): MaaResult<Unit> {
copilotService.delete(helper.requireUserId(), request!!)
fun deleteCopilot(@RequestBody request: CopilotCUDRequest): MaaResult<Unit> {
copilotService.delete(helper.requireUserId(), request)
return success()
}

Expand All @@ -74,19 +74,6 @@ class CopilotController(
fun queriesCopilot(
@ParameterObject parsed: @Valid CopilotQueriesRequest
): MaaResult<CopilotPageInfo> {
// FIXME 请求对下划线的处理存在问题,需要更正
if (parsed.copilotIds == null) {
parsed.copilotIds = parsed.copilot_ids
}
if (parsed.levelKeyword == null) {
parsed.levelKeyword = parsed.level_keyword
}
if (parsed.orderBy == null) {
parsed.orderBy = parsed.order_by
}
if (parsed.uploaderId == null) {
parsed.uploaderId = parsed.uploader_id
}
// 三秒防抖,缓解前端重复请求问题
response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=3, must-revalidate")
return success(copilotService.queriesCopilot(helper.userId, parsed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ import org.hibernate.validator.constraints.Length
* Date 2023-02-17 14:58
*/
data class CommentsAddDTO(
// 评论内容
/**
* 评论内容
*/
@field:Length(min = 1, max = 150, message = "评论内容不可超过150字,请删减")
@field:NotBlank(message = "请填写评论内容")
val message: String,
// 评论的作业id
/**
* 评论所在作业的 id
*/
val copilotId: Long,
// 子评论来源评论id(回复评论)
/**
* 被回复评论的 id
*/
val fromCommentId: String? = null,
/**
* 是否接收通知
*/
val notification: Boolean = true
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plus.maa.backend.controller.request.copilot

import jakarta.validation.constraints.Max
import org.springframework.web.bind.annotation.BindParam

/**
* @author LoMu
Expand All @@ -9,42 +10,13 @@ import jakarta.validation.constraints.Max
data class CopilotQueriesRequest(
val page: Int = 0,
val limit: @Max(value = 50, message = "单页大小不得超过50") Int = 10,
var levelKeyword: String? = null,
val level_keyword: String? = null,
@BindParam("level_keyword") var levelKeyword: String? = null,
val operator: String? = null,
val content: String? = null,
val document: String? = null,
var uploaderId: String? = null,
val uploader_id: String? = null,
@BindParam("uploader_id") var uploaderId: String? = null,
val desc: Boolean = true,
var orderBy: String? = null,
val order_by: String? = null,
@BindParam("order_by") var orderBy: String? = null,
val language: String? = null,
var copilotIds: List<Long>? = null,
val copilot_ids: List<Long>? = null
) {

// /*
// * 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
// * 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名
// * 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示
// * (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
// */
// @JsonIgnore
// @Suppress("unused")
// fun setLevel_keyword(levelKeyword: String?) {
// this.levelKeyword = levelKeyword
// }
//
// @JsonIgnore
// @Suppress("unused")
// fun setUploader_id(uploaderId: String?) {
// this.uploaderId = uploaderId
// }
//
// @JsonIgnore
// @Suppress("unused")
// fun setCopilot_ids(copilotIds: List<Long>?) {
// this.copilotIds = copilotIds
// }
}
@BindParam("copilot_ids") var copilotIds: List<Long>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ package plus.maa.backend.controller.response.comments
*/
data class CommentsAreaInfo (
val hasNext: Boolean,
/**
* Total number of pages
*/
val page: Int,
/**
* Total number of elements
*/
val total: Long,
val data: List<CommentsInfo>
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class CopilotInfo (
val id: Long,

val uploadTime: LocalDateTime,
val uploaderId: String,
val uploader: String,

//用于前端显示的格式化后的干员信息 [干员名]::[技能]
Expand Down
14 changes: 4 additions & 10 deletions src/main/kotlin/plus/maa/backend/service/ArkGameDataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,11 @@ class ArkGameDataService(private val okHttpClient: OkHttpClient) {
}
val node = mapper.reader().readTree(body.string())
val characters = mapper.convertValue(node, object : TypeReference<Map<String, ArkCharacter>>() {})
characters.forEach { (id, c) -> c.id = id }
arkCharacterMap.clear()
characters.values.forEach { c ->
if (c.id.isNullOrBlank()) {
return@forEach
}
val ids = c.id!!.split("_")
if (ids.size != 3) {
// 不是干员
return@forEach
}
characters.forEach { (id, c) ->
val ids = id.split("_")
if (ids.size != 3) return@forEach
c.id = id
arkCharacterMap[ids[2]] = c
}
log.info { "[DATA]获取character数据成功, 共${arkCharacterMap.size}" }
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/plus/maa/backend/service/ArkLevelService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.time.ZoneId
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

private val log = KotlinLogging.logger { }
private val log = KotlinLogging.logger { }

/**
* @author dragove
Expand Down Expand Up @@ -164,7 +164,8 @@ class ArkLevelService(
*/
fun updateActivitiesOpenStatus() {
log.info { "[ACTIVITIES-OPEN-STATUS]准备更新活动地图开放状态" }
val stages = githubRepo.getContents(githubToken, "resource").firstOrNull { content: GithubContent -> content.isFile && "stages.json" == content.name }
val stages = githubRepo.getContents(githubToken, "resource")
.firstOrNull { content: GithubContent -> content.isFile && "stages.json" == content.name }

if (stages == null) {
log.info { "[ACTIVITIES-OPEN-STATUS]活动地图开放状态数据不存在" }
Expand All @@ -186,14 +187,12 @@ class ArkLevelService(
okHttpClient
.newCall(Request.Builder().url(stages.downloadUrl).build())
.execute().use { response ->
if (!response.isSuccessful || response.body == null) {
val body = response.body?.byteStream()
if (!response.isSuccessful || body == null) {
log.error { "[ACTIVITIES-OPEN-STATUS]活动地图开放状态下载失败" }
return
}
val body = response.body!!.byteStream()
val stagesList: List<MaaArkStage> =
mapper.readValue(body, object : TypeReference<List<MaaArkStage>>() {
})
val stagesList = mapper.readValue(body, object : TypeReference<List<MaaArkStage>>() {})

val keyInfos = stagesList
.map { it.stageId } // 提取地图系列的唯一标识
Expand All @@ -210,7 +209,7 @@ class ArkLevelService(
val nowTime = LocalDateTime.now()

while (arkLevelPage.hasContent()) {
arkLevelPage.forEach{ arkLevel: ArkLevel ->
arkLevelPage.forEach { arkLevel: ArkLevel ->
// 只考虑地图系列的唯一标识
if (keyInfos.contains(ArkLevelUtil.getKeyInfoById(arkLevel.stageId))) {
arkLevel.isOpen = true
Expand Down Expand Up @@ -335,7 +334,7 @@ class ArkLevelService(
private val fail: AtomicInteger = AtomicInteger(0),
private val pass: AtomicInteger = AtomicInteger(0),
val total: Int = 0,
private val finishCallback: ((DownloadTask) -> Unit)? = null
private val finishCallback: ((DownloadTask) -> Unit)
) {
fun success() {
success.incrementAndGet()
Expand Down Expand Up @@ -365,7 +364,7 @@ class ArkLevelService(
if (success.get() + fail.get() + pass.get() != total) {
return
}
finishCallback!!.invoke(this)
finishCallback.invoke(this)
log.info { "[LEVEL]地图数据下载完成, 成功:${success.get()}, 失败:${fail.get()}, 跳过:${pass.get()} 总用时${duration}s" }
}
}
Expand Down
Loading

0 comments on commit 1e71dd4

Please sign in to comment.