Skip to content

Commit

Permalink
Fix rest routes
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Aug 20, 2024
1 parent 4eed057 commit c1f8bc7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,19 @@ Body:
```

Response:

If the YouTube source is not enabled, or the `refreshToken` is invalid:
`500 - Internal Server Error`

Otherwise:
`204 - No Content`

### `GET` `/youtube`

Response:

If the YouTube source is not enabled:
`400 - Bad Request`
`500 - Internal Server Error`

Otherwise:
```json
Expand All @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

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;
import org.springframework.stereotype.Service;
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 {
Expand All @@ -24,14 +22,14 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) {
}

@GetMapping("/youtube")
public Map<String, String> 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit c1f8bc7

Please sign in to comment.