Skip to content

Commit 28a0303

Browse files
committed
feat(login): Optimize login history and FN Connect functionality
1 parent 1af4edf commit 28a0303

File tree

5 files changed

+667
-381
lines changed

5 files changed

+667
-381
lines changed

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/data/model/LoginHistory.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,32 @@ data class LoginHistory(
4747
if (this === other) return true
4848
if (other !is LoginHistory) return false
4949

50-
if (isFnConnect) {
51-
return isFnConnect == other.isFnConnect &&
52-
fnId == other.fnId &&
53-
username == other.username
50+
if (isFnConnect != other.isFnConnect) return false
51+
52+
return if (isFnConnect) {
53+
fnId == other.fnId && username == other.username
54+
} else {
55+
host == other.host &&
56+
port == other.port &&
57+
username == other.username
5458
}
55-
56-
return host == other.host &&
57-
port == other.port &&
58-
username == other.username
5959
}
6060

6161
override fun hashCode(): Int {
62-
var result = host.hashCode()
63-
result = 31 * result + port
62+
var result = isFnConnect.hashCode()
63+
if (isFnConnect) {
64+
result = 31 * result + fnId.hashCode()
65+
} else {
66+
result = 31 * result + host.hashCode()
67+
result = 31 * result + port
68+
}
6469
result = 31 * result + username.hashCode()
65-
result = 31 * result + isFnConnect.hashCode()
66-
result = 31 * result + fnId.hashCode()
6770
return result
6871
}
6972

7073
fun getEndpoint(): String {
7174
if (isFnConnect) {
72-
return if (fnId.isNotBlank()) "FN Connect: $fnId" else "FN Connect"
75+
return fnId.ifBlank { "FN Connect" }
7376
}
7477
return if (port != 0) {
7578
"$host:$port"

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/data/network/impl/FnOfficialApiImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ class FnOfficialApiImpl() : FnOfficialApi {
277277
throw IllegalArgumentException("飞牛官方URL未配置")
278278
}
279279
val authx = genAuthx(url, parameters)
280-
logger.i { "GET request, url: ${AccountDataCache.getFnOfficialBaseUrl()}$url, authx: $authx, parameters: $parameters" }
280+
logger.i { "GET request, url: ${AccountDataCache.getFnOfficialBaseUrl()}$url, authx: $authx, parameters: $parameters, cookie: ${AccountDataCache.cookieState}" }
281281
val response = fnOfficialClient.get("${AccountDataCache.getFnOfficialBaseUrl()}$url") {
282282
header("Authx", authx)
283+
// header(HttpHeaders.Cookie, AccountDataCache.cookieState)
283284
parameters?.forEach { (key, value) ->
284285
if (value != null) {
285286
parameter(key, value)

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/manager/PreferencesManager.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,29 @@ class PreferencesManager private constructor() {
120120
emptyList()
121121
}
122122
}
123-
}
123+
124+
fun loadLoginUsernameHistory(): List<String> {
125+
val usernamesJson = settings.getString("loginUsernameHistory", "[]")
126+
return try {
127+
mapper.readValue<List<String>>(usernamesJson)
128+
} catch (e: Exception) {
129+
emptyList()
130+
}
131+
}
132+
133+
fun saveLoginUsernameHistory(usernames: List<String>) {
134+
val usernamesJson = mapper.writeValueAsString(usernames)
135+
settings.putString("loginUsernameHistory", usernamesJson)
136+
}
137+
138+
fun addLoginUsernameHistory(username: String) {
139+
val normalized = username.trim()
140+
if (normalized.isBlank()) return
141+
142+
val existing = loadLoginUsernameHistory()
143+
val updated = (listOf(normalized) + existing)
144+
.distinctBy { it.trim().lowercase() }
145+
.take(20)
146+
saveLoginUsernameHistory(updated)
147+
}
148+
}

0 commit comments

Comments
 (0)