Clarify expired attachment errors in app
This commit is contained in:
1 parent
3db2077da3
commit
0a261af380
3 files changed
+24
-3
No files matched your search
@@ -224,22 +224,32 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
},
|
},
|
||||||
onOpenAttachment = { messageId ->
|
onOpenAttachment = { messageId ->
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
|
runCatching {
|
||||||
|
appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
|
||||||
|
}.onSuccess { payload ->
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
openAttachment(payload)
|
openAttachment(payload)
|
||||||
} else {
|
} else {
|
||||||
appState.feedbackMessage = "当前附件暂无可打开内容"
|
appState.feedbackMessage = "当前附件暂无可打开内容"
|
||||||
}
|
}
|
||||||
|
}.onFailure {
|
||||||
|
appState.feedbackMessage = it.message ?: "打开附件失败"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDownloadAttachment = { messageId ->
|
onDownloadAttachment = { messageId ->
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
|
runCatching {
|
||||||
|
appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId)
|
||||||
|
}.onSuccess { payload ->
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
saveAttachment(payload)
|
saveAttachment(payload)
|
||||||
} else {
|
} else {
|
||||||
appState.feedbackMessage = "当前附件暂无可下载内容"
|
appState.feedbackMessage = "当前附件暂无可下载内容"
|
||||||
}
|
}
|
||||||
|
}.onFailure {
|
||||||
|
appState.feedbackMessage = it.message ?: "下载附件失败"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+11
-1
@@ -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 {
|
||||||
|
client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") {
|
||||||
authHeader()
|
authHeader()
|
||||||
}.body()
|
}.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() {
|
||||||
|
|||||||
@@ -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 附件打开
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user