Skip to content

Commit

Permalink
Bugfix for not clearing thumbnail after ref is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Sep 27, 2024
1 parent 2137b6f commit cea64d4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/main/java/jasper/component/FileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,21 @@ public Ref fetchThumbnail(String url, String origin, OutputStream os) {
if (bannedOrBroken(fullSize)) return null;
if (fullSize.isThumbnail()) return fetch(url, origin, os, false);
var thumbnailId = "t_" + fullSize.getId();
var oldThumbnailUrl = "internal:" + thumbnailId;
var thumbnailUrl = "cache:" + thumbnailId;
if (storage.exists(origin, CACHE, thumbnailId)) {
try {
return fetch(thumbnailUrl, origin, os, false);
} catch (ScrapeProtocolException e) {
// TODO: remove support for old internal: scheme after migrating to cache: scheme
return fetch(oldThumbnailUrl, origin, os, false);
}
var existingCache = stat(thumbnailUrl, origin);
if (existingCache == null) {
// TODO: stop checking internal: after cache migrates to cache: scheme
thumbnailUrl = "internal:" + thumbnailId;
existingCache = stat(thumbnailUrl, origin);
}
if (existingCache != null && isBlank(existingCache.getId())) {
// If id is blank the last thumbnail generation must have failed
// Wait for the user to manually refresh
return null;
}
if (existingCache != null && storage.exists(origin, CACHE, thumbnailId)) {
return fetch(thumbnailUrl, origin, os, false);
} else {
var existingCache = stat(thumbnailUrl, origin);
if (existingCache != null && isBlank(existingCache.getId())) {
// If id is blank the last thumbnail generation must have failed
// Wait for the user to manually refresh
return null;
}
var data = images.thumbnail(storage.stream(origin, CACHE, fullSize.getId()));
if (data == null) {
// Returning null means the full size image is already small enough to be a thumbnail
Expand All @@ -192,6 +191,9 @@ public Ref fetchThumbnail(String url, String origin, OutputStream os) {
return tagger.internalPlugin(url, origin, "_plugin/cache", fullSize, "-_plugin/delta/cache");
}
try {
if (storage.exists(origin, CACHE, thumbnailId)) {
storage.delete(origin, CACHE, thumbnailId);
}
storage.storeAt(origin, CACHE, thumbnailId, data);
if (os != null) StreamUtils.copy(data, os);
} catch (Exception e) {
Expand Down

0 comments on commit cea64d4

Please sign in to comment.