diff --git a/mwmbl/main.py b/mwmbl/main.py index d1231d9..fa5e1c5 100644 --- a/mwmbl/main.py +++ b/mwmbl/main.py @@ -12,6 +12,7 @@ from mwmbl import background from mwmbl.crawler import app as crawler from mwmbl.indexer.batch_cache import BatchCache from mwmbl.indexer.paths import INDEX_NAME, BATCH_DIR_NAME +from mwmbl.platform import user from mwmbl.tinysearchengine import search from mwmbl.tinysearchengine.completer import Completer from mwmbl.tinysearchengine.indexer import TinyIndex, Document, NUM_PAGES, PAGE_SIZE @@ -72,6 +73,9 @@ def run(): crawler_router = crawler.get_router(batch_cache, url_queue) app.include_router(crawler_router) + user_router = user.create_router() + app.include_router(user_router) + # Initialize uvicorn server using global app instance and server config params uvicorn.run(app, host="0.0.0.0", port=5000) diff --git a/mwmbl/platform/__init__.py b/mwmbl/platform/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mwmbl/platform/user.py b/mwmbl/platform/user.py new file mode 100644 index 0000000..cf06fe0 --- /dev/null +++ b/mwmbl/platform/user.py @@ -0,0 +1,29 @@ +import os +from urllib.parse import urljoin + +import requests +from fastapi import APIRouter, Response +from pydantic import BaseModel +from starlette.responses import JSONResponse + +LEMMY_URL = os.environ["LEMMY_URL"] + + +class Register(BaseModel): + username: str + email: str + password: str + password_verify: str + + +def create_router() -> APIRouter: + router = APIRouter(prefix="/user", tags=["user"]) + + @router.post("/register") + def register_user(register: Register) -> Response: + request = requests.post(urljoin(LEMMY_URL, "api/v3/user/register"), json=register.json()) + print("Request", request) + # TODO: add in missing fields with null values from here: https://join-lemmy.org/api/classes/Register.html + return Response(content=request.content, status_code=request.status_code, media_type="text/json") + + return router