refact: [NETWORK] format on data part to be able to filter and search… (#288)

Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
Florent CHAMPIGNY 2025-10-02 14:32:56 +02:00 committed by GitHub
parent 8c6ce2e244
commit 08e58f60f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 4420 additions and 67 deletions

View file

@ -40,7 +40,7 @@ import io.github.openflocon.flocondesktop.common.db.converters.MapStringsConvert
import kotlinx.coroutines.Dispatchers
@Database(
version = 61,
version = 62,
entities = [
FloconNetworkCallEntity::class,
FileEntity::class,

View file

@ -6,35 +6,6 @@ import io.github.openflocon.domain.network.models.responseByteSizeFormatted
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkItemViewState
import io.ktor.http.Url
fun extractDomain(url: String): String {
// Parse l'URL en un objet Url
val parsedUrl = Url(url)
// Utilise host pour le domaine et encodedPathAndQuery pour le chemin
val domainAndPath = parsedUrl.host
// Le code ci-dessous pourrait aussi fonctionner, mais host est plus précis pour le domaine
// return parsedUrl.hostWithPort + parsedUrl.fullPath
return domainAndPath.removePrefix("www.")
}
fun extractDomainAndPath(url: String): String {
// Parse l'URL en un objet Url
val parsedUrl = Url(url)
// Utilise host pour le domaine et encodedPathAndQuery pour le chemin
val domainAndPath = parsedUrl.host + parsedUrl.encodedPathAndQuery
// Le code ci-dessous pourrait aussi fonctionner, mais host est plus précis pour le domaine
// return parsedUrl.hostWithPort + parsedUrl.fullPath
return domainAndPath.removePrefix("www.")
}
fun extractPath(url: String): String {
val parsedUrl = Url(url)
return parsedUrl.encodedPathAndQuery
}
fun toUi(
networkCall: FloconNetworkCallDomainModel,
deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel?
@ -45,7 +16,7 @@ fun toUi(
timeFormatted = networkCall.response?.durationFormatted,
requestSize = networkCall.request.byteSizeFormatted,
responseSize = networkCall.responseByteSizeFormatted(),
domain = getDomainUi(networkCall),
domain = networkCall.request.domainFormatted,
type = toTypeUi(networkCall),
method = getMethodUi(networkCall),
status = getStatusUi(networkCall),
@ -53,9 +24,3 @@ fun toUi(
isFromOldAppInstance = deviceIdAndPackageName?.appInstance?.let { it != networkCall.appInstance } ?: false
)
}
fun getDomainUi(networkRequest: FloconNetworkCallDomainModel): String = when (networkRequest.request.specificInfos) {
is FloconNetworkCallDomainModel.Request.SpecificInfos.GraphQl -> extractDomainAndPath(networkRequest.request.url)
is FloconNetworkCallDomainModel.Request.SpecificInfos.Http -> extractDomain(networkRequest.request.url)
is FloconNetworkCallDomainModel.Request.SpecificInfos.Grpc -> networkRequest.request.url
}

View file

@ -5,20 +5,18 @@ import io.github.openflocon.flocondesktop.features.network.list.model.NetworkIte
fun toTypeUi(call: FloconNetworkCallDomainModel): NetworkItemViewState.NetworkTypeUi = when (val s = call.request.specificInfos) {
is FloconNetworkCallDomainModel.Request.SpecificInfos.GraphQl -> NetworkItemViewState.NetworkTypeUi.GraphQl(
queryName = s.query,
queryName = call.request.queryFormatted,
)
is FloconNetworkCallDomainModel.Request.SpecificInfos.Http -> {
val query = extractPath(call.request.url)
NetworkItemViewState.NetworkTypeUi.Url(
query = query,
method = call.request.method,
query = call.request.queryFormatted,
)
}
is FloconNetworkCallDomainModel.Request.SpecificInfos.Grpc -> {
NetworkItemViewState.NetworkTypeUi.Grpc(
method = call.request.method,
method = call.request.queryFormatted,
)
}
}

View file

@ -32,7 +32,6 @@ data class NetworkItemViewState(
@Immutable
data class Url(
val method: String,
val query: String,
) : NetworkTypeUi {
override fun contains(text: String): Boolean = query.contains(text, ignoreCase = true)
@ -68,7 +67,6 @@ fun previewNetworkItemViewState(): NetworkItemViewState = NetworkItemViewState(
status = NetworkStatusUi("200", NetworkStatusUi.Status.SUCCESS),
type = NetworkItemViewState.NetworkTypeUi.Url(
query = "/search?q=test",
method = "get",
),
isMocked = false,
isFromOldAppInstance = false,