download zip file

This commit is contained in:
damage 2024-12-23 10:39:06 +01:00
parent 36473592ad
commit 97324e4647
2 changed files with 12 additions and 3 deletions

View File

@ -31,11 +31,14 @@ public class Download extends AuthenticatedServlet {
private static final String PARAMETER_VERSION = "version";
private static final String PARAMETER_POM = "pom";
private static final String PARAMETER_TYPE = "type";
private static final String PARAMETER_ZIP = "zip";
// TODO: set as property
private static final String MAVEN_CMD = "/usr/bin/mvn";
private static final String TEMP_DIR = "/home/damage/Temp/mavor";
private File tempDir = new File(TEMP_DIR);
@Override
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO: implement a lot of checks:
@ -50,6 +53,13 @@ public class Download extends AuthenticatedServlet {
generatePomXmlByArtifact(site, groupId, artifactId, version);
} else if (type.equals("pom")) {
writePomXml(req.getParameter(PARAMETER_POM));
} else if (type.equals("zip")) {
String zipFilename = req.getParameter(PARAMETER_ZIP);
File zipFile = new File(tempDir, zipFilename);
resp.setContentType("application/zip");
FileInputStream fileInputStream = new FileInputStream(zipFile);
fileInputStream.transferTo(resp.getOutputStream());
fileInputStream.close();
} else {
throw new ServletException("Unknown download type: " + type);
}
@ -96,7 +106,7 @@ public class Download extends AuthenticatedServlet {
}
private void writePomXml(String pomXml) throws IOException {
File pomXmlFile = new File(TEMP_DIR + "/pom.xml");
File pomXmlFile = new File(tempDir, "pom.xml");
pomXmlFile.delete();
FileWriter fileWriter = new FileWriter(pomXmlFile);
fileWriter.write(pomXml);
@ -104,7 +114,6 @@ public class Download extends AuthenticatedServlet {
}
private String zipDependencies() throws IOException {
File tempDir = new File(TEMP_DIR);
File zipFile = new File(tempDir, "mavor_" + UUID.randomUUID() + ".zip");
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
// TODO: this goes BOOM on parallel use

View File

@ -4,7 +4,7 @@
<body style="background-color:black; color:white">
Output:<br/>
<pre>${stdout}</pre><br/>
File: ${zipFilename}<br/>
File: <a href="/mavor/download?type=zip&file=${zipFilename}">${zipFilename}</a><br/>
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
</body>
</html>