@@ -20,9 +20,20 @@ private fun File.readMicroBlogHistory(type: BlogUser): List<MicroBlog> {
20
20
}
21
21
22
22
private fun File.readMicroBlogPicture (type : BlogUser ): List <MicroBlog > {
23
- return read<Temp <PictureData >>(type).data().blogs.fold(mutableMapOf<Long , MicroBlog >()) { acc, new ->
24
- acc.apply { compute(new.id) { _, old -> old?.copy(pictures = old.pictures + new.pictures) ? : new } }
25
- }.values.map { it.copy(user = PictureUser ) }
23
+ val map = mutableMapOf<Long , MicroBlog >()
24
+ val epoch = 515483463L
25
+ // XXX
26
+ fun timestamp (id : Long ): Long = (id shr 22 ) + epoch
27
+
28
+ read<Temp <PictureData >>(type).data().blogs.forEach { new ->
29
+ map.compute(new.id) { _, old ->
30
+ old?.copy(pictures = old.pictures + new.pictures) ? : new
31
+ }
32
+ }
33
+
34
+ return map.values.map {
35
+ it.copy(created = OffsetDateTime .ofInstant(Instant .ofEpochSecond(timestamp(it.id)), it.created.offset))
36
+ }
26
37
}
27
38
28
39
private suspend fun getLongTextContent (id : Long ): String {
@@ -33,7 +44,7 @@ private suspend fun getLongTextContent(id: Long): String {
33
44
return content.replace(" <br />" , " \n " ).remove(SIGN )
34
45
}
35
46
36
- class MicroBlogData (override val dir : File ): GameDataDownloader {
47
+ class MicroBlogData (override val dir : File ) : GameDataDownloader {
37
48
val arknights get() = dir.readMicroBlogHistory(BlogUser .ARKNIGHTS )
38
49
val byproduct get() = dir.readMicroBlogHistory(BlogUser .BYPRODUCT )
39
50
val historicus get() = dir.readMicroBlogHistory(BlogUser .HISTORICUS )
@@ -78,7 +89,7 @@ val MicroBlog.images get() = pictures.map { image(pid = it) }
78
89
79
90
val MicroBlog .content get() = raw ? : text.replace(" <br />" , " \n " ).remove(SIGN )
80
91
81
- val MicroBlog .url get() = Url (" https://weibo.com/${user?.id ? : " detail" } /$bid " )
92
+ val MicroBlog .url get() = Url (" https://weibo.com/${user?.id ? : " detail" } /${ bid.ifBlank { id }} " )
82
93
83
94
suspend fun MicroBlog.content (): String = if (isLongText) getLongTextContent(id = id) else content
84
95
@@ -114,7 +125,7 @@ data class MicroBlog(
114
125
@SerialName(" id" )
115
126
val id : Long ,
116
127
@SerialName(" bid" )
117
- val bid : String ,
128
+ val bid : String = " " ,
118
129
@SerialName(" isLongText" )
119
130
val isLongText : Boolean = false ,
120
131
@SerialName(" pic_ids" )
@@ -165,13 +176,6 @@ data class LongTextContent(
165
176
val ok : Int ,
166
177
)
167
178
168
- private val PictureUser = MicroBlogUser (
169
- avatar = " " ,
170
- description = " " ,
171
- id = 0 ,
172
- name = " 此微博被锁定为热门,机器人无法获取详情,请打开链接自行查看"
173
- )
174
-
175
179
private val PictureData .blogs get() = cards.flatMap { it.group }.flatMap { it.pictures }.map { it.blog }
176
180
177
181
@Serializable
0 commit comments