Skip to content

Commit

Permalink
Implementing drag-and-drop file upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelschoen committed Sep 10, 2022
1 parent 8ad5bae commit d270517
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
7 changes: 5 additions & 2 deletions app/src/main/java/org/acme/BrowseFilesResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@ public Response browse(@QueryParam("path") String path, @QueryParam("image") Str
body += " <meta charset=\"UTF-8\">\n";
body += " <link rel=\"stylesheet\" href=\"/retroio.css\">\n";
body += " <title>RetroIO Floppy Image Browser</title>\n";
body += "</head><body>\n";
body += "</head><body><div style=\"margin: 20px;\">\n";
body += createHeaderDiv(path, imageName);
body += "<h3>Contents</h3>\n";

body += "<div style=\"font-size: -1; font-size: 0.9rem; margin-left: 20px;\">";
String uuidPathOnly = path.substring(0, path.indexOf("/"));

body += new FolderNode(uuidPathOnly, pathDir, true).getFolderDivTag();
body += "</div>";
body += "</div></div>";
body += "</body></html>\n";
return Response.status(200).entity(body).build();
}

private String createHeaderDiv(String path, String filename) {
String headerDiv = "<div>\n";

headerDiv += "<img src=\"/images/retroio-logo-main.png\" alt=\"RetroIO\" />";
headerDiv += "<img src=\"/images/floppy-image-loader-logo.png\" alt=\"Floppy Image Loader \" />";

headerDiv += "<h3>Image: " + filename + "</h3>\n";

headerDiv += "<ul>\n";
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/acme/FloppyImageUploadResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public Response uploadFile(MultipartFormDataInput input) {
ImageType imageType = ImageType.getTypeFromFile(finalImageFile);
System.out.println("Image type: " + imageType.name());
if(imageType == ImageType.unknown) {
return Response.status(500).entity("Invalid/unsupported file format").build();
if(!isAjax) {
return Response.status(500).entity("Invalid/unsupported file format").build();
} else {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}

try {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

</head>
<body>
<div style="margin: 30px;">
<div style="margin: 20px;">

<img src="/images/retroio-logo-main.png" alt="RetroIO" />
<img src="/images/floppy-image-loader-logo.png" alt="Floppy Image Loader" />
Expand Down Expand Up @@ -200,18 +200,13 @@ <h3>File Upload</h3>
{
window.location.href = data.url;
},
error: function()
error: function (xhr, ajaxOptions, thrownError)
{
alert( 'Error. Please, contact the webmaster!' );
/*
if (data.redirect) {
// data.redirect contains the string URL to redirect to
alert( 'Redirect to:' + data.redirect );
window.location.href = data.redirect;
if(xhr.status == 400) {
alert('Invalid or unsupported image file.')
} else {
alert( 'Error. Please, contact the webmaster!' );
alert('Unknown error, image may be invalid.')
}
*/
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/resources/META-INF/resources/retroio.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d270517

Please sign in to comment.