use of org.libresonic.player.domain.Share in project libresonic by Libresonic.
the class ShareManagementController method createShare.
@RequestMapping(method = RequestMethod.GET)
public ModelAndView createShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<MediaFile> files = getMediaFiles(request);
MediaFile dir = null;
if (!files.isEmpty()) {
dir = files.get(0);
if (!dir.isAlbum()) {
dir = mediaFileService.getParentOf(dir);
}
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("dir", dir);
map.put("user", securityService.getCurrentUser(request));
Share share = shareService.createShare(request, files);
String description = getDescription(request);
if (description != null) {
share.setDescription(description);
shareService.updateShare(share);
}
map.put("playUrl", shareService.getShareUrl(request, share));
return new ModelAndView("createShare", "model", map);
}
use of org.libresonic.player.domain.Share in project libresonic by Libresonic.
the class ShareSettingsController method handleParameters.
private void handleParameters(HttpServletRequest request) {
User user = securityService.getCurrentUser(request);
for (Share share : shareService.getSharesForUser(user)) {
int id = share.getId();
String description = getParameter(request, "description", id);
boolean delete = getParameter(request, "delete", id) != null;
String expireIn = getParameter(request, "expireIn", id);
if (delete) {
shareService.deleteShare(id);
} else {
if (expireIn != null) {
share.setExpires(parseExpireIn(expireIn));
}
share.setDescription(description);
shareService.updateShare(share);
}
}
boolean deleteExpired = ServletRequestUtils.getBooleanParameter(request, "deleteExpired", false);
if (deleteExpired) {
Date now = new Date();
for (Share share : shareService.getSharesForUser(user)) {
Date expires = share.getExpires();
if (expires != null && expires.before(now)) {
shareService.deleteShare(share.getId());
}
}
}
}
use of org.libresonic.player.domain.Share in project libresonic by Libresonic.
the class RESTController method updateShare.
@RequestMapping(value = "/rest/updateShare", method = { RequestMethod.GET, RequestMethod.POST })
public void updateShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
User user = securityService.getCurrentUser(request);
int id = getRequiredIntParameter(request, "id");
Share share = shareService.getShareById(id);
if (share == null) {
error(request, response, ErrorCode.NOT_FOUND, "Shared media not found.");
return;
}
if (!user.isAdminRole() && !share.getUsername().equals(user.getUsername())) {
error(request, response, ErrorCode.NOT_AUTHORIZED, "Not authorized to modify shared media.");
return;
}
share.setDescription(request.getParameter("description"));
String expiresString = request.getParameter("expires");
if (expiresString != null) {
long expires = Long.parseLong(expiresString);
share.setExpires(expires == 0L ? null : new Date(expires));
}
shareService.updateShare(share);
writeEmptyResponse(request, response);
}
use of org.libresonic.player.domain.Share in project libresonic by Libresonic.
the class RESTController method createShare.
@RequestMapping(value = "/rest/createShare", method = { RequestMethod.GET, RequestMethod.POST })
public void createShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
User user = securityService.getCurrentUser(request);
if (!user.isShareRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to share media.");
return;
}
List<MediaFile> files = new ArrayList<MediaFile>();
for (int id : getRequiredIntParameters(request, "id")) {
files.add(mediaFileService.getMediaFile(id));
}
Share share = shareService.createShare(request, files);
share.setDescription(request.getParameter("description"));
long expires = getLongParameter(request, "expires", 0L);
if (expires != 0) {
share.setExpires(new Date(expires));
}
shareService.updateShare(share);
Shares result = new Shares();
org.libresonic.restapi.Share s = createJaxbShare(request, share);
result.getShare().add(s);
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
s.getEntry().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setShares(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.Share in project libresonic by Libresonic.
the class RESTController method getShares.
@RequestMapping(value = "/rest/getShares", method = { RequestMethod.GET, RequestMethod.POST })
public void getShares(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
User user = securityService.getCurrentUser(request);
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
Shares result = new Shares();
for (Share share : shareService.getSharesForUser(user)) {
org.libresonic.restapi.Share s = createJaxbShare(request, share);
result.getShare().add(s);
for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
s.getEntry().add(createJaxbChild(player, mediaFile, username));
}
}
Response res = createResponse();
res.setShares(result);
jaxbWriter.writeResponse(request, response, res);
}
Aggregations