proxy images through commafeed (#231)

This commit is contained in:
Athou
2013-06-22 21:36:55 +02:00
parent ab51b63b39
commit 52e4a2a0b7
10 changed files with 118 additions and 8 deletions

View File

@@ -24,7 +24,8 @@ import com.wordnik.swagger.annotations.ApiProperty;
@ApiClass("Entry details")
public class Entry implements Serializable {
public static Entry build(FeedEntryStatus status, String publicUrl) {
public static Entry build(FeedEntryStatus status, String publicUrl,
boolean proxyImages) {
Entry entry = new Entry();
FeedEntry feedEntry = status.getEntry();
@@ -36,7 +37,8 @@ public class Entry implements Serializable {
entry.setId(String.valueOf(feedEntry.getId()));
entry.setGuid(feedEntry.getGuid());
entry.setTitle(feedEntry.getContent().getTitle());
entry.setContent(feedEntry.getContent().getContent());
entry.setContent(FeedUtils.proxyImages(feedEntry.getContent()
.getContent(), publicUrl, proxyImages));
entry.setRtl(FeedUtils.isRTL(feedEntry));
entry.setAuthor(feedEntry.getAuthor());
entry.setEnclosureUrl(feedEntry.getContent().getEnclosureUrl());

View File

@@ -25,6 +25,7 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.util.crypt.Base64;
import com.commafeed.backend.DatabaseCleaner;
import com.commafeed.backend.HttpGetter;
import com.commafeed.backend.MetricsBean;
import com.commafeed.backend.StartupBean;
import com.commafeed.backend.dao.FeedCategoryDAO;
@@ -128,6 +129,9 @@ public abstract class AbstractREST {
@Inject
DatabaseCleaner cleaner;
@Inject
HttpGetter httpGetter;
@PostConstruct
public void init() {
CommaFeedApplication app = CommaFeedApplication.get();

View File

@@ -96,7 +96,8 @@ public class CategoryREST extends AbstractResourceREST {
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl()));
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
}
} else if (STARRED.equals(id)) {
@@ -106,7 +107,8 @@ public class CategoryREST extends AbstractResourceREST {
for (FeedEntryStatus status : starred) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl()));
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
}
} else {
FeedCategory feedCategory = feedCategoryDAO.findById(getUser(),
@@ -127,7 +129,9 @@ public class CategoryREST extends AbstractResourceREST {
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService
.get().getPublicUrl()));
.get().getPublicUrl(),
applicationSettingsService.get()
.isImageProxyEnabled()));
}
entries.setName(feedCategory.getName());
}

View File

@@ -75,7 +75,8 @@ public class EntryREST extends AbstractResourceREST {
.findByKeywords(getUser(), keywords, offset, limit);
for (FeedEntryStatus status : entriesStatus) {
list.add(Entry.build(status, applicationSettingsService.get()
.getPublicUrl()));
.getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}
entries.setName("Search for : " + keywords);

View File

@@ -113,7 +113,8 @@ public class FeedREST extends AbstractResourceREST {
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl()));
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
}
boolean hasMore = entries.getEntries().size() > limit;

View File

@@ -2,8 +2,13 @@ package com.commafeed.frontend.rest.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import com.commafeed.backend.HttpGetter.HttpResult;
import com.commafeed.backend.feeds.FeedUtils;
import com.commafeed.frontend.model.ServerInfo;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@@ -23,4 +28,19 @@ public class ServerREST extends AbstractResourceREST {
startupBean.getSupportedLanguages());
return Response.ok(infos).build();
}
@Path("/proxy")
@GET
@ApiOperation(value = "proxy image")
@Produces("image/png")
public Response get(@QueryParam("u") String url) {
url = FeedUtils.imageProxyDecoder(url);
try {
HttpResult result = httpGetter.getBinary(url);
return Response.ok(result.getContent()).build();
} catch (Exception e) {
return Response.status(Status.SERVICE_UNAVAILABLE)
.entity(e.getMessage()).build();
}
}
}