jukebox update prev

This commit is contained in:
_Bastler 2022-01-02 11:31:27 +01:00
parent 3dbe244af1
commit 9022b59408
5 changed files with 71 additions and 26 deletions

View File

@ -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);
@ -225,7 +223,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
/**
* Search track.
*
* @param query the query
* @param query the query
* @param offset the offset
* @return the json element
*/
@ -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.
*

View File

@ -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;

View File

@ -98,7 +98,7 @@ public class JukeboxController extends BaseController {
* Check.
*
* @throws JsonIOException the json IO exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("isAuthenticated()")
@GetMapping
@ -109,11 +109,11 @@ public class JukeboxController extends BaseController {
/**
* Search.
*
* @param query the query
* @param offset the offset
* @param query the query
* @param offset the offset
* @param response the response
* @throws JsonIOException the json IO exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("isAuthenticated()")
@GetMapping("/search")
@ -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());
}
}

View File

@ -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
@ -95,7 +89,7 @@ public class JukeboxManagementController extends BaseController {
* @param response the response
* @return the status
* @throws JsonIOException the json IO exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping()
@ -108,11 +102,11 @@ public class JukeboxManagementController extends BaseController {
/**
* Search.
*
* @param query the query
* @param offset the offset
* @param query the query
* @param offset the offset
* @param response the response
* @throws JsonIOException the json IO exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/search")

View File

@ -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>