Skip to content

Commit

Permalink
Move API endpoints to /api
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman committed Jun 19, 2024
1 parent 272dddd commit c93f791
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions src/tribler/core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
session.rest_manager.get_endpoint("/search").content_discovery_community = community
session.rest_manager.get_endpoint("/api/search").content_discovery_community = community

def get_endpoints(self) -> list[RESTEndpoint]:
"""
Expand Down Expand Up @@ -161,10 +161,10 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
session.rest_manager.get_endpoint("/downloads").mds = session.mds
session.rest_manager.get_endpoint("/statistics").mds = session.mds
session.rest_manager.get_endpoint("/api/downloads").mds = session.mds
session.rest_manager.get_endpoint("/api/statistics").mds = session.mds

db_endpoint = session.rest_manager.get_endpoint("/metadata")
db_endpoint = session.rest_manager.get_endpoint("/api/metadata")
db_endpoint.download_manager = session.download_manager
db_endpoint.mds = session.mds
db_endpoint.tribler_db = session.db
Expand Down Expand Up @@ -193,7 +193,7 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
endpoint = session.rest_manager.get_endpoint("/knowledge")
endpoint = session.rest_manager.get_endpoint("/api/knowledge")
endpoint.db = session.db
endpoint.community = community

Expand Down Expand Up @@ -263,7 +263,7 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
When we are done launching, register our REST API.
"""
community.register_task("Start torrent checker", session.torrent_checker.initialize)
session.rest_manager.get_endpoint("/metadata").torrent_checker = session.torrent_checker
session.rest_manager.get_endpoint("/api/metadata").torrent_checker = session.torrent_checker


@set_in_session("dht_discovery_community")
Expand All @@ -278,7 +278,7 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
session.rest_manager.get_endpoint("/ipv8").endpoints["/dht"].dht = community
session.rest_manager.get_endpoint("/api/ipv8").endpoints["/dht"].dht = community


@set_in_session("tunnel_community")
Expand Down Expand Up @@ -314,8 +314,8 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
session.rest_manager.get_endpoint("/downloads").tunnel_community = community
session.rest_manager.get_endpoint("/ipv8").endpoints["/tunnel"].tunnels = community
session.rest_manager.get_endpoint("/api/downloads").tunnel_community = community
session.rest_manager.get_endpoint("/api/ipv8").endpoints["/tunnel"].tunnels = community


