Javalin v5 bump (#930)

This commit is contained in:
Sriman Achanta
2023-10-05 18:22:56 -04:00
committed by GitHub
parent ce0d28da93
commit b3a3ab71bd
5 changed files with 62 additions and 49 deletions

View File

@@ -69,7 +69,7 @@ public class RequestHandler {
return;
}
if (!file.getExtension().contains("zip")) {
if (!file.extension().contains("zip")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'zip'. The uploaded file should be a .zip file.");
@@ -132,7 +132,7 @@ public class RequestHandler {
return;
}
if (!file.getExtension().contains("json")) {
if (!file.extension().contains("json")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'json'. The uploaded file should be a .json file.");
@@ -174,7 +174,7 @@ public class RequestHandler {
return;
}
if (!file.getExtension().contains("json")) {
if (!file.extension().contains("json")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'json'. The uploaded file should be a .json file.");
@@ -216,7 +216,7 @@ public class RequestHandler {
return;
}
if (!file.getExtension().contains("json")) {
if (!file.extension().contains("json")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'json'. The uploaded file should be a .json file.");
@@ -258,7 +258,7 @@ public class RequestHandler {
return;
}
if (!file.getExtension().contains("jar")) {
if (!file.extension().contains("jar")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'jar'. The uploaded file should be a .jar file.");
@@ -273,7 +273,7 @@ public class RequestHandler {
File targetFile = new File(filePath.toString());
var stream = new FileOutputStream(targetFile);
file.getContent().transferTo(stream);
file.content().transferTo(stream);
stream.close();
ctx.status(200);
@@ -492,14 +492,20 @@ public class RequestHandler {
*/
private static Optional<File> handleTempFileCreation(UploadedFile file) {
var tempFilePath =
new File(Path.of(System.getProperty("java.io.tmpdir"), file.getFilename()).toString());
tempFilePath.getParentFile().mkdirs();
new File(Path.of(System.getProperty("java.io.tmpdir"), file.filename()).toString());
boolean makeDirsRes = tempFilePath.getParentFile().mkdirs();
if (!makeDirsRes) {
logger.error(
"There was an error while uploading " + file.filename() + " to the temp folder!");
return Optional.empty();
}
try {
FileUtils.copyInputStreamToFile(file.getContent(), tempFilePath);
FileUtils.copyInputStreamToFile(file.content(), tempFilePath);
} catch (IOException e) {
logger.error(
"There was an error while uploading " + file.getFilename() + " to the temp folder!");
"There was an error while uploading " + file.filename() + " to the temp folder!");
return Optional.empty();
}