Allow filenames with # in them
Avoid unnecessary nullpointer exception
This commit is contained in:
parent
4e662b92ff
commit
3f94629953
4 changed files with 31 additions and 8 deletions
|
|
@ -93,7 +93,9 @@ public class ThumbnailDatabase extends TupleBinding<CachedImage> {
|
||||||
img.mimeType = in.readString();
|
img.mimeType = in.readString();
|
||||||
int lobLen = in.readInt();
|
int lobLen = in.readInt();
|
||||||
img.bits = new byte[lobLen];
|
img.bits = new byte[lobLen];
|
||||||
|
if (lobLen > 0) {
|
||||||
in.read(img.bits, 0, lobLen);
|
in.read(img.bits, 0, lobLen);
|
||||||
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,8 +106,12 @@ public class ThumbnailDatabase extends TupleBinding<CachedImage> {
|
||||||
out.writeInt(1); // version 1
|
out.writeInt(1); // version 1
|
||||||
out.writeLong(img.lastModified);
|
out.writeLong(img.lastModified);
|
||||||
out.writeString(img.mimeType);
|
out.writeString(img.mimeType);
|
||||||
|
if (img.bits != null) {
|
||||||
out.writeInt(img.bits.length);
|
out.writeInt(img.bits.length);
|
||||||
out.write(img.bits);
|
out.write(img.bits);
|
||||||
|
} else {
|
||||||
|
out.writeInt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -468,7 +468,8 @@ public class AlbumServlet
|
||||||
if (cimg == null) {
|
if (cimg == null) {
|
||||||
cimg = pictureScaler.scalePicture(file, thumbnail, size);
|
cimg = pictureScaler.scalePicture(file, thumbnail, size);
|
||||||
thumbDb.store(key, cimg);
|
thumbDb.store(key, cimg);
|
||||||
log.info(" " + key + " added to the cache with size " + cimg.bits.length + " -- now " + thumbDb.size() + " entries");
|
int byteSize = cimg.bits != null ? cimg.bits.length : 0;
|
||||||
|
log.info(" " + key + " added to the cache with size " + byteSize + " -- now " + thumbDb.size() + " entries");
|
||||||
}
|
}
|
||||||
res.setStatus(HttpServletResponse.SC_OK);
|
res.setStatus(HttpServletResponse.SC_OK);
|
||||||
res.setDateHeader("Last-Modified", file.lastModified());
|
res.setDateHeader("Last-Modified", file.lastModified());
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,13 @@ public class PictureScaler {
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage img = ImageIO.read(file);
|
BufferedImage img = ImageIO.read(file);
|
||||||
|
if (img == null) {
|
||||||
|
CachedImage cimg = new CachedImage();
|
||||||
|
cimg.lastModified = file.lastModified();
|
||||||
|
cimg.mimeType = "image/jpeg";
|
||||||
|
cimg.bits = new byte[0];
|
||||||
|
return cimg;
|
||||||
|
}
|
||||||
|
|
||||||
// The orientation is about flipping and rotating. Here is what an 'F' looks like
|
// The orientation is about flipping and rotating. Here is what an 'F' looks like
|
||||||
// on pictures with each orientation.
|
// on pictures with each orientation.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,15 @@ $(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function encUri(str) {
|
||||||
|
return encodeURI(str)
|
||||||
|
.replace(/%5B/g, "[")
|
||||||
|
.replace(/%5D/g, "]")
|
||||||
|
.replace(/[!'()*?&#]/g, function (c) {
|
||||||
|
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function renderGrid(data, textStatus) {
|
function renderGrid(data, textStatus) {
|
||||||
|
|
||||||
var container = $("#container");
|
var container = $("#container");
|
||||||
|
|
@ -34,7 +43,7 @@ $(function() {
|
||||||
isWrapped = imgElement.parent().get()[0].tagName == "A",
|
isWrapped = imgElement.parent().get()[0].tagName == "A",
|
||||||
anchor = isWrapped ? imgElement.parent() : $("<a></a>");
|
anchor = isWrapped ? imgElement.parent() : $("<a></a>");
|
||||||
if (destination) {
|
if (destination) {
|
||||||
anchor.attr("href", encodeURI("/photo/album" + destination + ".album") + location.search);
|
anchor.attr("href", encUri("/photo/album" + destination + ".album") + location.search);
|
||||||
if (!isWrapped) {
|
if (!isWrapped) {
|
||||||
imgElement.wrap(anchor);
|
imgElement.wrap(anchor);
|
||||||
}
|
}
|
||||||
|
|
@ -77,8 +86,8 @@ $(function() {
|
||||||
|
|
||||||
var gridDiv = $("<div class=\"grid\">\n"
|
var gridDiv = $("<div class=\"grid\">\n"
|
||||||
+ " <span class=\"name\">" + entry.name + "</span><br/>\n"
|
+ " <span class=\"name\">" + entry.name + "</span><br/>\n"
|
||||||
+ " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"/photo/album" + encodeURI(entry.path) + "?size=" + picSize + "\" title=\"" + entry.name + "\">"
|
+ " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"/photo/album" + encUri(entry.path) + "?size=" + picSize + "\" title=\"" + entry.name + "\">"
|
||||||
+ "<img class=\"" + entry.type + "pic\" src=\"/photo/album" + (entry.thumbtype == "movie" ? encodeURI(entry.path) + ".frame" : encodeURI(entry.path)) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
+ "<img class=\"" + entry.type + "pic\" src=\"/photo/album" + (entry.thumbtype == "movie" ? encUri(entry.path) + ".frame" : encUri(entry.path)) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
||||||
+ "</div>\n");
|
+ "</div>\n");
|
||||||
|
|
||||||
var captionP = $("<p class=\"caption\"></p>\n");
|
var captionP = $("<p class=\"caption\"></p>\n");
|
||||||
|
|
@ -134,7 +143,7 @@ $(function() {
|
||||||
|
|
||||||
|
|
||||||
$("#search").on("submit", function () {
|
$("#search").on("submit", function () {
|
||||||
var searchStr = "?q=" + encodeURI($("#searchBox").val());
|
var searchStr = "?q=" + encUri($("#searchBox").val());
|
||||||
history.pushState({ }, null, searchStr);
|
history.pushState({ }, null, searchStr);
|
||||||
$.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json') + searchStr, renderGrid);
|
$.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json') + searchStr, renderGrid);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue