-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeOauthConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.lavalink.youtube.plugin; | ||
|
||
public class YoutubeOauthConfig { | ||
private String refreshToken; | ||
|
||
public String getRefreshToken() { | ||
return refreshToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.lavalink.youtube.plugin; | ||
|
||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; | ||
import dev.lavalink.youtube.YoutubeAudioSourceManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
@Service | ||
public class YoutubeRestHandler { | ||
private static final Logger log = LoggerFactory.getLogger(YoutubeRestHandler.class); | ||
|
||
private final AudioPlayerManager playerManager; | ||
|
||
public YoutubeRestHandler(AudioPlayerManager playerManager) { | ||
this.playerManager = playerManager; | ||
} | ||
|
||
@GetMapping("/v4/youtube") | ||
public Map<String, String> 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()); | ||
} | ||
|
||
@PostMapping("/v4/youtube") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public void updateRefreshToken(@RequestBody YoutubeOauthConfig config) { | ||
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class); | ||
|
||
if (source == null) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The YouTube source manager is not registered."); | ||
} | ||
|
||
source.useOauth2(config.getRefreshToken()); | ||
log.debug("Updated YouTube OAuth2 refresh token to {}", config.getRefreshToken()); | ||
} | ||
} |