use of org.libresonic.player.domain.TransferStatus in project libresonic by Libresonic.
the class StatusServiceTestCase method testSimpleAddRemove.
public void testSimpleAddRemove() {
TransferStatus status = service.createStreamStatus(player1);
assertTrue("Wrong status.", status.isActive());
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
service.removeStreamStatus(status);
assertFalse("Wrong status.", status.isActive());
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
}
use of org.libresonic.player.domain.TransferStatus in project libresonic by Libresonic.
the class StatusServiceTestCase method testMultipleStreamsSamePlayer.
public void testMultipleStreamsSamePlayer() {
TransferStatus statusA = service.createStreamStatus(player1);
TransferStatus statusB = service.createStreamStatus(player1);
assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getStreamStatusesForPlayer(player1));
// Stop stream A.
service.removeStreamStatus(statusA);
assertFalse("Wrong status.", statusA.isActive());
assertTrue("Wrong status.", statusB.isActive());
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
// Stop stream B.
service.removeStreamStatus(statusB);
assertFalse("Wrong status.", statusB.isActive());
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
// Start stream C.
TransferStatus statusC = service.createStreamStatus(player1);
assertTrue("Wrong status.", statusC.isActive());
assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getAllStreamStatuses());
assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getStreamStatusesForPlayer(player1));
}
use of org.libresonic.player.domain.TransferStatus in project libresonic by Libresonic.
the class UploadController method handleRequestInternal.
@RequestMapping(method = { RequestMethod.POST })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();
List<File> uploadedFiles = new ArrayList<>();
List<File> unzippedFiles = new ArrayList<>();
TransferStatus status = null;
try {
status = statusService.createUploadStatus(playerService.getPlayer(request, response, false, false));
status.setBytesTotal(request.getContentLength());
request.getSession().setAttribute(UPLOAD_STATUS, status);
// Check that we have a file upload request
if (!ServletFileUpload.isMultipartContent(request)) {
throw new Exception("Illegal request.");
}
File dir = null;
boolean unzip = false;
UploadListener listener = new UploadListenerImpl(status);
FileItemFactory factory = new MonitoredDiskFileItemFactory(listener);
ServletFileUpload upload = new ServletFileUpload(factory);
List<?> items = upload.parseRequest(request);
// First, look for "dir" and "unzip" parameters.
for (Object o : items) {
FileItem item = (FileItem) o;
if (item.isFormField() && "dir".equals(item.getFieldName())) {
dir = new File(item.getString());
} else if (item.isFormField() && "unzip".equals(item.getFieldName())) {
unzip = true;
}
}
if (dir == null) {
throw new Exception("Missing 'dir' parameter.");
}
// Look for file items.
for (Object o : items) {
FileItem item = (FileItem) o;
if (!item.isFormField()) {
String fileName = item.getName();
if (fileName.trim().length() > 0) {
File targetFile = new File(dir, new File(fileName).getName());
if (!securityService.isUploadAllowed(targetFile)) {
throw new Exception("Permission denied: " + StringUtil.toHtml(targetFile.getPath()));
}
if (!dir.exists()) {
dir.mkdirs();
}
item.write(targetFile);
uploadedFiles.add(targetFile);
LOG.info("Uploaded " + targetFile);
if (unzip && targetFile.getName().toLowerCase().endsWith(".zip")) {
unzip(targetFile, unzippedFiles);
}
}
}
}
} catch (Exception x) {
LOG.warn("Uploading failed.", x);
map.put("exception", x);
} finally {
if (status != null) {
statusService.removeUploadStatus(status);
request.getSession().removeAttribute(UPLOAD_STATUS);
User user = securityService.getCurrentUser(request);
securityService.updateUserByteCounts(user, 0L, 0L, status.getBytesTransfered());
}
}
map.put("uploadedFiles", uploadedFiles);
map.put("unzippedFiles", unzippedFiles);
return new ModelAndView("upload", "model", map);
}
use of org.libresonic.player.domain.TransferStatus in project libresonic by Libresonic.
the class NowPlayingController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Player player = playerService.getPlayer(request, response);
List<TransferStatus> statuses = statusService.getStreamStatusesForPlayer(player);
MediaFile current = statuses.isEmpty() ? null : mediaFileService.getMediaFile(statuses.get(0).getFile());
MediaFile dir = current == null ? null : mediaFileService.getParentOf(current);
String url;
if (dir != null && !mediaFileService.isRoot(dir)) {
url = "main.view?id=" + dir.getId();
} else {
url = "home.view";
}
return new ModelAndView(new RedirectView(url));
}
Aggregations