From c1f8bc74d3eb978b76a60a26afd2c6e1b3fe68a2 Mon Sep 17 00:00:00 2001 From: Devoxin Date: Tue, 20 Aug 2024 14:05:13 +0100 Subject: [PATCH] Fix rest routes --- README.md | 9 ++++++--- plugin/build.gradle.kts | 2 +- .../youtube/plugin/YoutubeRestHandler.java | 8 +++----- .../plugin/rest/MinimalConfigResponse.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 plugin/src/main/java/dev/lavalink/youtube/plugin/rest/MinimalConfigResponse.java diff --git a/README.md b/README.md index 2019ad5..50da81f 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,11 @@ Body: ``` Response: + +If the YouTube source is not enabled, or the `refreshToken` is invalid: +`500 - Internal Server Error` + +Otherwise: `204 - No Content` ### `GET` `/youtube` @@ -315,7 +320,7 @@ Response: Response: If the YouTube source is not enabled: -`400 - Bad Request` +`500 - Internal Server Error` Otherwise: ```json @@ -324,8 +329,6 @@ Otherwise: } ``` - - ## Migration from Lavaplayer's built-in YouTube source This client is intended as a direct replacement for Lavaplayer's built-in `YoutubeAudioSourceManager`, diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 525e9a8..a93db8e 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -12,7 +12,7 @@ lavalinkPlugin { name = "youtube-plugin" path = "dev.lavalink.youtube.plugin" apiVersion = libs.versions.lavalink - serverVersion = "4.0.4" + serverVersion = "4.0.7" configurePublishing = false } diff --git a/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java b/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java index 3081ab9..37bc8b0 100644 --- a/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java +++ b/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java @@ -2,6 +2,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import dev.lavalink.youtube.YoutubeAudioSourceManager; +import dev.lavalink.youtube.plugin.rest.MinimalConfigResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -9,9 +10,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; -import java.util.Collections; -import java.util.Map; - @Service @RestController public class YoutubeRestHandler { @@ -24,14 +22,14 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) { } @GetMapping("/youtube") - public Map getYoutubeConfig() { + public MinimalConfigResponse getYoutubeConfig() { YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class); if (source == null) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The YouTube source manager is not registered."); } - return Collections.singletonMap("refreshToken", source.getOauth2RefreshToken()); + return MinimalConfigResponse.from(source); } @PostMapping("/youtube") diff --git a/plugin/src/main/java/dev/lavalink/youtube/plugin/rest/MinimalConfigResponse.java b/plugin/src/main/java/dev/lavalink/youtube/plugin/rest/MinimalConfigResponse.java new file mode 100644 index 0000000..df34b55 --- /dev/null +++ b/plugin/src/main/java/dev/lavalink/youtube/plugin/rest/MinimalConfigResponse.java @@ -0,0 +1,17 @@ +package dev.lavalink.youtube.plugin.rest; + +import dev.lavalink.youtube.YoutubeAudioSourceManager; +import org.jetbrains.annotations.Nullable; + +public class MinimalConfigResponse { + @Nullable + public String refreshToken; + + private MinimalConfigResponse(@Nullable String refreshToken) { + this.refreshToken = refreshToken; + } + + public static MinimalConfigResponse from(YoutubeAudioSourceManager sourceManager) { + return new MinimalConfigResponse(sourceManager.getOauth2RefreshToken()); + } +}