mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Unauthenticated: Use GET when subs <= 100
This commit is contained in:
parent
1f2be76559
commit
67a951f39e
@ -108,6 +108,11 @@ interface PipedApi {
|
||||
@GET("feed")
|
||||
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>
|
||||
|
||||
@GET("feed/unauthenticated")
|
||||
suspend fun getUnauthenticatedFeed(
|
||||
@Query("channels") channels: String
|
||||
): List<StreamItem>
|
||||
|
||||
@POST("feed/unauthenticated")
|
||||
suspend fun getUnauthenticatedFeed(
|
||||
@Body channels: List<String>
|
||||
@ -122,6 +127,11 @@ interface PipedApi {
|
||||
@GET("subscriptions")
|
||||
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
||||
|
||||
@GET("subscriptions/unauthenticated")
|
||||
suspend fun unauthenticatedSubscriptions(
|
||||
@Query("channels") channels: String
|
||||
): List<Subscription>
|
||||
|
||||
@POST("subscriptions/unauthenticated")
|
||||
suspend fun unauthenticatedSubscriptions(
|
||||
@Body channels: List<String>
|
||||
|
@ -17,6 +17,8 @@ import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
object SubscriptionHelper {
|
||||
private const val GET_SUBSCRIPTIONS_LIMIT = 100
|
||||
|
||||
suspend fun subscribe(channelId: String) {
|
||||
val token = PreferenceHelper.getToken()
|
||||
if (token.isNotEmpty()) {
|
||||
@ -108,7 +110,14 @@ object SubscriptionHelper {
|
||||
RetrofitInstance.authApi.subscriptions(token)
|
||||
} else {
|
||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
||||
RetrofitInstance.authApi.unauthenticatedSubscriptions(subscriptions)
|
||||
when {
|
||||
subscriptions.size > GET_SUBSCRIPTIONS_LIMIT -> RetrofitInstance.authApi.unauthenticatedSubscriptions(
|
||||
subscriptions
|
||||
)
|
||||
else -> RetrofitInstance.authApi.unauthenticatedSubscriptions(
|
||||
subscriptions.joinToString(",")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +127,14 @@ object SubscriptionHelper {
|
||||
RetrofitInstance.authApi.getFeed(token)
|
||||
} else {
|
||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
||||
RetrofitInstance.authApi.getUnauthenticatedFeed(subscriptions)
|
||||
when {
|
||||
subscriptions.size > GET_SUBSCRIPTIONS_LIMIT -> RetrofitInstance.authApi.getUnauthenticatedFeed(
|
||||
subscriptions
|
||||
)
|
||||
else -> RetrofitInstance.authApi.getUnauthenticatedFeed(
|
||||
subscriptions.joinToString(",")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user