Exemple #1
0
func (con Article) Handler(c context.Context) http.Handler {
	logger := webfw.GetLogger(c)
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := readeef.GetUser(c, r)

		params := webfw.GetParams(c, r)
		action := webfw.GetMultiPatternIdentifier(c, r)

		logger.Infof("Invoking Article controller with action '%s', article id '%s'\n", action, params["article-id"])

		var articleId int64
		var resp responseError

		articleId, resp.err = strconv.ParseInt(params["article-id"], 10, 64)

		if resp.err == nil {
			id := data.ArticleId(articleId)
			switch action {
			case "fetch":
				resp = fetchArticle(user, id)
			case "read":
				resp = articleReadState(user, id, params["value"] == "true")
			case "favorite":
				resp = articleFavoriteState(user, id, params["value"] == "true")
			case "format":
				resp = formatArticle(user, id, con.extractor, webfw.GetConfig(c), con.config)
			}
		}

		var b []byte
		if resp.err == nil {
			b, resp.err = json.Marshal(resp.val)
		}

		if resp.err == nil {
			w.Write(b)
		} else {
			webfw.GetLogger(c).Print(resp.err)

			w.WriteHeader(http.StatusInternalServerError)
		}
	})
}
Exemple #2
0
func (a apiRequest) processor(
	c context.Context,
	s context.Session,
	user content.User,
	fm *readeef.FeedManager,
	sp content.SearchProvider,
	extractor content.Extractor,
	capabilities capabilities,
	secret []byte,
) (Processor, error) {

	switch a.Method {
	case "heartbeat":
		return &heartbeatProcessor{}, nil
	case "get-auth-data":
		return &getAuthDataProcessor{user: user, session: s, capabilities: capabilities}, nil
	case "logout":
		return &logoutProcessor{session: s}, nil
	case "article-read-state":
		return &articleReadStateProcessor{user: user}, nil
	case "article-favorite-state":
		return &articleFavoriteStateProcessor{user: user}, nil
	case "format-article":
		return &formatArticleProcessor{
			user:          user,
			extractor:     extractor,
			webfwConfig:   webfw.GetConfig(c),
			readeefConfig: readeef.GetConfig(c),
		}, nil
	case "get-article":
		return &getArticleProcessor{user: user}, nil
	case "list-feeds":
		return &listFeedsProcessor{user: user}, nil
	case "discover-feeds":
		return &discoverFeedsProcessor{user: user, fm: fm}, nil
	case "export-opml":
		return &exportOpmlProcessor{user: user}, nil
	case "parse-opml":
		return &parseOpmlProcessor{user: user, fm: fm}, nil
	case "add-feeds":
		return &addFeedsProcessor{user: user, fm: fm}, nil
	case "remove-feed":
		return &removeFeedProcessor{user: user, fm: fm}, nil
	case "get-feed-tags":
		return &getFeedTagsProcessor{user: user}, nil
	case "set-feed-tags":
		return &setFeedTagsProcessor{user: user}, nil
	case "read-state":
		return &readStateProcessor{user: user}, nil
	case "get-feed-articles":
		return &getFeedArticlesProcessor{user: user, sp: sp}, nil
	case "get-user-attribute":
		return &getUserAttributeProcessor{user: user}, nil
	case "set-user-attribute":
		return &setUserAttributeProcessor{user: user, secret: secret}, nil
	case "list-users":
		return &listUsersProcessor{user: user}, nil
	case "add-user":
		return &addUserProcessor{user: user, secret: secret}, nil
	case "remove-user":
		return &removeUserProcessor{user: user}, nil
	case "set-attribute-for-user":
		return &setAttributeForUserProcessor{user: user, secret: secret}, nil
	default:
		return nil, errInvalidMethodValue
	}
}
Exemple #3
0
func (a apiRequest) processor(
	c context.Context,
	user content.User,
	fm *readeef.FeedManager,
	si readeef.SearchIndex,
	secret []byte,
) (Processor, error) {

	switch a.Method {
	case "heartbeat":
		return &heartbeatProcessor{}, nil
	case "get-auth-data":
		return &getAuthDataProcessor{user: user}, nil
	case "mark-article-as-read":
		return &markArticleAsReadProcessor{user: user}, nil
	case "mark-article-as-favorite":
		return &markArticleAsFavoriteProcessor{user: user}, nil
	case "format-article":
		return &formatArticleProcessor{
			user:          user,
			webfwConfig:   webfw.GetConfig(c),
			readeefConfig: readeef.GetConfig(c),
		}, nil
	case "get-article":
		return &getArticleProcessor{user: user}, nil
	case "list-feeds":
		return &listFeedsProcessor{user: user}, nil
	case "discover-feeds":
		return &discoverFeedsProcessor{user: user, fm: fm}, nil
	case "parse-opml":
		return &parseOpmlProcessor{user: user, fm: fm}, nil
	case "add-feed":
		return &addFeedProcessor{user: user, fm: fm}, nil
	case "remove-feed":
		return &removeFeedProcessor{user: user, fm: fm}, nil
	case "get-feed-tags":
		return &getFeedTagsProcessor{user: user}, nil
	case "set-feed-tags":
		return &setFeedTagsProcessor{user: user}, nil
	case "mark-feed-as-read":
		return &markFeedAsReadProcessor{user: user}, nil
	case "get-feed-articles":
		return &getFeedArticlesProcessor{user: user}, nil
	case "search":
		return &searchProcessor{user: user, si: si}, nil
	case "get-user-attribute":
		return &getUserAttributeProcessor{user: user}, nil
	case "set-user-attribute":
		return &setUserAttributeProcessor{user: user, secret: secret}, nil
	case "list-users":
		return &listUsersProcessor{user: user}, nil
	case "add-user":
		return &addUserProcessor{user: user, secret: secret}, nil
	case "remove-user":
		return &removeUserProcessor{user: user}, nil
	case "set-attribute-for-user":
		return &setAttributeForUserProcessor{user: user, secret: secret}, nil
	default:
		return nil, errInvalidMethodValue
	}
}