[db] add support for detecting swap repos

Note that those are not really meant to be added to the DB as they are ephemeral by nature.
This commit is contained in:
Torsten Grote
2023-09-13 16:36:54 +02:00
committed by Michael Pöhn
parent f068d920bd
commit 7c0c9c2cae
3 changed files with 51 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package org.fdroid.index
import android.content.Context
import android.net.Uri
import androidx.annotation.AnyThread
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
@@ -20,6 +21,7 @@ import org.fdroid.download.DownloaderFactory
import org.fdroid.download.HttpManager
import org.fdroid.repo.AddRepoState
import org.fdroid.repo.RepoAdder
import org.fdroid.repo.RepoUriGetter
import java.io.File
import java.net.Proxy
import java.util.concurrent.CountDownLatch
@@ -155,4 +157,12 @@ public class RepoManager @JvmOverloads constructor(
repoAdder.abortAddingRepo()
}
/**
* Returns true if the given [uri] belongs to a swap repo.
*/
@UiThread
public fun isSwapUri(uri: Uri?): Boolean {
return uri != null && RepoUriGetter.isSwapUri(uri)
}
}

View File

@@ -21,6 +21,7 @@ internal object RepoUriGetter {
}
}
val fingerprint = uri.getQueryParameter("fingerprint")?.lowercase()
?: uri.getQueryParameter("FINGERPRINT")?.lowercase()
val pathSegments = uri.pathSegments
val normalizedUri = uri.buildUpon().apply {
@@ -53,6 +54,11 @@ internal object RepoUriGetter {
return NormalizedUri(normalizedUri, fingerprint)
}
fun isSwapUri(uri: Uri): Boolean {
val swap = uri.getQueryParameter("swap") ?: uri.getQueryParameter("SWAP")
return swap != null && uri.scheme?.lowercase() == "http"
}
private fun getFdroidLinkUri(uri: Uri): Uri {
val tmpUri = uri.buildUpon().encodedQuery(uri.encodedFragment).build()
return Uri.parse(tmpUri.getQueryParameter("repo"))