修复 QQVersionList Rainbow 源#156
Merged
Merged
Conversation
Contributor
评审者指南(在小型 PR 上折叠)评审者指南更新了 Rainbow QQ 版本列表的来源 URL,并将脆弱的字符串拆分解析器替换为健壮的基于 JSON 的实现,同时刷新了 Kuikly 图标矢量资源的尺寸和路径数据。 更新后的 Rainbow QQ 版本列表获取与 JSON 解析时序图sequenceDiagram
participant MainActivity
participant OkHttpClient
participant Request
participant Response
participant VersionUtil
participant Gson
participant KotlinJson
MainActivity->>OkHttpClient: OkHttpClient()
MainActivity->>Request: Request.Builder().url("https://cdn-go.cn/qq-web/im.qq.com_new/latest/rainbow/androidNewVersion.js").build()
MainActivity->>OkHttpClient: newCall(request)
OkHttpClient-->>MainActivity: Call
MainActivity->>OkHttpClient: execute()
OkHttpClient-->>MainActivity: Response
MainActivity->>Response: body
Response-->>MainActivity: ResponseBody
MainActivity->>Response: string()
Response-->>MainActivity: responseData
MainActivity->>VersionUtil: resolveQQRainbow(viewModel, responseData)
activate VersionUtil
VersionUtil->>Gson: fromJson(totalJson, JsonObject::class.java)
Gson-->>VersionUtil: JsonObject
VersionUtil->>JsonObject: getAsJsonArray(versions64)
JsonObject-->>VersionUtil: JsonArray
loop for each json in JsonArray
VersionUtil->>KotlinJson: decodeFromString<QQVersionBean>(json.toString())
KotlinJson-->>VersionUtil: QQVersionBean
Note right of VersionUtil: Set QQVersionBean.jsonString = json.toString()
end
deactivate VersionUtil
文件级变更
提示与命令与 Sourcery 交互
自定义你的使用体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates the Rainbow QQ version list source URL and replaces the brittle string-splitting parser with a robust JSON-based implementation, plus refreshes the Kuikly icon vector asset sizing and path data. Sequence diagram for updated Rainbow QQ version list fetching and JSON parsingsequenceDiagram
participant MainActivity
participant OkHttpClient
participant Request
participant Response
participant VersionUtil
participant Gson
participant KotlinJson
MainActivity->>OkHttpClient: OkHttpClient()
MainActivity->>Request: Request.Builder().url("https://cdn-go.cn/qq-web/im.qq.com_new/latest/rainbow/androidNewVersion.js").build()
MainActivity->>OkHttpClient: newCall(request)
OkHttpClient-->>MainActivity: Call
MainActivity->>OkHttpClient: execute()
OkHttpClient-->>MainActivity: Response
MainActivity->>Response: body
Response-->>MainActivity: ResponseBody
MainActivity->>Response: string()
Response-->>MainActivity: responseData
MainActivity->>VersionUtil: resolveQQRainbow(viewModel, responseData)
activate VersionUtil
VersionUtil->>Gson: fromJson(totalJson, JsonObject::class.java)
Gson-->>VersionUtil: JsonObject
VersionUtil->>JsonObject: getAsJsonArray(versions64)
JsonObject-->>VersionUtil: JsonArray
loop for each json in JsonArray
VersionUtil->>KotlinJson: decodeFromString<QQVersionBean>(json.toString())
KotlinJson-->>VersionUtil: QQVersionBean
Note right of VersionUtil: Set QQVersionBean.jsonString = json.toString()
end
deactivate VersionUtil
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - 我发现了两个问题,并给出了一些高层面的反馈:
- 在
resolveQQRainbow中,建议在调用substring之前,对start/end索引做一下健全性检查(例如当indexOf返回 -1 时),这样即使 Rainbow 返回数据格式异常或发生变更,也不会导致崩溃。 - 你在每次调用
resolveQQRainbow时都会新建一个Gson和KotlinJson实例;如果这个方法被频繁调用,建议把它们移动到可复用的单例/伴生对象属性中,以避免重复分配。
给 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- In `resolveQQRainbow`, consider adding a sanity check for `start`/`end` indices (e.g., when `indexOf` returns -1) before calling `substring`, so a malformed or changed Rainbow response doesn’t cause a crash.
- You construct a new `Gson` and `KotlinJson` instance on every `resolveQQRainbow` call; if this method is invoked frequently, consider moving these to reusable singletons/companion properties to avoid repeated allocations.
## Individual Comments
### Comment 1
<location path="app/src/main/java/com/xiaoniu/qqversionlist/util/VersionUtil.kt" line_range="53" />
<code_context>
fun resolveQQRainbow(viewModel: MainActivityViewModel, responseData: String) {
- val start = (responseData.indexOf("versions64\":[")) + 12
+ val start = (responseData.indexOf("{\"versions64\":["))
val end = (responseData.indexOf(";\n" + " typeof"))
val totalJson = responseData.substring(start, end)
- var qqVersion: List<QQVersionBean> = mutableListOf<QQVersionBean>()
</code_context>
<issue_to_address>
**issue (bug_risk):** The new JS endpoint might not preserve the exact `";\n typeof"` delimiter, which could break parsing.
If the new CDN script is minified or its whitespace/newlines differ, `indexOf(";\n" + " typeof")` may return `-1`, making `substring(start, end)` throw. Consider using a more robust delimiter (e.g., look for a structural marker like the closing `}` before `typeof`, or parse via regex/JSON) and at minimum guard against `end == -1` to avoid crashes.
</issue_to_address>
### Comment 2
<location path="app/src/main/java/com/xiaoniu/qqversionlist/util/VersionUtil.kt" line_range="58" />
<code_context>
+ val totalObject = Gson().fromJson(totalJson, JsonObject::class.java)
+ val jsonParser = KotlinJson { ignoreUnknownKeys = true }
+ val qqVersion: List<QQVersionBean> = totalObject.getAsJsonArray("versions64").reversed().map { json ->
val qqVersionInstall = DataStoreUtil.getStringKV("QQVersionInstall", "")
- KotlinJson.decodeFromString<QQVersionBean>(json).apply {
- jsonString = json
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid repeated DataStore lookups inside the `map` loop.
`DataStoreUtil.getStringKV("QQVersionInstall", "")` is called for every item in `versions64`, even though the value is constant. Read it once before the `map { ... }` and store it in a local `val` to avoid repeated I/O/overhead.
Suggested implementation:
```
val totalObject = Gson().fromJson(totalJson, JsonObject::class.java)
val jsonParser = KotlinJson { ignoreUnknownKeys = true }
val qqVersionInstall = DataStoreUtil.getStringKV("QQVersionInstall", "")
val qqVersion: List<QQVersionBean> = totalObject.getAsJsonArray("versions64").reversed().map { json ->
jsonParser.decodeFromString<QQVersionBean>(json.toString()).apply {
```
```
jsonString = json.toString()
// 标记本机 Android QQ 版本
this.apply {
// use qqVersionInstall here as needed
```
1. Ensure any logic that previously used the locally-defined `qqVersionInstall` inside the `map` still references the new outer-scoped `qqVersionInstall` variable.
2. If `displayInstall` or other properties depend on `qqVersionInstall`, keep that logic unchanged other than relying on the moved variable.
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- In
resolveQQRainbow, consider adding a sanity check forstart/endindices (e.g., whenindexOfreturns -1) before callingsubstring, so a malformed or changed Rainbow response doesn’t cause a crash. - You construct a new
GsonandKotlinJsoninstance on everyresolveQQRainbowcall; if this method is invoked frequently, consider moving these to reusable singletons/companion properties to avoid repeated allocations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `resolveQQRainbow`, consider adding a sanity check for `start`/`end` indices (e.g., when `indexOf` returns -1) before calling `substring`, so a malformed or changed Rainbow response doesn’t cause a crash.
- You construct a new `Gson` and `KotlinJson` instance on every `resolveQQRainbow` call; if this method is invoked frequently, consider moving these to reusable singletons/companion properties to avoid repeated allocations.
## Individual Comments
### Comment 1
<location path="app/src/main/java/com/xiaoniu/qqversionlist/util/VersionUtil.kt" line_range="53" />
<code_context>
fun resolveQQRainbow(viewModel: MainActivityViewModel, responseData: String) {
- val start = (responseData.indexOf("versions64\":[")) + 12
+ val start = (responseData.indexOf("{\"versions64\":["))
val end = (responseData.indexOf(";\n" + " typeof"))
val totalJson = responseData.substring(start, end)
- var qqVersion: List<QQVersionBean> = mutableListOf<QQVersionBean>()
</code_context>
<issue_to_address>
**issue (bug_risk):** The new JS endpoint might not preserve the exact `";\n typeof"` delimiter, which could break parsing.
If the new CDN script is minified or its whitespace/newlines differ, `indexOf(";\n" + " typeof")` may return `-1`, making `substring(start, end)` throw. Consider using a more robust delimiter (e.g., look for a structural marker like the closing `}` before `typeof`, or parse via regex/JSON) and at minimum guard against `end == -1` to avoid crashes.
</issue_to_address>
### Comment 2
<location path="app/src/main/java/com/xiaoniu/qqversionlist/util/VersionUtil.kt" line_range="58" />
<code_context>
+ val totalObject = Gson().fromJson(totalJson, JsonObject::class.java)
+ val jsonParser = KotlinJson { ignoreUnknownKeys = true }
+ val qqVersion: List<QQVersionBean> = totalObject.getAsJsonArray("versions64").reversed().map { json ->
val qqVersionInstall = DataStoreUtil.getStringKV("QQVersionInstall", "")
- KotlinJson.decodeFromString<QQVersionBean>(json).apply {
- jsonString = json
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid repeated DataStore lookups inside the `map` loop.
`DataStoreUtil.getStringKV("QQVersionInstall", "")` is called for every item in `versions64`, even though the value is constant. Read it once before the `map { ... }` and store it in a local `val` to avoid repeated I/O/overhead.
Suggested implementation:
```
val totalObject = Gson().fromJson(totalJson, JsonObject::class.java)
val jsonParser = KotlinJson { ignoreUnknownKeys = true }
val qqVersionInstall = DataStoreUtil.getStringKV("QQVersionInstall", "")
val qqVersion: List<QQVersionBean> = totalObject.getAsJsonArray("versions64").reversed().map { json ->
jsonParser.decodeFromString<QQVersionBean>(json.toString()).apply {
```
```
jsonString = json.toString()
// 标记本机 Android QQ 版本
this.apply {
// use qqVersionInstall here as needed
```
1. Ensure any logic that previously used the locally-defined `qqVersionInstall` inside the `map` still references the new outer-scoped `qqVersionInstall` variable.
2. If `displayInstall` or other properties depend on `qqVersionInstall`, keep that logic unchanged other than relying on the moved variable.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 解决了什么问题?
更新日志
修复
优化
自检清单
Summary by Sourcery
更新 QQ Rainbow 版本来源端点,并刷新 Kuikly 官方图标资源。
Bug 修复:
改进:
Original summary in English
Summary by Sourcery
Update the QQ Rainbow version source endpoint and refresh the Kuikly official icon asset.
Bug Fixes:
Enhancements: