Skip to content

Commit 8cadf23

Browse files
committed
fix: http server can not get old snapshot (#1185)
1 parent 24bb5e0 commit 8cadf23

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/src/main/kotlin/li/songe/gkd/util/SnapshotExt.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import kotlinx.coroutines.coroutineScope
99
import kotlinx.coroutines.delay
1010
import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.withContext
12+
import kotlinx.serialization.json.JsonArray
13+
import kotlinx.serialization.json.JsonObject
1214
import li.songe.gkd.a11y.TopActivity
1315
import li.songe.gkd.a11y.screenshot
1416
import li.songe.gkd.a11y.topActivityFlow
@@ -32,21 +34,25 @@ object SnapshotExt {
3234
return snapshotParentPath(id).resolve("${id}.min.json")
3335
}
3436

35-
suspend fun getMinSnapshot(id: Long): ComplexSnapshot {
37+
suspend fun getMinSnapshot(id: Long): JsonObject {
3638
val f = minSnapshotFile(id)
3739
if (!f.exists()) {
3840
val text = withContext(Dispatchers.IO) { snapshotFile(id).readText() }
39-
val snapshot = withContext(Dispatchers.Default) {
40-
json.decodeFromString<ComplexSnapshot>(text)
41+
val snapshotJson = withContext(Dispatchers.Default) {
42+
// #1185
43+
json.decodeFromString<JsonObject>(text)
4144
}
42-
val minSnapshot = snapshot.copy(nodes = emptyList())
45+
val minSnapshot = JsonObject(snapshotJson.toMutableMap().apply {
46+
this["nodes"] = JsonArray(emptyList())
47+
})
4348
withContext(Dispatchers.IO) {
4449
f.writeText(keepNullJson.encodeToString(minSnapshot))
4550
}
51+
return minSnapshot
4652
}
4753
val text = withContext(Dispatchers.IO) { f.readText() }
4854
return withContext(Dispatchers.Default) {
49-
json.decodeFromString<ComplexSnapshot>(text)
55+
json.decodeFromString<JsonObject>(text)
5056
}
5157
}
5258

0 commit comments

Comments
 (0)