mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
Adding basic support for favicon
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -17,8 +19,10 @@ import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
@@ -48,6 +52,7 @@ import com.commafeed.frontend.model.request.IDRequest;
|
||||
import com.commafeed.frontend.model.request.MarkRequest;
|
||||
import com.commafeed.frontend.model.request.SubscribeRequest;
|
||||
import com.commafeed.frontend.rest.Enums.ReadType;
|
||||
import com.commafeed.frontend.utils.FetchFavicon;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sun.syndication.feed.opml.Opml;
|
||||
@@ -245,6 +250,30 @@ public class FeedREST extends AbstractResourceREST {
|
||||
.getPublicUrl(), 0)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/favicon")
|
||||
@ApiOperation(value = "Fetch feed icon", notes = "Fetch icon of a feed")
|
||||
public Response favicon(@QueryParam("url") String path) {
|
||||
try {
|
||||
path = URLDecoder.decode(path, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
byte[] icon = new FetchFavicon().get(path);
|
||||
ResponseBuilder reponse = Response.ok(icon, "image/x-icon");
|
||||
|
||||
CacheControl cacheControl = new CacheControl();
|
||||
cacheControl.setMaxAge(2592000);
|
||||
cacheControl.setPrivate(false);
|
||||
reponse.cacheControl(cacheControl); // trying to replicate "public, max-age=2592000"
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
reponse.expires(calendar.getTime());
|
||||
|
||||
return reponse.build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/subscribe")
|
||||
@ApiOperation(value = "Subscribe to a feed", notes = "Subscribe to a feed")
|
||||
|
||||
Reference in New Issue
Block a user