Fetch attachment bytes from BFF when opening
This commit is contained in:
1 parent
e55bd16253
commit
4260121f20
6 files changed
+36
-2
No files matched your search
@@ -219,12 +219,14 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||
copyToClipboard(fileName)
|
||||
},
|
||||
onOpenAttachment = { messageId ->
|
||||
val payload = appState.repository.attachmentOpenPayload(messageId)
|
||||
coroutineScope.launch {
|
||||
val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
|
||||
if (payload != null) {
|
||||
openAttachment(payload)
|
||||
} else {
|
||||
appState.feedbackMessage = "当前附件暂无可打开内容"
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ interface OpenClawRepository {
|
||||
)
|
||||
suspend fun retryAttachment(sessionId: String, messageId: String)
|
||||
fun attachmentOpenPayload(messageId: String): AttachmentOpenPayload?
|
||||
suspend fun ensureAttachmentOpenPayload(sessionId: String, messageId: String): AttachmentOpenPayload?
|
||||
}
|
||||
|
||||
data class AttachmentOpenPayload(
|
||||
|
||||
+13
@@ -8,6 +8,7 @@ import cn.xiaobai.openclawapp.network.SessionSummaryDto
|
||||
import cn.xiaobai.openclawapp.network.SessionStreamEvent
|
||||
import cn.xiaobai.openclawapp.network.SseSessionStream
|
||||
import cn.xiaobai.openclawapp.network.createDefaultHttpClient
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -82,6 +83,18 @@ class RemoteOpenClawRepository(
|
||||
|
||||
override fun attachmentOpenPayload(messageId: String): AttachmentOpenPayload? = attachmentOpenStore[messageId]
|
||||
|
||||
override suspend fun ensureAttachmentOpenPayload(sessionId: String, messageId: String): AttachmentOpenPayload? {
|
||||
attachmentOpenStore[messageId]?.let { return it }
|
||||
val remote = api.readAttachment(sessionId, messageId)
|
||||
val payload = AttachmentOpenPayload(
|
||||
fileName = remote.fileName,
|
||||
bytes = kotlin.io.encoding.Base64.decode(remote.base64Data),
|
||||
contentType = remote.contentType,
|
||||
)
|
||||
attachmentOpenStore[messageId] = payload
|
||||
return payload
|
||||
}
|
||||
|
||||
override fun markSessionOpened(sessionId: String) {
|
||||
recentSessionId = sessionId
|
||||
sessions = sessions.map {
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.http.encodeURLPathPart
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.io.bytestring.decodeBase64Bytes
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class MobileGatewayApi(
|
||||
@@ -99,6 +100,14 @@ class MobileGatewayApi(
|
||||
}.body()
|
||||
}
|
||||
|
||||
suspend fun readAttachment(sessionId: String, attachmentId: String): AttachmentReadResponseDto {
|
||||
val encodedId = sessionId.encodeURLPathPart()
|
||||
val encodedAttachmentId = attachmentId.encodeURLPathPart()
|
||||
return client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") {
|
||||
authHeader()
|
||||
}.body()
|
||||
}
|
||||
|
||||
private fun io.ktor.client.request.HttpRequestBuilder.authHeader() {
|
||||
val token = tokenProvider().trim()
|
||||
if (token.isNotBlank()) {
|
||||
|
||||
@@ -83,3 +83,12 @@ data class UploadAttachmentResponseDto(
|
||||
val sizeBytes: Int,
|
||||
val queuedAt: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class AttachmentReadResponseDto(
|
||||
val attachmentId: String,
|
||||
val fileName: String,
|
||||
val contentType: String? = null,
|
||||
val sizeBytes: Int,
|
||||
val base64Data: String,
|
||||
)
|
||||
@@ -193,7 +193,7 @@ Android/iOS App
|
||||
|
||||
- [x] 复制文件名(Android 真剪贴板)
|
||||
- [x] 查看附件详情
|
||||
- [x] 点击附件打开(Android,基于本地缓存文件)
|
||||
- [x] 点击附件打开(Android,优先本地缓存;无缓存时经 BFF 回源读取)
|
||||
- [ ] 下载附件
|
||||
- [ ] iOS / Web 剪贴板
|
||||
- [ ] iOS / Web 附件打开
|
||||
|
||||
Reference in new issue
Block a user