This commit is contained in:
_Bastler 2022-01-03 12:40:32 +01:00
parent d597700258
commit 2e4b48729d
3 changed files with 31 additions and 41 deletions

View File

@ -64,7 +64,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
* afterSingletonsInstantiated() * afterSingletonsInstantiated()
*/ */
/* /*
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() * @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated()
*/ */
/* /*
* @see org.springframework.beans.factory.SmartInitializingSingleton# * @see org.springframework.beans.factory.SmartInitializingSingleton#
@ -213,7 +214,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
disable = true; disable = true;
} else { } else {
JsonObject device = statusObject.getAsJsonObject("device"); JsonObject device = statusObject.getAsJsonObject("device");
if (!device.get("id").getAsString().equals(config.getDeviceId())) { if (!device.get("id").getAsString().equals(config.getDeviceId())
&& StringUtils.hasText(config.getDeviceId())) {
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>(); MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("device_id", config.getDeviceId()); queryParameters.add("device_id", config.getDeviceId());
request = webClient.method(HttpMethod.PUT) request = webClient.method(HttpMethod.PUT)

View File

@ -53,7 +53,7 @@ public class JukeboxController extends BaseController {
/** /**
* Check queue permission. * Check queue permission.
*/ */
protected void checkQueuePermission() { protected JsonElement checkQueuePermission() {
if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)) { if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)) {
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
} }
@ -62,7 +62,7 @@ public class JukeboxController extends BaseController {
throw new EntityResponseStatusException(HttpStatus.GONE); throw new EntityResponseStatusException(HttpStatus.GONE);
} }
jukeboxManager.getStatus(); JsonElement status = jukeboxManager.getStatus();
if (!jukeboxManager.getConfig().isActive()) { if (!jukeboxManager.getConfig().isActive()) {
throw new EntityResponseStatusException(HttpStatus.GONE); throw new EntityResponseStatusException(HttpStatus.GONE);
@ -74,6 +74,8 @@ public class JukeboxController extends BaseController {
Duration.between(queueList.get(getCurrentUserId()), Instant.now()).getSeconds(), Duration.between(queueList.get(getCurrentUserId()), Instant.now()).getSeconds(),
HttpStatus.PAYMENT_REQUIRED); HttpStatus.PAYMENT_REQUIRED);
} }
return status;
} }
/** /**
@ -104,8 +106,21 @@ public class JukeboxController extends BaseController {
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping @GetMapping
public void check() throws JsonIOException, IOException { public void check(HttpServletResponse response) throws JsonIOException, IOException {
checkQueuePermission(); JsonElement status = checkQueuePermission();
if (status != null) {
JsonObject statusObject = status.getAsJsonObject();
if (statusObject.has("item")) {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpStatus.OK.value());
gson.toJson(statusObject.getAsJsonObject("item"), response.getWriter());
return;
}
}
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
} }
/** /**
@ -142,33 +157,6 @@ public class JukeboxController extends BaseController {
queueList.put(getCurrentUserId(), Instant.now()); queueList.put(getCurrentUserId(), Instant.now());
} }
/**
* Current.
*
* @param response the response
* @throws JsonIOException the json IO exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("isAuthenticated()")
@GetMapping("/current")
public void current(HttpServletResponse response) throws JsonIOException, IOException {
checkSearchPermission();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JsonElement status = jukeboxManager.getStatus();
if (status != null) {
JsonObject statusObject = status.getAsJsonObject();
if (statusObject.has("item")) {
gson.toJson(statusObject.getAsJsonObject("item"), response.getWriter());
return;
}
}
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
}
/** /**
* Last. * Last.
* *

View File

@ -13,7 +13,7 @@
<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.17.1</log4j2.version> <log4j2.version>2.17.1</log4j2.version>
<revision>1.4.8-SNAPSHOT</revision> <revision>1.4.9-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>