mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
import OPML
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Category implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Entries implements Serializable {
|
||||
private String name;
|
||||
private List<Entry> entries = Lists.newArrayList();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.commafeed.frontend.model;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Entry implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.commafeed.frontend.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Settings implements Serializable {
|
||||
|
||||
private String readingMode;
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.commafeed.frontend.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Subscription implements Serializable {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String message;
|
||||
private int unread;
|
||||
|
||||
public Long getId() {
|
||||
@@ -32,4 +34,12 @@ public class Subscription implements Serializable {
|
||||
this.unread = unread;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.commafeed.frontend.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SubscriptionRequest implements Serializable {
|
||||
|
||||
private String url;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<script src="vendor/angular/angular.min.js"></script>
|
||||
<script src="vendor/angular/angular-resource.min.js"></script>
|
||||
<script src="vendor/angular/angular-sanitize.min.js"></script>
|
||||
<script src="vendor/angular-upload/ng-upload.min.js"></script>
|
||||
<script src="vendor/angular-ui/angular-ui.min.js"></script>
|
||||
<script src="vendor/angular-ui-bootstrap/ui-bootstrap-tpls-0.2.0.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.commafeed.backend.dao.FeedService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
||||
import com.commafeed.backend.dao.UserService;
|
||||
import com.commafeed.backend.dao.UserSettingsService;
|
||||
import com.commafeed.backend.feeds.OPMLImporter;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.CommaFeedApplication;
|
||||
import com.commafeed.frontend.CommaFeedSession;
|
||||
@@ -59,6 +60,9 @@ public abstract class AbstractREST {
|
||||
@Inject
|
||||
UserSettingsService userSettingsService;
|
||||
|
||||
@Inject
|
||||
OPMLImporter opmlImporter;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
CommaFeedApplication app = CommaFeedApplication.get();
|
||||
|
||||
@@ -33,14 +33,14 @@ public class EntriesREST extends AbstractREST {
|
||||
boolean unreadOnly = "unread".equals(readType);
|
||||
|
||||
if ("feed".equals(type)) {
|
||||
FeedSubscription subscription = feedSubscriptionService
|
||||
.findById(Long.valueOf(id));
|
||||
FeedSubscription subscription = feedSubscriptionService.findById(
|
||||
getUser(), Long.valueOf(id));
|
||||
entries.setName(subscription.getTitle());
|
||||
entries.getEntries().addAll(buildEntries(subscription, unreadOnly));
|
||||
|
||||
} else {
|
||||
FeedCategory feedCategory = "all".equals(id) ? null
|
||||
: feedCategoryService.findById(Long.valueOf(id));
|
||||
: feedCategoryService.findById(getUser(), Long.valueOf(id));
|
||||
Collection<FeedSubscription> subscriptions = "all".equals(id) ? feedSubscriptionService
|
||||
.findAll(getUser()) : feedSubscriptionService
|
||||
.findWithCategory(getUser(), feedCategory);
|
||||
|
||||
@@ -2,11 +2,18 @@ package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
@@ -50,6 +57,27 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
feedSubscriptionService.deleteById(subscriptionId);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("import")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void importOpml() {
|
||||
try {
|
||||
FileItemFactory factory = new DiskFileItemFactory(1000000, null);
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
List<FileItem> items = upload.parseRequest(request);
|
||||
for (FileItem item : items) {
|
||||
if ("file".equals(item.getFieldName())) {
|
||||
opmlImporter.importOpml(getUser(),
|
||||
IOUtils.toString(item.getInputStream(), "UTF-8"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
public Category getSubscriptions() {
|
||||
Category root = new Category();
|
||||
@@ -65,6 +93,7 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
Subscription sub = new Subscription();
|
||||
sub.setId(subscription.getId());
|
||||
sub.setName(subscription.getTitle());
|
||||
sub.setMessage(subscription.getFeed().getMessage());
|
||||
int size = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser()).size();
|
||||
sub.setUnread(size);
|
||||
@@ -88,6 +117,7 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
Subscription sub = new Subscription();
|
||||
sub.setId(subscription.getId());
|
||||
sub.setName(subscription.getTitle());
|
||||
sub.setMessage(subscription.getFeed().getMessage());
|
||||
int size = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser()).size();
|
||||
sub.setUnread(size);
|
||||
|
||||
Reference in New Issue
Block a user