jukebox update prev
This commit is contained in:
parent
3dbe244af1
commit
9022b59408
@ -56,6 +56,9 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
@ -200,11 +203,6 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
if (!statusObject.has("device")) {
|
||||
disable = true;
|
||||
}
|
||||
JsonObject device = statusObject.getAsJsonObject("device");
|
||||
if (!device.has("is_private_session")
|
||||
|| !device.get("is_private_session").getAsBoolean()) {
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
if (disable) {
|
||||
config.setActive(false);
|
||||
@ -255,6 +253,37 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last.
|
||||
*
|
||||
* @param limit the limit
|
||||
* @return the last
|
||||
*/
|
||||
public JsonElement getLast(Long limit) {
|
||||
if (!checkToken()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
if (limit != null) {
|
||||
queryParameters.add("limit", String.valueOf(limit));
|
||||
}
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/recently-played")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
|
||||
String jsonString = request.retrieve().bodyToMono(String.class)
|
||||
.onErrorResume(e -> Mono.just(e.getMessage())).block();
|
||||
|
||||
if (StringUtils.hasText(jsonString)) {
|
||||
return JsonParser.parseString(jsonString);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the to queue.
|
||||
*
|
||||
|
@ -93,14 +93,18 @@ public class JukeboxConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accountUrl
|
||||
* Gets the account url.
|
||||
*
|
||||
* @return the account url
|
||||
*/
|
||||
public String getAccountUrl() {
|
||||
return accountUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param accountUrl the accountUrl to set
|
||||
* Sets the account url.
|
||||
*
|
||||
* @param accountUrl the new account url
|
||||
*/
|
||||
public void setAccountUrl(String accountUrl) {
|
||||
this.accountUrl = accountUrl;
|
||||
|
@ -140,4 +140,22 @@ public class JukeboxController extends BaseController {
|
||||
queueList.put(getCurrentUserId(), Instant.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Last.
|
||||
*
|
||||
* @param limit the limit
|
||||
* @param response the response
|
||||
* @throws JsonIOException the json IO exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/last")
|
||||
public void last(@RequestParam("limit") Optional<Long> limit, HttpServletResponse response)
|
||||
throws JsonIOException, IOException {
|
||||
checkSearchPermission();
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
gson.toJson(jukeboxManager.getLast(limit.orElse(3L)), response.getWriter());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,10 +62,7 @@ public class JukeboxManagementController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the config.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the jukebox config
|
||||
* Sets the active.
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PutMapping
|
||||
@ -76,10 +73,7 @@ public class JukeboxManagementController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the config.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the jukebox config
|
||||
* Disable.
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping
|
||||
|
4
pom.xml
4
pom.xml
@ -12,8 +12,8 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
<log4j2.version>2.16.0</log4j2.version>
|
||||
<revision>1.4.6-SNAPSHOT</revision>
|
||||
<log4j2.version>2.17.1</log4j2.version>
|
||||
<revision>1.4.7-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
|
Loading…
Reference in New Issue
Block a user