forked from Archives/Athou_commafeed
cache default (missing) favicon too
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 238 B |
@@ -1,27 +1,40 @@
|
||||
package com.commafeed.backend.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.commafeed.backend.dao.FeedDAO;
|
||||
import com.commafeed.backend.favicon.AbstractFaviconFetcher;
|
||||
import com.commafeed.backend.feed.FeedUtils;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
|
||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
||||
@Singleton
|
||||
public class FeedService {
|
||||
|
||||
private final FeedDAO feedDAO;
|
||||
private final Set<AbstractFaviconFetcher> faviconFetchers;
|
||||
|
||||
private byte[] defaultFavicon;
|
||||
|
||||
@Inject
|
||||
public FeedService(FeedDAO feedDAO, Set<AbstractFaviconFetcher> faviconFetchers) {
|
||||
this.feedDAO = feedDAO;
|
||||
this.faviconFetchers = faviconFetchers;
|
||||
|
||||
try {
|
||||
defaultFavicon = IOUtils.toByteArray(getClass().getResource("/images/default_favicon.ico"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("could not load default favicon", e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Feed findOrCreate(String url) {
|
||||
String normalized = FeedUtils.normalizeURL(url);
|
||||
Feed feed = feedDAO.findByUrl(normalized);
|
||||
@@ -46,6 +59,9 @@ public class FeedService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (icon == null) {
|
||||
icon = defaultFavicon;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
@@ -324,13 +324,7 @@ public class FeedREST {
|
||||
Feed feed = subscription.getFeed();
|
||||
byte[] icon = feedService.fetchFavicon(feed);
|
||||
|
||||
ResponseBuilder builder = null;
|
||||
if (icon == null) {
|
||||
String baseUrl = FeedUtils.removeTrailingSlash(config.getApplicationSettings().getPublicUrl());
|
||||
builder = Response.status(Status.MOVED_PERMANENTLY).location(URI.create(baseUrl + "/images/default_favicon.gif"));
|
||||
} else {
|
||||
builder = Response.ok(icon, "image/x-icon");
|
||||
}
|
||||
ResponseBuilder builder = Response.ok(icon, "image/x-icon");
|
||||
|
||||
CacheControl cacheControl = new CacheControl();
|
||||
cacheControl.setMaxAge(2592000);
|
||||
|
||||
BIN
src/main/resources/images/default_favicon.ico
Normal file
BIN
src/main/resources/images/default_favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Reference in New Issue
Block a user