Skip to content

Commit

Permalink
Merge pull request #275 from meower-media-co/v0-refactor
Browse files Browse the repository at this point in the history
Chore: Refactor v0 into v0 folder.
  • Loading branch information
tnix100 authored Aug 13, 2024
2 parents c766c82 + 9e92bef commit a92fccc
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
37 changes: 13 additions & 24 deletions rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
22 changes: 22 additions & 0 deletions rest_api/v0/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a92fccc

Please sign in to comment.