Controller migration

master
Rémi Cocula 8 years ago
parent cf8a0f6d70
commit 24996c628e
  1. 57
      libresonic-main/src/main/java/org/libresonic/player/controller/DownloadController.java
  2. 9
      libresonic-main/src/main/resources/libresonic-servlet.xml

@ -38,10 +38,13 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.LastModified; import org.springframework.web.servlet.mvc.LastModified;
import org.libresonic.player.Logger; import org.libresonic.player.Logger;
@ -69,15 +72,23 @@ import org.libresonic.player.util.Util;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class DownloadController implements Controller, LastModified { @Controller
@RequestMapping("/download")
public class DownloadController implements LastModified {
private static final Logger LOG = Logger.getLogger(DownloadController.class); private static final Logger LOG = Logger.getLogger(DownloadController.class);
@Autowired
private PlayerService playerService; private PlayerService playerService;
@Autowired
private StatusService statusService; private StatusService statusService;
@Autowired
private SecurityService securityService; private SecurityService securityService;
@Autowired
private PlaylistService playlistService; private PlaylistService playlistService;
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private MediaFileService mediaFileService; private MediaFileService mediaFileService;
public long getLastModified(HttpServletRequest request) { public long getLastModified(HttpServletRequest request) {
@ -92,6 +103,7 @@ public class DownloadController implements Controller, LastModified {
} }
} }
@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = securityService.getCurrentUser(request); User user = securityService.getCurrentUser(request);
@ -120,7 +132,7 @@ public class DownloadController implements Controller, LastModified {
if (mediaFile != null) { if (mediaFile != null) {
if (!securityService.isFolderAccessAllowed(mediaFile, user.getUsername())) { if (!securityService.isFolderAccessAllowed(mediaFile, user.getUsername())) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, response.sendError(HttpServletResponse.SC_FORBIDDEN,
"Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername()); "Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername());
return null; return null;
} }
@ -163,7 +175,6 @@ public class DownloadController implements Controller, LastModified {
/** /**
* Downloads a single file. * Downloads a single file.
* *
*
* @param response The HTTP response. * @param response The HTTP response.
* @param status The download status. * @param status The download status.
* @param file The file to download. * @param file The file to download.
@ -205,14 +216,13 @@ public class DownloadController implements Controller, LastModified {
* Downloads the given files. The files are packed together in an * Downloads the given files. The files are packed together in an
* uncompressed zip-file. * uncompressed zip-file.
* *
* * @param response The HTTP response.
* @param response The HTTP response. * @param status The download status.
* @param status The download status. * @param files The files to download.
* @param files The files to download. * @param indexes Only download songs at these indexes. May be <code>null</code>.
* @param indexes Only download songs at these indexes. May be <code>null</code>.
* @param coverArtFile The cover art file to include, may be {@code null}. * @param coverArtFile The cover art file to include, may be {@code null}.
*@param range The byte range, may be <code>null</code>. * @param range The byte range, may be <code>null</code>.
* @param zipFileName The name of the resulting zip file. @throws IOException If an I/O error occurs. * @param zipFileName The name of the resulting zip file. @throws IOException If an I/O error occurs.
*/ */
private void downloadFiles(HttpServletResponse response, TransferStatus status, List<MediaFile> files, int[] indexes, File coverArtFile, HttpRange range, String zipFileName) throws IOException { private void downloadFiles(HttpServletResponse response, TransferStatus status, List<MediaFile> files, int[] indexes, File coverArtFile, HttpRange range, String zipFileName) throws IOException {
if (indexes != null && indexes.length == 1) { if (indexes != null && indexes.length == 1) {
@ -253,7 +263,6 @@ public class DownloadController implements Controller, LastModified {
/** /**
* Utility method for writing the content of a given file to a given output stream. * Utility method for writing the content of a given file to a given output stream.
* *
*
* @param file The file to copy. * @param file The file to copy.
* @param out The output stream to write to. * @param out The output stream to write to.
* @param status The download status. * @param status The download status.
@ -317,7 +326,6 @@ public class DownloadController implements Controller, LastModified {
* Writes a file or a directory structure to a zip output stream. File entries in the zip file are relative * Writes a file or a directory structure to a zip output stream. File entries in the zip file are relative
* to the given root. * to the given root.
* *
*
* @param out The zip output stream. * @param out The zip output stream.
* @param root The root of the directory structure. Used to create path information in the zip file. * @param root The root of the directory structure. Used to create path information in the zip file.
* @param file The file or directory to zip. * @param file The file or directory to zip.
@ -389,27 +397,4 @@ public class DownloadController implements Controller, LastModified {
return crc.getValue(); return crc.getValue();
} }
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setStatusService(StatusService statusService) {
this.statusService = statusService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlaylistService(PlaylistService playlistService) {
this.playlistService = playlistService;
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
} }

@ -31,14 +31,6 @@
<property name="playerService" ref="playerService"/> <property name="playerService" ref="playerService"/>
<property name="shareService" ref="shareService"/> <property name="shareService" ref="shareService"/>
</bean> </bean>
<bean id="downloadController" class="org.libresonic.player.controller.DownloadController">
<property name="playerService" ref="playerService"/>
<property name="statusService" ref="statusService"/>
<property name="securityService" ref="securityService"/>
<property name="playlistService" ref="playlistService"/>
<property name="settingsService" ref="settingsService"/>
<property name="mediaFileService" ref="mediaFileService"/>
</bean>
<bean id="wapController" class="org.libresonic.player.controller.WapController"> <bean id="wapController" class="org.libresonic.player.controller.WapController">
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
<property name="playerService" ref="playerService"/> <property name="playerService" ref="playerService"/>
@ -90,7 +82,6 @@
<property name="mappings"> <property name="mappings">
<props> <props>
<prop key="/videoPlayer.view">videoPlayerController</prop> <prop key="/videoPlayer.view">videoPlayerController</prop>
<prop key="/download.view">downloadController</prop>
<prop key="/db.view">dbController</prop> <prop key="/db.view">dbController</prop>
<prop key="/podcast/**">podcastController</prop> <prop key="/podcast/**">podcastController</prop>
<prop key="/wap/download.view">downloadController</prop> <prop key="/wap/download.view">downloadController</prop>

Loading…
Cancel
Save