jukebox update prev

This commit is contained in:
2022-01-02 11:31:27 +01:00
parent 3dbe244af1
commit 9022b59408
5 changed files with 71 additions and 26 deletions
@@ -56,6 +56,9 @@ public class JukeboxManager implements SmartInitializingSingleton {
* @see org.springframework.beans.factory.SmartInitializingSingleton# * @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated() * afterSingletonsInstantiated()
*/ */
/*
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
*/
/* /*
* @see org.springframework.beans.factory.SmartInitializingSingleton# * @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated() * afterSingletonsInstantiated()
@@ -200,11 +203,6 @@ public class JukeboxManager implements SmartInitializingSingleton {
if (!statusObject.has("device")) { if (!statusObject.has("device")) {
disable = true; disable = true;
} }
JsonObject device = statusObject.getAsJsonObject("device");
if (!device.has("is_private_session")
|| !device.get("is_private_session").getAsBoolean()) {
disable = true;
}
} }
if (disable) { if (disable) {
config.setActive(false); config.setActive(false);
@@ -255,6 +253,37 @@ public class JukeboxManager implements SmartInitializingSingleton {
return null; 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. * 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() { public String getAccountUrl() {
return accountUrl; return accountUrl;
} }
/** /**
* @param accountUrl the accountUrl to set * Sets the account url.
*
* @param accountUrl the new account url
*/ */
public void setAccountUrl(String accountUrl) { public void setAccountUrl(String accountUrl) {
this.accountUrl = accountUrl; this.accountUrl = accountUrl;
@@ -140,4 +140,22 @@ public class JukeboxController extends BaseController {
queueList.put(getCurrentUserId(), Instant.now()); 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. * Sets the active.
*
* @param config the config
* @return the jukebox config
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@PutMapping @PutMapping
@@ -76,10 +73,7 @@ public class JukeboxManagementController extends BaseController {
} }
/** /**
* Sets the config. * Disable.
*
* @param config the config
* @return the jukebox config
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@DeleteMapping @DeleteMapping
+2 -2
View File
@@ -12,8 +12,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>
<log4j2.version>2.16.0</log4j2.version> <log4j2.version>2.17.1</log4j2.version>
<revision>1.4.6-SNAPSHOT</revision> <revision>1.4.7-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>