fix: 修复空字符串时 getBaseUrl 返回斜杠的问题
当保存的 base URL 为空字符串时,之前会返回 "/"。现在检查空字符串并直接返回空字符串,同时确保非空 URL 有正确的协议前缀。
This commit is contained in:
@@ -29,7 +29,17 @@ object HttpManager {
|
|||||||
fun getBaseUrl(context: Context): String {
|
fun getBaseUrl(context: Context): String {
|
||||||
val prefs = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE)
|
val prefs = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE)
|
||||||
val saved = prefs.getString(PREF_KEY_BASE_URL, "").orEmpty().trim()
|
val saved = prefs.getString(PREF_KEY_BASE_URL, "").orEmpty().trim()
|
||||||
return saved.trimEnd('/')
|
if (saved.isEmpty()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
val normalized = if (saved.startsWith("http://", ignoreCase = true) ||
|
||||||
|
saved.startsWith("https://", ignoreCase = true)
|
||||||
|
) {
|
||||||
|
saved
|
||||||
|
} else {
|
||||||
|
"http://$saved"
|
||||||
|
}
|
||||||
|
return normalized.trimEnd('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun login(context: Context): String? = withContext(Dispatchers.IO) {
|
suspend fun login(context: Context): String? = withContext(Dispatchers.IO) {
|
||||||
|
|||||||
Reference in New Issue
Block a user