jukebox
This commit is contained in:
parent
d597700258
commit
2e4b48729d
@ -64,7 +64,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
@ -213,7 +214,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
disable = true;
|
||||
} else {
|
||||
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>();
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
request = webClient.method(HttpMethod.PUT)
|
||||
@ -245,7 +247,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
/**
|
||||
* Search track.
|
||||
*
|
||||
* @param query the query
|
||||
* @param query the query
|
||||
* @param offset the offset
|
||||
* @return the json element
|
||||
*/
|
||||
|
@ -53,7 +53,7 @@ public class JukeboxController extends BaseController {
|
||||
/**
|
||||
* Check queue permission.
|
||||
*/
|
||||
protected void checkQueuePermission() {
|
||||
protected JsonElement checkQueuePermission() {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class JukeboxController extends BaseController {
|
||||
throw new EntityResponseStatusException(HttpStatus.GONE);
|
||||
}
|
||||
|
||||
jukeboxManager.getStatus();
|
||||
JsonElement status = jukeboxManager.getStatus();
|
||||
|
||||
if (!jukeboxManager.getConfig().isActive()) {
|
||||
throw new EntityResponseStatusException(HttpStatus.GONE);
|
||||
@ -74,6 +74,8 @@ public class JukeboxController extends BaseController {
|
||||
Duration.between(queueList.get(getCurrentUserId()), Instant.now()).getSeconds(),
|
||||
HttpStatus.PAYMENT_REQUIRED);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,22 +102,35 @@ 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
|
||||
public void check() throws JsonIOException, IOException {
|
||||
checkQueuePermission();
|
||||
public void check(HttpServletResponse response) throws JsonIOException, IOException {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
@ -142,40 +157,13 @@ public class JukeboxController extends BaseController {
|
||||
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.
|
||||
*
|
||||
* @param limit the limit
|
||||
* @param limit the limit
|
||||
* @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("/last")
|
||||
|
Loading…
Reference in New Issue
Block a user