Skip to content

Commit c1f8bc7

Browse files
committed
Fix rest routes
1 parent 4eed057 commit c1f8bc7

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,19 @@ Body:
308308
```
309309

310310
Response:
311+
312+
If the YouTube source is not enabled, or the `refreshToken` is invalid:
313+
`500 - Internal Server Error`
314+
315+
Otherwise:
311316
`204 - No Content`
312317

313318
### `GET` `/youtube`
314319

315320
Response:
316321

317322
If the YouTube source is not enabled:
318-
`400 - Bad Request`
323+
`500 - Internal Server Error`
319324

320325
Otherwise:
321326
```json
@@ -324,8 +329,6 @@ Otherwise:
324329
}
325330
```
326331

327-
328-
329332
## Migration from Lavaplayer's built-in YouTube source
330333

331334
This client is intended as a direct replacement for Lavaplayer's built-in `YoutubeAudioSourceManager`,

plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ lavalinkPlugin {
1212
name = "youtube-plugin"
1313
path = "dev.lavalink.youtube.plugin"
1414
apiVersion = libs.versions.lavalink
15-
serverVersion = "4.0.4"
15+
serverVersion = "4.0.7"
1616
configurePublishing = false
1717
}
1818

plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
44
import dev.lavalink.youtube.YoutubeAudioSourceManager;
5+
import dev.lavalink.youtube.plugin.rest.MinimalConfigResponse;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import org.springframework.http.HttpStatus;
89
import org.springframework.stereotype.Service;
910
import org.springframework.web.bind.annotation.*;
1011
import org.springframework.web.server.ResponseStatusException;
1112

12-
import java.util.Collections;
13-
import java.util.Map;
14-
1513
@Service
1614
@RestController
1715
public class YoutubeRestHandler {
@@ -24,14 +22,14 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) {
2422
}
2523

2624
@GetMapping("/youtube")
27-
public Map<String, String> getYoutubeConfig() {
25+
public MinimalConfigResponse getYoutubeConfig() {
2826
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class);
2927

3028
if (source == null) {
3129
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The YouTube source manager is not registered.");
3230
}
3331

34-
return Collections.singletonMap("refreshToken", source.getOauth2RefreshToken());
32+
return MinimalConfigResponse.from(source);
3533
}
3634

3735
@PostMapping("/youtube")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dev.lavalink.youtube.plugin.rest;
2+
3+
import dev.lavalink.youtube.YoutubeAudioSourceManager;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
public class MinimalConfigResponse {
7+
@Nullable
8+
public String refreshToken;
9+
10+
private MinimalConfigResponse(@Nullable String refreshToken) {
11+
this.refreshToken = refreshToken;
12+
}
13+
14+
public static MinimalConfigResponse from(YoutubeAudioSourceManager sourceManager) {
15+
return new MinimalConfigResponse(sourceManager.getOauth2RefreshToken());
16+
}
17+
}

0 commit comments

Comments
 (0)