mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Use POST requests for unauthenticated subscriptions
This commit is contained in:
parent
459d8f92ac
commit
4bd2d473bf
@ -108,8 +108,10 @@ 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>
|
||||
): List<StreamItem>
|
||||
|
||||
@GET("subscribed")
|
||||
suspend fun isSubscribed(
|
||||
@ -120,8 +122,10 @@ 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>
|
||||
): List<Subscription>
|
||||
|
||||
@POST("subscribe")
|
||||
suspend fun subscribe(
|
||||
|
@ -102,17 +102,13 @@ object SubscriptionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getFormattedLocalSubscriptions(): String {
|
||||
return Database.localSubscriptionDao().getAll()
|
||||
.joinToString(",") { it.channelId }
|
||||
}
|
||||
|
||||
suspend fun getSubscriptions(): List<Subscription> {
|
||||
val token = PreferenceHelper.getToken()
|
||||
return if (token.isNotEmpty()) {
|
||||
RetrofitInstance.authApi.subscriptions(token)
|
||||
} else {
|
||||
RetrofitInstance.authApi.unauthenticatedSubscriptions(getFormattedLocalSubscriptions())
|
||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
||||
RetrofitInstance.authApi.unauthenticatedSubscriptions(subscriptions)
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +117,8 @@ object SubscriptionHelper {
|
||||
return if (token.isNotEmpty()) {
|
||||
RetrofitInstance.authApi.getFeed(token)
|
||||
} else {
|
||||
RetrofitInstance.authApi.getUnauthenticatedFeed(getFormattedLocalSubscriptions())
|
||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
||||
RetrofitInstance.authApi.getUnauthenticatedFeed(subscriptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.github.libretube.api.JsonHelper
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toastFromMainThread
|
||||
import com.github.libretube.obj.ImportPlaylist
|
||||
@ -83,6 +84,7 @@ class ImportHelper(
|
||||
/**
|
||||
* Write the text to the document
|
||||
*/
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
fun exportSubscriptions(uri: Uri?) {
|
||||
if (uri == null) return
|
||||
runBlocking(Dispatchers.IO) {
|
||||
@ -90,9 +92,8 @@ class ImportHelper(
|
||||
val subs = if (token.isNotEmpty()) {
|
||||
RetrofitInstance.authApi.subscriptions(token)
|
||||
} else {
|
||||
RetrofitInstance.authApi.unauthenticatedSubscriptions(
|
||||
SubscriptionHelper.getFormattedLocalSubscriptions()
|
||||
)
|
||||
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
|
||||
RetrofitInstance.authApi.unauthenticatedSubscriptions(subscriptions)
|
||||
}
|
||||
val newPipeChannels = subs.map {
|
||||
NewPipeSubscription(it.name, 0, "https://www.youtube.com${it.url}")
|
||||
|
@ -22,9 +22,9 @@ import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
import com.github.libretube.ui.views.TimePickerPreference
|
||||
import java.time.LocalTime
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.time.LocalTime
|
||||
|
||||
/**
|
||||
* The notification worker which checks for new streams in a certain frequency
|
||||
|
Loading…
Reference in New Issue
Block a user