mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
fix: don't use dead fallback instances api anymore
This commit is contained in:
parent
916a91a861
commit
8edef3583c
@ -1,6 +1,6 @@
|
||||
package com.github.libretube.api
|
||||
|
||||
import com.github.libretube.api.obj.Instances
|
||||
import com.github.libretube.api.obj.PipedInstance
|
||||
import com.github.libretube.api.obj.SubmitSegmentResponse
|
||||
import com.github.libretube.obj.update.UpdateInfo
|
||||
import retrofit2.http.GET
|
||||
@ -14,7 +14,7 @@ private const val SB_API_URL = "https://sponsor.ajay.app"
|
||||
interface ExternalApi {
|
||||
// only for fetching servers list
|
||||
@GET
|
||||
suspend fun getInstances(@Url url: String): List<Instances>
|
||||
suspend fun getInstances(@Url url: String): List<PipedInstance>
|
||||
|
||||
// fetch latest version info
|
||||
@GET(GITHUB_API_URL)
|
||||
|
@ -2,34 +2,31 @@ package com.github.libretube.api
|
||||
|
||||
import android.content.Context
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.Instances
|
||||
import com.github.libretube.api.obj.PipedInstance
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
object InstanceHelper {
|
||||
private const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks"
|
||||
private const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz"
|
||||
|
||||
/**
|
||||
* fetch official public instances from kavin.rocks as well as tokhmi.xyz as fallback
|
||||
* Fetch official public instances from kavin.rocks
|
||||
*/
|
||||
suspend fun getInstances(context: Context): List<Instances> {
|
||||
suspend fun getInstances(context: Context): List<PipedInstance> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
RetrofitInstance.externalApi.getInstances(PIPED_INSTANCES_URL)
|
||||
}.getOrNull() ?: runCatching {
|
||||
RetrofitInstance.externalApi.getInstances(FALLBACK_INSTANCES_URL)
|
||||
}.getOrNull() ?: run {
|
||||
throw Exception(context.getString(R.string.failed_fetching_instances))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstancesFallback(context: Context): List<Instances> {
|
||||
fun getInstancesFallback(context: Context): List<PipedInstance> {
|
||||
val instanceNames = context.resources.getStringArray(R.array.instances)
|
||||
return context.resources.getStringArray(R.array.instancesValue)
|
||||
.mapIndexed { index, instanceValue ->
|
||||
Instances(instanceNames[index], instanceValue)
|
||||
PipedInstance(instanceNames[index], instanceValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Instances(
|
||||
data class PipedInstance(
|
||||
val name: String,
|
||||
@SerialName("api_url") val apiUrl: String,
|
||||
val locations: String = "",
|
||||
@ -16,5 +16,8 @@ data class Instances(
|
||||
@SerialName("cache") val chache: Boolean = false,
|
||||
@SerialName("s3_enabled") val s3Enabled: Boolean = false,
|
||||
@SerialName("image_proxy_url") val imageProxyUrl: String = "",
|
||||
@SerialName("registration_disabled") val registrationDisabled: Boolean = false
|
||||
@SerialName("registration_disabled") val registrationDisabled: Boolean = false,
|
||||
@SerialName("uptime_24h") val uptimeToday: Float = 0f,
|
||||
@SerialName("uptime_7d") val uptimeWeek: Float = 0f,
|
||||
@SerialName("uptime_30d") val uptimeMonth: Float = 0f
|
||||
)
|
@ -5,13 +5,13 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.Instances
|
||||
import com.github.libretube.api.obj.PipedInstance
|
||||
import com.github.libretube.databinding.InstanceRowBinding
|
||||
import com.github.libretube.ui.models.WelcomeModel
|
||||
import com.github.libretube.ui.viewholders.InstancesViewHolder
|
||||
|
||||
class InstancesAdapter(
|
||||
private val instances: List<Instances>,
|
||||
private val instances: List<PipedInstance>,
|
||||
viewModel: WelcomeModel,
|
||||
private val onSelectInstance: (index: Int) -> Unit
|
||||
) : RecyclerView.Adapter<InstancesViewHolder>() {
|
||||
|
@ -5,7 +5,7 @@ import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.github.libretube.api.InstanceHelper
|
||||
import com.github.libretube.api.obj.Instances
|
||||
import com.github.libretube.api.obj.PipedInstance
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -13,7 +13,7 @@ import kotlinx.coroutines.launch
|
||||
class WelcomeModel(private val application: Application) : AndroidViewModel(application) {
|
||||
val selectedInstanceIndex = MutableLiveData<Int>()
|
||||
|
||||
var instances = MutableLiveData<List<Instances>>()
|
||||
var instances = MutableLiveData<List<PipedInstance>>()
|
||||
|
||||
fun fetchInstances() {
|
||||
if (!instances.value.isNullOrEmpty()) return
|
||||
|
@ -10,7 +10,7 @@ import androidx.preference.SwitchPreferenceCompat
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.InstanceHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.Instances
|
||||
import com.github.libretube.api.obj.PipedInstance
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.db.DatabaseHolder.Database
|
||||
@ -135,14 +135,14 @@ class InstanceSettings : BasePreferenceFragment() {
|
||||
|
||||
private suspend fun initInstancesPref(
|
||||
instancePrefs: List<ListPreference>,
|
||||
publicInstances: List<Instances>
|
||||
publicInstances: List<PipedInstance>
|
||||
) = runCatching {
|
||||
val customInstanceList = withContext(Dispatchers.IO) {
|
||||
Database.customInstanceDao().getAll()
|
||||
}
|
||||
|
||||
val customInstances = customInstanceList
|
||||
.map { Instances(it.name, it.apiUrl) }
|
||||
.map { PipedInstance(it.name, it.apiUrl) }
|
||||
|
||||
val instances = publicInstances
|
||||
.plus(customInstances)
|
||||
|
Loading…
x
Reference in New Issue
Block a user