Clarify expired attachment errors in app

This commit is contained in:
OpenClaw committed 2026-03-07 09:57:58 +08:00
1 parent 3db2077da3
commit 0a261af380
3 files changed
+34 -13

No files matched your search

@@ -224,21 +224,31 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
}, },
onOpenAttachment = { messageId -> onOpenAttachment = { messageId ->
coroutineScope.launch { coroutineScope.launch {
val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) runCatching {
if (payload != null) { appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
openAttachment(payload) }.onSuccess { payload ->
} else { if (payload != null) {
appState.feedbackMessage = "当前附件暂无可打开内容" openAttachment(payload)
} else {
appState.feedbackMessage = "当前附件暂无可打开内容"
}
}.onFailure {
appState.feedbackMessage = it.message ?: "打开附件失败"
} }
} }
}, },
onDownloadAttachment = { messageId -> onDownloadAttachment = { messageId ->
coroutineScope.launch { coroutineScope.launch {
val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) runCatching {
if (payload != null) { appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
saveAttachment(payload) }.onSuccess { payload ->
} else { if (payload != null) {
appState.feedbackMessage = "当前附件暂无可下载内容" saveAttachment(payload)
} else {
appState.feedbackMessage = "当前附件暂无可下载内容"
}
}.onFailure {
appState.feedbackMessage = it.message ?: "下载附件失败"
} }
} }
}, },
@@ -3,6 +3,7 @@ package cn.xiaobai.openclawapp.network
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.call.body import io.ktor.client.call.body
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.request.get import io.ktor.client.request.get
import io.ktor.client.request.header import io.ktor.client.request.header
import io.ktor.client.request.post import io.ktor.client.request.post
@@ -103,9 +104,18 @@ class MobileGatewayApi(
suspend fun readAttachment(sessionId: String, attachmentId: String): AttachmentReadResponseDto { suspend fun readAttachment(sessionId: String, attachmentId: String): AttachmentReadResponseDto {
val encodedId = sessionId.encodeURLPathPart() val encodedId = sessionId.encodeURLPathPart()
val encodedAttachmentId = attachmentId.encodeURLPathPart() val encodedAttachmentId = attachmentId.encodeURLPathPart()
return client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") { return try {
authHeader() client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") {
}.body() authHeader()
}.body()
} catch (e: ClientRequestException) {
val message = when (e.response.status.value) {
403 -> "该附件不属于当前会话"
404 -> "附件不存在或已过期"
else -> "读取附件失败(HTTP ${e.response.status.value})"
}
throw IllegalStateException(message, e)
}
} }
private fun io.ktor.client.request.HttpRequestBuilder.authHeader() { private fun io.ktor.client.request.HttpRequestBuilder.authHeader() {
+1
View File
@@ -196,6 +196,7 @@ Android/iOS App
- [x] 点击附件打开(Android,优先本地缓存;无缓存时经 BFF 回源读取) - [x] 点击附件打开(Android,优先本地缓存;无缓存时经 BFF 回源读取)
- [x] BFF 附件 overlay 落盘,重启后仍可读取最近附件 - [x] BFF 附件 overlay 落盘,重启后仍可读取最近附件
- [x] 下载附件(Android,系统另存为) - [x] 下载附件(Android,系统另存为)
- [x] 附件过期/越权读取在前端已有明确提示文案
- [ ] iOS / Web 剪贴板 - [ ] iOS / Web 剪贴板
- [ ] iOS / Web 附件打开 - [ ] iOS / Web 附件打开