From 9e92bef32c16f76cffe87421267d377774fe78ea Mon Sep 17 00:00:00 2001 From: ShowierData9978 Date: Mon, 12 Aug 2024 22:53:33 -0500 Subject: [PATCH] Chore: Refactor v0 into v0 folder. --- rest_api/__init__.py | 37 +++++++++++++------------------------ rest_api/v0/__init__.py | 22 ++++++++++++++++++++++ rest_api/{ => v0}/auth.py | 0 rest_api/{ => v0}/chats.py | 0 rest_api/{ => v0}/home.py | 0 rest_api/{ => v0}/inbox.py | 0 rest_api/{ => v0}/me.py | 0 rest_api/{ => v0}/posts.py | 0 rest_api/{ => v0}/search.py | 0 rest_api/{ => v0}/users.py | 0 10 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 rest_api/v0/__init__.py rename rest_api/{ => v0}/auth.py (100%) rename rest_api/{ => v0}/chats.py (100%) rename rest_api/{ => v0}/home.py (100%) rename rest_api/{ => v0}/inbox.py (100%) rename rest_api/{ => v0}/me.py (100%) rename rest_api/{ => v0}/posts.py (100%) rename rest_api/{ => v0}/search.py (100%) rename rest_api/{ => v0}/users.py (100%) diff --git a/rest_api/__init__.py b/rest_api/__init__.py index 00b452a..bd76c2d 100755 --- a/rest_api/__init__.py +++ b/rest_api/__init__.py @@ -4,14 +4,9 @@ from pydantic import BaseModel import time, os -from .auth import auth_bp -from .me import me_bp -from .home import home_bp -from .inbox import inbox_bp -from .posts import posts_bp -from .users import users_bp -from .chats import chats_bp -from .search import search_bp +from .v0 import v0 + + from .admin import admin_bp from database import db, blocked_ips, registration_blocked_ips @@ -97,7 +92,7 @@ async def check_auth(headers: TokenHeader): @app.get("/") # Welcome message async def index(): - return { + return { "captcha": { "enabled": os.getenv("CAPTCHA_SECRET") is not None, "sitekey": os.getenv("CAPTCHA_SITEKEY") @@ -108,7 +103,7 @@ async def index(): @app.get("/favicon.ico") # Favicon, my ass. We need no favicon for an API. @hide async def favicon_my_ass(): - return "", 200 + return "", 200 @app.get("/status") @@ -167,12 +162,12 @@ async def validation_error(e): @app.errorhandler(400) # Bad request async def bad_request(e): - return {"error": True, "type": "badRequest"}, 400 + return {"error": True, "type": "badRequest"}, 400 @app.errorhandler(401) # Unauthorized async def unauthorized(e): - return {"error": True, "type": "Unauthorized"}, 401 + return {"error": True, "type": "Unauthorized"}, 401 @app.errorhandler(403) # Missing permissions @@ -182,22 +177,22 @@ async def missing_permissions(e): @app.errorhandler(404) # We do need a 404 handler. async def not_found(e): - return {"error": True, "type": "notFound"}, 404 + return {"error": True, "type": "notFound"}, 404 @app.errorhandler(405) # Method not allowed async def method_not_allowed(e): - return {"error": True, "type": "methodNotAllowed"}, 405 + return {"error": True, "type": "methodNotAllowed"}, 405 @app.errorhandler(429) # Too many requests async def too_many_requests(e): - return {"error": True, "type": "tooManyRequests"}, 429 + return {"error": True, "type": "tooManyRequests"}, 429 @app.errorhandler(500) # Internal async def internal(e): - return {"error": True, "type": "Internal"}, 500 + return {"error": True, "type": "Internal"}, 500 @app.errorhandler(501) # Not implemented @@ -206,12 +201,6 @@ async def not_implemented(e): # Register blueprints -app.register_blueprint(auth_bp) -app.register_blueprint(me_bp) -app.register_blueprint(home_bp) -app.register_blueprint(inbox_bp) -app.register_blueprint(posts_bp) -app.register_blueprint(users_bp) -app.register_blueprint(chats_bp) -app.register_blueprint(search_bp) app.register_blueprint(admin_bp) +app.register_blueprint(v0, url_prefix="/v0") +app.register_blueprint(v0, url_prefix="/", name="root") \ No newline at end of file diff --git a/rest_api/v0/__init__.py b/rest_api/v0/__init__.py new file mode 100644 index 0000000..3cce37f --- /dev/null +++ b/rest_api/v0/__init__.py @@ -0,0 +1,22 @@ +from quart import Blueprint + +from .search import search_bp +from .chats import chats_bp +from .inbox import inbox_bp +from .posts import posts_bp +from .users import users_bp +from .auth import auth_bp +from .home import home_bp +from .me import me_bp + +v0 = Blueprint("v0", __name__) + +v0.register_blueprint(auth_bp) +v0.register_blueprint(me_bp) +v0.register_blueprint(home_bp) +v0.register_blueprint(inbox_bp) +v0.register_blueprint(posts_bp) +v0.register_blueprint(users_bp) +v0.register_blueprint(chats_bp) +v0.register_blueprint(search_bp) + diff --git a/rest_api/auth.py b/rest_api/v0/auth.py similarity index 100% rename from rest_api/auth.py rename to rest_api/v0/auth.py diff --git a/rest_api/chats.py b/rest_api/v0/chats.py similarity index 100% rename from rest_api/chats.py rename to rest_api/v0/chats.py diff --git a/rest_api/home.py b/rest_api/v0/home.py similarity index 100% rename from rest_api/home.py rename to rest_api/v0/home.py diff --git a/rest_api/inbox.py b/rest_api/v0/inbox.py similarity index 100% rename from rest_api/inbox.py rename to rest_api/v0/inbox.py diff --git a/rest_api/me.py b/rest_api/v0/me.py similarity index 100% rename from rest_api/me.py rename to rest_api/v0/me.py diff --git a/rest_api/posts.py b/rest_api/v0/posts.py similarity index 100% rename from rest_api/posts.py rename to rest_api/v0/posts.py diff --git a/rest_api/search.py b/rest_api/v0/search.py similarity index 100% rename from rest_api/search.py rename to rest_api/v0/search.py diff --git a/rest_api/users.py b/rest_api/v0/users.py similarity index 100% rename from rest_api/users.py rename to rest_api/v0/users.py