delete zip after download

This commit is contained in:
damage 2024-12-23 11:10:04 +01:00
parent a5cf24366e
commit 53aece5e85
2 changed files with 18 additions and 12 deletions

View File

@ -23,15 +23,21 @@ public class DownloadZip extends AuthenticatedServlet {
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String zipFilename = req.getParameter(PARAMETER_FILENAME); String zipFilename = req.getParameter(PARAMETER_FILENAME);
File zipFile = new File(tempDir, zipFilename); File zipFile = new File(tempDir, zipFilename);
if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) {
resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename)); if (zipFile.exists()) {
resp.setContentType("application/zip"); if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) {
resp.setContentLengthLong(zipFile.length()); resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename));
FileInputStream fileInputStream = new FileInputStream(zipFile); resp.setContentType("application/zip");
fileInputStream.transferTo(resp.getOutputStream()); resp.setContentLengthLong(zipFile.length());
fileInputStream.close(); FileInputStream fileInputStream = new FileInputStream(zipFile);
fileInputStream.transferTo(resp.getOutputStream());
fileInputStream.close();
zipFile.delete();
} else {
throw new ServletException("-.-");
}
} else { } else {
throw new ServletException("-.-"); resp.sendRedirect("/mavor");
} }
} }
} }

View File

@ -2,9 +2,9 @@
<%@ page isELIgnored="false" %> <%@ page isELIgnored="false" %>
<html> <html>
<body style="background-color:black; color:white"> <body style="background-color:black; color:white">
Output:<br/> Download dependencies (Link only works once!): <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/>
<pre>${stdout}</pre><br/> <a href="/mavor/logout">logout</a> | <a href="/mavor">back</a><br/>
File: <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/> Maven Output:<br/>
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a> <pre>${stdout}</pre>
</body> </body>
</html> </html>