Search in sources :

Example 6 with Share

use of org.libresonic.player.domain.Share in project libresonic by Libresonic.

the class ShareSettingsController method getShareInfos.

private List<ShareInfo> getShareInfos(HttpServletRequest request) {
    List<ShareInfo> result = new ArrayList<ShareInfo>();
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    for (Share share : shareService.getSharesForUser(user)) {
        List<MediaFile> files = shareService.getSharedFiles(share.getId(), musicFolders);
        if (!files.isEmpty()) {
            MediaFile file = files.get(0);
            result.add(new ShareInfo(shareService.getShareUrl(request, share), share, file.isDirectory() ? file : mediaFileService.getParentOf(file)));
        }
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) User(org.libresonic.player.domain.User) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share)

Example 7 with Share

use of org.libresonic.player.domain.Share in project libresonic by Libresonic.

the class RESTController method deleteShare.

@RequestMapping(value = "/rest/deleteShare", method = { RequestMethod.GET, RequestMethod.POST })
public void deleteShare(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 delete shared media.");
        return;
    }
    shareService.deleteShare(id);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) 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