Search in sources :

Example 1 with Share

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);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ModelAndView(org.springframework.web.servlet.ModelAndView) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Share

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());
            }
        }
    }
}
Also used : User(org.libresonic.player.domain.User) Share(org.libresonic.player.domain.Share)

Example 3 with Share

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);
}
Also used : User(org.libresonic.player.domain.User) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Share

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);
}
Also used : User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) HttpServletResponse(javax.servlet.http.HttpServletResponse) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Share

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Share (org.libresonic.player.domain.Share)7 User (org.libresonic.player.domain.User)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 MusicFolder (org.libresonic.player.domain.MusicFolder)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MediaFile (org.libresonic.player.domain.MediaFile)2 org.libresonic.restapi (org.libresonic.restapi)2 ModelAndView (org.springframework.web.servlet.ModelAndView)1