From 4bd2d473bfc21bd67eea0e2ca44f504ee0c4b000 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 4 Feb 2023 11:16:55 +0100 Subject: [PATCH] Use POST requests for unauthenticated subscriptions --- .../main/java/com/github/libretube/api/PipedApi.kt | 12 ++++++++---- .../com/github/libretube/api/SubscriptionHelper.kt | 11 ++++------- .../com/github/libretube/helpers/ImportHelper.kt | 7 ++++--- .../github/libretube/workers/NotificationWorker.kt | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/PipedApi.kt b/app/src/main/java/com/github/libretube/api/PipedApi.kt index 98e032389..809fdc6ce 100644 --- a/app/src/main/java/com/github/libretube/api/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/api/PipedApi.kt @@ -108,8 +108,10 @@ interface PipedApi { @GET("feed") suspend fun getFeed(@Query("authToken") token: String?): List - @GET("feed/unauthenticated") - suspend fun getUnauthenticatedFeed(@Query("channels") channels: String): List + @POST("feed/unauthenticated") + suspend fun getUnauthenticatedFeed( + @Body channels: List + ): List @GET("subscribed") suspend fun isSubscribed( @@ -120,8 +122,10 @@ interface PipedApi { @GET("subscriptions") suspend fun subscriptions(@Header("Authorization") token: String): List - @GET("subscriptions/unauthenticated") - suspend fun unauthenticatedSubscriptions(@Query("channels") channels: String): List + @POST("subscriptions/unauthenticated") + suspend fun unauthenticatedSubscriptions( + @Body channels: List + ): List @POST("subscribe") suspend fun subscribe( diff --git a/app/src/main/java/com/github/libretube/api/SubscriptionHelper.kt b/app/src/main/java/com/github/libretube/api/SubscriptionHelper.kt index e2d45fe49..f2b1f0491 100644 --- a/app/src/main/java/com/github/libretube/api/SubscriptionHelper.kt +++ b/app/src/main/java/com/github/libretube/api/SubscriptionHelper.kt @@ -102,17 +102,13 @@ object SubscriptionHelper { } } - suspend fun getFormattedLocalSubscriptions(): String { - return Database.localSubscriptionDao().getAll() - .joinToString(",") { it.channelId } - } - suspend fun getSubscriptions(): List { 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) } } } diff --git a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt index 5ad42edef..c61b70dab 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt @@ -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}") diff --git a/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt b/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt index 2c526c108..004f20e6d 100644 --- a/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt +++ b/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt @@ -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