aboutsummaryrefslogtreecommitdiff
path: root/newspipe/web/views/api/v2/feed.py
blob: 1081ed8cdcb27d02c5c614cb80416e5b861cc1a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import current_app
from flask_restful import Api

from newspipe.bootstrap import application
from newspipe.web.views.common import api_permission
from newspipe.controllers.feed import FeedController, DEFAULT_MAX_ERROR, DEFAULT_LIMIT

from newspipe.web.views.api.v2.common import (
    PyAggAbstractResource,
    PyAggResourceNew,
    PyAggResourceExisting,
    PyAggResourceMulti,
)


class FeedNewAPI(PyAggResourceNew):
    controller_cls = FeedController


class FeedAPI(PyAggResourceExisting):
    controller_cls = FeedController


class FeedsAPI(PyAggResourceMulti):
    controller_cls = FeedController


class FetchableFeedAPI(PyAggAbstractResource):
    controller_cls = FeedController
    attrs = {
        "max_error": {"type": int, "default": DEFAULT_MAX_ERROR},
        "limit": {"type": int, "default": DEFAULT_LIMIT},
    }

    @api_permission.require(http_exception=403)
    def get(self):
        args = self.reqparse_args(right="read", allow_empty=True)
        result = [feed for feed in self.controller.list_fetchable(**args)]
        return result or None, 200 if result else 204


api = Api(current_app, prefix=application.config['API_ROOT'])

api.add_resource(FeedNewAPI, "/feed", endpoint="feed_new.json")
api.add_resource(FeedAPI, "/feed/<int:obj_id>", endpoint="feed.json")
api.add_resource(FeedsAPI, "/feeds", endpoint="feeds.json")
api.add_resource(FetchableFeedAPI, "/feeds/fetchable", endpoint="fetchable_feed.json")
bgstack15