mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
bypass our server directly for feed favicons
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -365,7 +365,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<targetGroups>app</targetGroups>
|
||||
<options>indent,devel,noarg,quotmark</options>
|
||||
<options>indent,devel,noarg,quotmark,laxcomma,laxbreak</options>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.frontend.pages.DemoLoginPage;
|
||||
import com.commafeed.frontend.pages.FaviconPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportCallbackPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportRedirectPage;
|
||||
import com.commafeed.frontend.pages.HomePage;
|
||||
@@ -69,7 +68,6 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
mountPage("demo", DemoLoginPage.class);
|
||||
mountPage("logout", LogoutPage.class);
|
||||
mountPage("error", DisplayExceptionPage.class);
|
||||
mountPage("favicon", FaviconPage.class);
|
||||
mountPage("google/import/redirect", GoogleImportRedirectPage.class);
|
||||
mountPage(GoogleImportCallbackPage.PAGE_PATH,
|
||||
GoogleImportCallbackPage.class);
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.commafeed.frontend.pages;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.impl.cookie.DateUtils;
|
||||
import org.apache.wicket.request.IRequestCycle;
|
||||
import org.apache.wicket.request.IRequestHandler;
|
||||
import org.apache.wicket.request.http.WebResponse;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import org.apache.wicket.util.time.Time;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.HttpGetter;
|
||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@SecurityCheck(Role.USER)
|
||||
public class FaviconPage extends BasePage {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(FaviconPage.class);
|
||||
|
||||
@Inject
|
||||
HttpGetter getter;
|
||||
|
||||
@Inject
|
||||
StartupBean startupBean;
|
||||
|
||||
public FaviconPage(PageParameters params) {
|
||||
final String url = params.get("url").toString();
|
||||
getRequestCycle().scheduleRequestHandlerAfterCurrent(
|
||||
new IRequestHandler() {
|
||||
|
||||
@Override
|
||||
public void respond(IRequestCycle requestCycle) {
|
||||
WebResponse response = (WebResponse) requestCycle
|
||||
.getResponse();
|
||||
response.setLastModifiedTime(Time.millis(startupBean
|
||||
.getStartupTime()));
|
||||
response.setContentType("image/x-icon");
|
||||
long expiresAfter = TimeUnit.DAYS.toMillis(7);
|
||||
response.setHeader(
|
||||
HttpHeaders.EXPIRES,
|
||||
DateUtils.formatDate(new Date(startupBean
|
||||
.getStartupTime() + expiresAfter)));
|
||||
response.write(getImage(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach(IRequestCycle requestCycle) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private byte[] getImage(String url) {
|
||||
byte[] img = null;
|
||||
try {
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
int index = Math.max(url.length(), url.lastIndexOf("?"));
|
||||
url = url.substring(0, index);
|
||||
|
||||
String iconUrl = "http://g.etfv.co/"
|
||||
+ URLEncoder.encode(url, "UTF-8") + "?defaulticon=none";
|
||||
HttpResult result = getter.getBinary(iconUrl);
|
||||
if (result != null) {
|
||||
img = result.getContent();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
if (img == null) {
|
||||
img = getDefaultIcon();
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
private byte[] getDefaultIcon() {
|
||||
byte[] bytes = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = getClass().getResourceAsStream("/favicon.gif");
|
||||
bytes = IOUtils.toByteArray(is);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
@@ -7,7 +7,25 @@ module.directive('favicon', function() {
|
||||
url : '='
|
||||
},
|
||||
replace : true,
|
||||
template : '<img ng-src="favicon?url={{url}}" class="favicon"></img>'
|
||||
template : '<img ng-src="{{iconUrl()}}" class="favicon" onError="this.src=\'images/default_favicon.gif\'"></img>',
|
||||
controller : function($scope) {
|
||||
$scope.iconUrl = function() {
|
||||
var url = $scope.url;
|
||||
|
||||
var current = window.location.href;
|
||||
var baseUrl = current.substring(0, current.lastIndexOf('#'));
|
||||
var defaultIcon = baseUrl + 'images/default_favicon.gif';
|
||||
if (!url) {
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
var index = Math.max(url.length, url.lastIndexOf('?'));
|
||||
var iconUrl = 'http://g.etfv.co/';
|
||||
iconUrl += encodeURIComponent(url.substring(0, index));
|
||||
iconUrl += '?defaulticon=none';
|
||||
return iconUrl;
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -82,133 +100,144 @@ module.directive('category', [ function() {
|
||||
restrict : 'E',
|
||||
replace : true,
|
||||
templateUrl : 'directives/category.html',
|
||||
controller : ['$scope', '$state', '$dialog', 'FeedService',
|
||||
'CategoryService', 'SettingsService', function($scope, $state, $dialog, FeedService,
|
||||
CategoryService, SettingsService) {
|
||||
$scope.settingsService = SettingsService;
|
||||
$scope.unsubscribe = function(subscription) {
|
||||
var title = 'Unsubscribe';
|
||||
var msg = 'Unsubscribe from ' + subscription.name + ' ?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'OK',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
controller : [
|
||||
'$scope',
|
||||
'$state',
|
||||
'$dialog',
|
||||
'FeedService',
|
||||
'CategoryService',
|
||||
'SettingsService',
|
||||
function($scope, $state, $dialog, FeedService, CategoryService,
|
||||
SettingsService) {
|
||||
$scope.settingsService = SettingsService;
|
||||
$scope.unsubscribe = function(subscription) {
|
||||
var title = 'Unsubscribe';
|
||||
var msg = 'Unsubscribe from ' + subscription.name
|
||||
+ ' ?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'OK',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(
|
||||
function(result) {
|
||||
if (result == 'ok') {
|
||||
var data = {
|
||||
id : subscription.id
|
||||
};
|
||||
FeedService.unsubscribe(data, function() {
|
||||
CategoryService.init();
|
||||
$dialog.messageBox(title, msg, btns).open().then(
|
||||
function(result) {
|
||||
if (result == 'ok') {
|
||||
var data = {
|
||||
id : subscription.id
|
||||
};
|
||||
FeedService.unsubscribe(data,
|
||||
function() {
|
||||
CategoryService.init();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.formatCategoryName = function(category) {
|
||||
var count = $scope.unreadCount({
|
||||
category : category
|
||||
});
|
||||
};
|
||||
var label = category.name;
|
||||
if (count > 0) {
|
||||
label = label + ' (' + count + ')';
|
||||
}
|
||||
return label;
|
||||
};
|
||||
|
||||
$scope.formatCategoryName = function(category) {
|
||||
var count = $scope.unreadCount({
|
||||
category : category
|
||||
});
|
||||
var label = category.name;
|
||||
if (count > 0) {
|
||||
label = label + ' (' + count + ')';
|
||||
}
|
||||
return label;
|
||||
};
|
||||
$scope.formatFeedName = function(feed) {
|
||||
var label = feed.name;
|
||||
if (feed.unread > 0) {
|
||||
label = label + ' (' + feed.unread + ')';
|
||||
}
|
||||
return label;
|
||||
};
|
||||
|
||||
$scope.formatFeedName = function(feed) {
|
||||
var label = feed.name;
|
||||
if (feed.unread > 0) {
|
||||
label = label + ' (' + feed.unread + ')';
|
||||
}
|
||||
return label;
|
||||
};
|
||||
$scope.feedClicked = function(id) {
|
||||
if ($scope.selectedType == 'feed'
|
||||
&& id == $scope.selectedId) {
|
||||
$scope.$emit('emitReload');
|
||||
} else {
|
||||
$state.transitionTo('feeds.view', {
|
||||
_type : 'feed',
|
||||
_id : id
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.feedClicked = function(id) {
|
||||
if ($scope.selectedType == 'feed' && id == $scope.selectedId) {
|
||||
$scope.$emit('emitReload');
|
||||
} else {
|
||||
$state.transitionTo('feeds.view', {
|
||||
_type : 'feed',
|
||||
_id : id
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.categoryClicked = function(id) {
|
||||
if ($scope.selectedType == 'category'
|
||||
&& id == $scope.selectedId) {
|
||||
$scope.$emit('emitReload');
|
||||
} else {
|
||||
$state.transitionTo('feeds.view', {
|
||||
_type : 'category',
|
||||
_id : id
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.categoryClicked = function(id) {
|
||||
if ($scope.selectedType == 'category' && id == $scope.selectedId) {
|
||||
$scope.$emit('emitReload');
|
||||
} else {
|
||||
$state.transitionTo('feeds.view', {
|
||||
_type : 'category',
|
||||
_id : id
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.renameFeed = function(feed) {
|
||||
var name = window.prompt('Rename feed : ', feed.name);
|
||||
if (name && name != feed.name) {
|
||||
feed.name = name;
|
||||
FeedService.rename({
|
||||
id : feed.id,
|
||||
name : name
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.renameFeed = function(feed) {
|
||||
var name = window.prompt('Rename feed : ', feed.name);
|
||||
if (name && name != feed.name) {
|
||||
feed.name = name;
|
||||
FeedService.rename({
|
||||
id : feed.id,
|
||||
name : name
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.renameCategory = function(category) {
|
||||
var name = window.prompt('Rename category: ',
|
||||
category.name);
|
||||
if (name && name != category.name) {
|
||||
category.name = name;
|
||||
CategoryService.rename({
|
||||
id : category.id,
|
||||
name : name
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.renameCategory = function(category) {
|
||||
var name = window.prompt('Rename category: ', category.name);
|
||||
if (name && name != category.name) {
|
||||
category.name = name;
|
||||
CategoryService.rename({
|
||||
id : category.id,
|
||||
name : name
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.deleteCategory = function(category) {
|
||||
var title = 'Delete category';
|
||||
var msg = 'Delete category ' + category.name + ' ?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'OK',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$scope.deleteCategory = function(category) {
|
||||
var title = 'Delete category';
|
||||
var msg = 'Delete category ' + category.name + ' ?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'OK',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(
|
||||
function(result) {
|
||||
if (result == 'ok') {
|
||||
CategoryService.remove({
|
||||
id : category.id
|
||||
}, function() {
|
||||
CategoryService.init();
|
||||
$dialog.messageBox(title, msg, btns).open().then(
|
||||
function(result) {
|
||||
if (result == 'ok') {
|
||||
CategoryService.remove({
|
||||
id : category.id
|
||||
}, function() {
|
||||
CategoryService.init();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$scope.toggleCategory = function(category) {
|
||||
category.expanded = !category.expanded;
|
||||
if (category.id == 'all') {
|
||||
return;
|
||||
}
|
||||
CategoryService.collapse({
|
||||
id : category.id,
|
||||
collapse : !category.expanded
|
||||
});
|
||||
};
|
||||
}]
|
||||
$scope.toggleCategory = function(category) {
|
||||
category.expanded = !category.expanded;
|
||||
if (category.id == 'all') {
|
||||
return;
|
||||
}
|
||||
CategoryService.collapse({
|
||||
id : category.id,
|
||||
collapse : !category.expanded
|
||||
});
|
||||
};
|
||||
} ]
|
||||
};
|
||||
} ]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user