diff --git a/pinnwand/http.py b/pinnwand/http.py index f0abce9..918f1e0 100644 --- a/pinnwand/http.py +++ b/pinnwand/http.py @@ -238,6 +238,18 @@ async def post(self) -> None: ) +class APILexers(Base): + async def get(self) -> None: + self.write(utility.list_languages()) + + +class APIExpiries(Base): + async def get(self) -> None: + self.write( + {name: str(delta) for name, delta in utility.expiries.items()} + ) + + class RemovalPage(Base): """Serve the removal page.""" @@ -273,6 +285,8 @@ def make_application() -> tornado.web.Application: (r"/json/new", APINew), (r"/json/remove", APIRemove), (r"/json/show/(.*)", APIShow), + (r"/json/lexers", APILexers), + (r"/json/expiries", APIExpiries), ( r"/static/(.*)", tornado.web.StaticFileHandler, diff --git a/test/test_http.py b/test/test_http.py index 5f93096..57407c3 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -7,6 +7,7 @@ from pinnwand import http from pinnwand import database +from pinnwand import utility class WebsiteTestCase(tornado.testing.AsyncHTTPTestCase): @@ -149,3 +150,15 @@ def test_api_remove(self) -> None: response = self.fetch(f"/json/show/{data['paste_id']}") assert response.code == 404 + + def test_api_get_lexers(self) -> None: + response = self.fetch("/json/lexers", method="GET") + + assert response.code == 200 + assert json.loads(response.body) == utility.list_languages() + + def test_api_get_expiries(self) -> None: + response = self.fetch("/json/expiries", method="GET") + + assert response.code == 200 + assert json.loads(response.body).keys() == utility.expiries.keys()