mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +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")
|
@GET("feed")
|
||||||
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>
|
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>
|
||||||
|
|
||||||
|
@GET("feed/unauthenticated")
|
||||||
|
suspend fun getUnauthenticatedFeed(
|
||||||
|
@Query("channels") channels: String
|
||||||
|
): List<StreamItem>
|
||||||
|
|
||||||
@POST("feed/unauthenticated")
|
@POST("feed/unauthenticated")
|
||||||
suspend fun getUnauthenticatedFeed(
|
suspend fun getUnauthenticatedFeed(
|
||||||
@Body channels: List<String>
|
@Body channels: List<String>
|
||||||
@ -122,6 +127,11 @@ interface PipedApi {
|
|||||||
@GET("subscriptions")
|
@GET("subscriptions")
|
||||||
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
||||||
|
|
||||||
|
@GET("subscriptions/unauthenticated")
|
||||||
|
suspend fun unauthenticatedSubscriptions(
|
||||||
|
@Query("channels") channels: String
|
||||||
|
): List<Subscription>
|
||||||
|
|
||||||
@POST("subscriptions/unauthenticated")
|
@POST("subscriptions/unauthenticated")
|
||||||
suspend fun unauthenticatedSubscriptions(
|
suspend fun unauthenticatedSubscriptions(
|
||||||
@Body channels: List<String>
|
@Body channels: List<String>
|
||||||
|
@ -17,6 +17,8 @@ import kotlinx.coroutines.runBlocking
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
object SubscriptionHelper {
|
object SubscriptionHelper {
|
||||||
|
private const val GET_SUBSCRIPTIONS_LIMIT = 100
|
||||||
|
|
||||||
suspend fun subscribe(channelId: String) {
|
suspend fun subscribe(channelId: String) {
|
||||||
val token = PreferenceHelper.getToken()
|
val token = PreferenceHelper.getToken()
|
||||||
if (token.isNotEmpty()) {
|
if (token.isNotEmpty()) {
|
||||||
@ -108,7 +110,14 @@ object SubscriptionHelper {
|
|||||||
RetrofitInstance.authApi.subscriptions(token)
|
RetrofitInstance.authApi.subscriptions(token)
|
||||||
} else {
|
} else {
|
||||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
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)
|
RetrofitInstance.authApi.getFeed(token)
|
||||||
} else {
|
} else {
|
||||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
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