@after("ContentDiscoveryComponent", "TorrentCheckerComponent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SearchEndpoint(RESTEndpoint):
This endpoint is responsible for searching in channels and torrents present in the local Tribler database.
"""

path = "/search"
path = "/api/search"

def __init__(self, middlewares: tuple = (), client_max_size: int = MAX_REQUEST_SIZE) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/database/restapi/database_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DatabaseEndpoint(RESTEndpoint):
/<public_key>
"""

path = "/metadata"
path = "/api/metadata"

def __init__(self, middlewares: tuple = (), client_max_size: int = MAX_REQUEST_SIZE) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/knowledge/restapi/knowledge_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class KnowledgeEndpoint(RESTEndpoint):
Top-level endpoint for knowledge management.
"""

path = "/knowledge"
path = "/api/knowledge"

def __init__(self, middlewares: tuple = (), client_max_size: int = MAX_REQUEST_SIZE) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CreateTorrentEndpoint(RESTEndpoint):
See: http://www.bittorrent.org/beps/bep_0012.html
"""

path = "/createtorrent"
path = "/api/createtorrent"

def __init__(self, download_manager: DownloadManager, client_max_size: int = MAX_REQUEST_SIZE) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/libtorrent/restapi/downloads_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DownloadsEndpoint(RESTEndpoint):
starting, pausing and stopping downloads.
"""

path = "/downloads"
path = "/api/downloads"

def __init__(self, download_manager: DownloadManager, metadata_store: MetadataStore | None = None,
tunnel_community: TriblerTunnelCommunity | None = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/libtorrent/restapi/libtorrent_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LibTorrentEndpoint(RESTEndpoint):
Endpoint for getting information about libtorrent sessions and settings.
"""

path = "/libtorrent"
path = "/api/libtorrent"

def __init__(self, download_manager: DownloadManager) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TorrentInfoEndpoint(RESTEndpoint):
This endpoint is responsible for handing all requests regarding torrent info in Tribler.
"""

path = "/torrentinfo"
path = "/api/torrentinfo"

def __init__(self, download_manager: DownloadManager) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/restapi/events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EventsEndpoint(RESTEndpoint):
indicates the type of the event. Individual events are separated by a newline character.
"""

path = "/events"
path = "/api/events"

def __init__(self, notifier: Notifier, public_key: str | None = None) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/restapi/ipv8_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class IPv8RootEndpoint(RootEndpoint, RESTEndpoint):
Make the IPv8 REST endpoint Tribler-compatible.
"""

path = "/ipv8"
path = "/api/ipv8"
2 changes: 1 addition & 1 deletion src/tribler/core/restapi/settings_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SettingsEndpoint(RESTEndpoint):
This endpoint is responsible for handing all requests regarding settings and configuration.
"""

path = "/settings"
path = "/api/settings"

def __init__(self, tribler_config: TriblerConfigManager, download_manager: DownloadManager = None) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/restapi/shutdown_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ShutdownEndpoint(RESTEndpoint):
With this endpoint you can shut down Tribler.
"""

path = "/shutdown"
path = "/api/shutdown"

def __init__(self, shutdown_callback: Callable[[], None]) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/restapi/statistics_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StatisticsEndpoint(RESTEndpoint):
This endpoint is responsible for handing requests regarding statistics in Tribler.
"""

path = "/statistics"
path = "/api/statistics"

def __init__(self, middlewares: tuple = (), client_max_size: int = MAX_REQUEST_SIZE) -> None:
"""
Expand Down
6 changes: 3 additions & 3 deletions src/tribler/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ async def start(self) -> None:
await self.ipv8.start()

# REST (2/2)
self.rest_manager.get_endpoint("/ipv8").initialize(self.ipv8)
self.rest_manager.get_endpoint("/statistics").ipv8 = self.ipv8
self.rest_manager.get_endpoint("/api/ipv8").initialize(self.ipv8)
self.rest_manager.get_endpoint("/api/statistics").ipv8 = self.ipv8
if self.config.get("statistics"):
self.rest_manager.get_endpoint("/ipv8").endpoints["/overlays"].enable_overlay_statistics(True, None, True)
self.rest_manager.get_endpoint("/api/ipv8").endpoints["/overlays"].enable_overlay_statistics(True, None, True)

async def shutdown(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/event_request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create_request(self) -> QNetworkRequest | None:
logger.warning("Can't create a request: api_port is not set (%d).", self.api_port)
return

url = QUrl(f"http://127.0.0.1:{self.api_port}/events")
url = QUrl(f"http://127.0.0.1:{self.api_port}/api/events")
request = QNetworkRequest(url)
request.setRawHeader(b'X-Api-Key', self.api_key.encode('ascii'))
return request
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/network/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
super().__init__()
self.logger = logging.getLogger(self.__class__.__name__)

self.endpoint = endpoint
self.endpoint = 'api/' + endpoint
self.url_params = url_params

self.priority = priority
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/test_unit/core/restapi/test_events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, endpoint: EventsEndpoint, count: int = 1) -> None:
Create a new GetEventsRequest.
"""
self.payload_writer = MockStreamWriter(endpoint, count=count)
super().__init__({}, "GET", "/events", payload_writer=self.payload_writer)
super().__init__({}, "GET", "/api/events", payload_writer=self.payload_writer)


class MockStreamWriter(AbstractStreamWriter):
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/test_unit/core/restapi/test_ipv8_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_binding(self) -> None:
endpoint = IPv8RootEndpoint()
endpoint.setup_routes()

self.assertEqual("/ipv8", endpoint.path)
self.assertEqual("/api/ipv8", endpoint.path)
self.assertIn("/asyncio", endpoint.endpoints)
self.assertIn("/attestation", endpoint.endpoints)
self.assertIn("/dht", endpoint.endpoints)
Expand Down

0 comments on commit c93f791

Please sign in to comment.