Adding debug extension to see cache entries.

This commit is contained in:
Knut Forkalsrud 2014-11-28 19:45:24 -08:00
parent 93868e0d18
commit 577348ca26
2 changed files with 34 additions and 1 deletions

View file

@ -23,7 +23,6 @@ import org.forkalsrud.album.db.DirectoryProps;
*/ */
public class DirectoryEntry extends EntryWithChildren<Entry> { public class DirectoryEntry extends EntryWithChildren<Entry> {
final static String CACHE_FILE = "cache.properties";
final static String OVERRIDE_FILE = "album.properties"; final static String OVERRIDE_FILE = "album.properties";
public interface ServiceApi { public interface ServiceApi {
@ -122,6 +121,7 @@ public class DirectoryEntry extends EntryWithChildren<Entry> {
DirectoryProps props = services.getMetadataGenerator().generate(file); DirectoryProps props = services.getMetadataGenerator().generate(file);
services.getDirectoryDatabase().store(file.getAbsolutePath(), props); services.getDirectoryDatabase().store(file.getAbsolutePath(), props);
cache = props;
return props; return props;
} }
@ -214,4 +214,9 @@ public class DirectoryEntry extends EntryWithChildren<Entry> {
public boolean groupByYear() { public boolean groupByYear() {
return parent == null; return parent == null;
} }
public DirectoryProps getCache() {
return cache;
}
} }

View file

@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.forkalsrud.album.db.DirectoryDatabase; import org.forkalsrud.album.db.DirectoryDatabase;
import org.forkalsrud.album.db.DirectoryProps;
import org.forkalsrud.album.db.MovieDatabase; import org.forkalsrud.album.db.MovieDatabase;
import org.forkalsrud.album.db.ThumbnailDatabase; import org.forkalsrud.album.db.ThumbnailDatabase;
import org.forkalsrud.album.exif.DirectoryEntry; import org.forkalsrud.album.exif.DirectoryEntry;
@ -277,6 +278,12 @@ public class AlbumServlet
return; return;
} }
if (pathInfo.endsWith(".cache")) {
pathInfo = pathInfo.substring(0, pathInfo.length() - ".cache".length());
handleCache(req, res, (DirectoryEntry)resolveEntry(pathInfo));
return;
}
File file = new File(base, pathInfo); File file = new File(base, pathInfo);
if (!file.canRead()) { if (!file.canRead()) {
res.setStatus(HttpServletResponse.SC_FORBIDDEN); res.setStatus(HttpServletResponse.SC_FORBIDDEN);
@ -449,6 +456,27 @@ public class AlbumServlet
return in == null ? "null" : "\"" + in.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + "\""; return in == null ? "null" : "\"" + in.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + "\"";
} }
void handleCache(HttpServletRequest req, HttpServletResponse res, DirectoryEntry entry) {
if (entry == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
DirectoryProps props = entry.getCache();
if (props == null) {
props = new DirectoryProps();
}
try {
res.setContentType("text/plain");
res.setCharacterEncoding("UTF-8");
PrintWriter out = res.getWriter();
out.println("# cache timestamp: " + props.getTimestamp());
out.println("# dir timestamp: " + entry.getPath().lastModified());
out.println();
props.store(out, "");
} catch (Exception e) {
throw new RuntimeException("sadness", e);
}
}
void handleEdit(HttpServletRequest req, HttpServletResponse res, FileEntry entry) throws Exception { void handleEdit(HttpServletRequest req, HttpServletResponse res, FileEntry entry) throws Exception {
String value = req.getParameter("value"); String value = req.getParameter("value");
if (value != null) { if (value != null) {