Skip to content

Commit

Permalink
Fix #1161 无权限访问的条目显示为了错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Nov 10, 2024
1 parent 190029d commit 8dc50b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class AbstractBangumiBatchGraphQLExecutor {

data class BangumiGraphQLResponse(
val data: List<JsonObject?>,
val errors: String,
val errors: String?,
)

fun IntSet.toIntArray(): IntArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ query BatchGetSubjectQuery(${'$'}id: Int!) {
return try {
BangumiGraphQLResponse(
processResponse(resp),
errors = resp["errors"].toString(),
errors = resp["errors"]?.toString(),
)
} catch (e: Exception) {
throw IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,38 @@ class RemoteBangumiSubjectService(
// 解析条目详情
response.mapIndexed { index, element ->
if (element == null) { // error
val subjectId = ids[index]
BatchSubjectDetails(
SubjectInfo.Empty.copy(
subjectId = subjectId, subjectType = SubjectType.ANIME,
nameCn = "<$subjectId 错误>",
name = "<$subjectId 错误>",
summary = errors,
),
LightSubjectRelations(
emptyList(),
emptyList(),
),
)
if (errors == null) {
// 没有错误, 说明这个条目是没权限获取
val subjectId = ids[index]
BatchSubjectDetails(
SubjectInfo.Empty.copy(
subjectId = subjectId,
subjectType = SubjectType.ANIME,
nameCn = "此条目已被隐藏 $subjectId",
name = "此条目已被隐藏 $subjectId",
summary = "此条目已被隐藏, 请尝试登录后再次尝试. 如已登录, 请等待注册时间满四个月后再看.",
nsfw = true,
),
LightSubjectRelations(
emptyList(),
emptyList(),
),
)
} else {
val subjectId = ids[index]
BatchSubjectDetails(
SubjectInfo.Empty.copy(
subjectId = subjectId, subjectType = SubjectType.ANIME,
nameCn = "<$subjectId 错误>",
name = "<$subjectId 错误>",
summary = errors,
),
LightSubjectRelations(
emptyList(),
emptyList(),
),
)
}
} else {
BangumiSubjectGraphQLParser.parseBatchSubjectDetails(element)
}
Expand Down

0 comments on commit 8dc50b8

Please sign in to comment.