From c92b331df93480f6d0f6e0ac7c4fb44888dbddd9 Mon Sep 17 00:00:00 2001 From: Eric85710 Date: Sun, 14 Jun 2026 15:34:47 +0800 Subject: [PATCH] dm-126 --- .../example/login_v3/data/di/NetworkModule.kt | 5 ++--- .../Message/UI/Detail/Message_Messaging.kt | 19 +++++++------------ .../{fullchain1.crt => technologia_root.crt} | 0 .../main/res/xml/network_security_config.xml | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) rename app/src/main/res/raw/{fullchain1.crt => technologia_root.crt} (100%) diff --git a/app/src/main/java/com/example/login_v3/data/di/NetworkModule.kt b/app/src/main/java/com/example/login_v3/data/di/NetworkModule.kt index 0cc5f86..92d5fc0 100644 --- a/app/src/main/java/com/example/login_v3/data/di/NetworkModule.kt +++ b/app/src/main/java/com/example/login_v3/data/di/NetworkModule.kt @@ -38,8 +38,6 @@ object NetworkModule { return OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS) - // 🟢 如果未來改用 HTTPS 且 IP 是 192.168.0.189 遇到憑證問題再開啟 - // .hostnameVerifier { hostname, _ -> hostname == "192.168.0.189" } .addInterceptor { chain -> // 在 OkHttp 的背景執行緒中安全地進行同步等待 val (token, userId) = runBlocking(Dispatchers.IO) { @@ -74,7 +72,8 @@ object NetworkModule { @Singleton fun provideRetrofit(moshi: Moshi, okHttpClient: OkHttpClient): Retrofit { return Retrofit.Builder() - .baseUrl("http://192.168.0.189/") // 確保與實際伺服器 IP 一致 + // 修正:更換為新的 HTTPS 正式網域 + .baseUrl("https://tg.technologia-tw.com/") .client(okHttpClient) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build() diff --git a/app/src/main/java/com/example/login_v3/home/Message/UI/Detail/Message_Messaging.kt b/app/src/main/java/com/example/login_v3/home/Message/UI/Detail/Message_Messaging.kt index 273fb44..ef73b43 100644 --- a/app/src/main/java/com/example/login_v3/home/Message/UI/Detail/Message_Messaging.kt +++ b/app/src/main/java/com/example/login_v3/home/Message/UI/Detail/Message_Messaging.kt @@ -512,14 +512,15 @@ fun MessageRow( val isAttachmentImage = message.attachment?.mimeType?.startsWith("image/") == true val contentLowerCase = (message.content ?: "").lowercase() val imageExtensions = listOf(".jpg", ".jpeg", ".png", ".webp", ".heic", ".heif") - val isLegacyImage = contentLowerCase.startsWith("http") && imageExtensions.any { contentLowerCase.contains(it) } + + // 修正:只要字串包含圖片副檔名,就認定它是舊版圖片路徑(拿掉 startsWith("http") 的限制) + val isLegacyImage = imageExtensions.any { contentLowerCase.contains(it) } val isImage = isAttachmentImage || isLegacyImage val rawContent = message.content ?: "" - // 💡 核心修正:利用 remember 根據 message 狀態動態計算正確的圖片 URL + val finalImageModel = remember(message) { - // 1. 取得原始路徑(優先使用 attachment 的 filename,次之用 content) val rawPath = if (isAttachmentImage && !message.attachment?.filename.isNullOrBlank()) { message.attachment!!.filename } else { @@ -528,17 +529,12 @@ fun MessageRow( when { rawPath.isBlank() -> "" - // 如果後端已經貼心地給了完整網址(包含 http 或 https),就直接使用 rawPath.startsWith("http") -> rawPath - // 如果後端給的路徑已經包含 "/uploads/"(例如 "/uploads/attachment/dfec7f...jpg") - rawPath.startsWith("/uploads/") -> "https://192.168.0.217$rawPath" - rawPath.contains("uploads/") -> "https://192.168.0.217/$rawPath" - - // 💡 關鍵處理:如果後端只給了純檔名(例如 "dfec7f...jpg")或是 "attachment/dfec7f...jpg" - // 我們要在前方幫它手動補上標準的存放路徑 "/uploads/" else -> { - val cleanPath = rawPath.removePrefix("/") // 移除可能重複的開頭斜線 + // 統一先把開頭的 "/" 或 "uploads/" 乾淨地剝離,再統一重新組合 + val cleanPath = rawPath.removePrefix("/").removePrefix("uploads/") + if (cleanPath.startsWith("attachment/")) { "https://192.168.0.217/uploads/$cleanPath" } else { @@ -550,7 +546,6 @@ fun MessageRow( - val finalBubbleColor = remember(message.status, isHighlight) { val baseColor = when { isMe && isHighlight -> Color(0xFFB4E197) diff --git a/app/src/main/res/raw/fullchain1.crt b/app/src/main/res/raw/technologia_root.crt similarity index 100% rename from app/src/main/res/raw/fullchain1.crt rename to app/src/main/res/raw/technologia_root.crt diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml index 8d00865..9eb83ec 100644 --- a/app/src/main/res/xml/network_security_config.xml +++ b/app/src/main/res/xml/network_security_config.xml @@ -1,9 +1,9 @@ - + - + \ No newline at end of file