-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
99 lines (77 loc) · 2.9 KB
/
Copy pathmain.py
File metadata and controls
99 lines (77 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# import
from brotli_asgi import BrotliMiddleware
from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, ORJSONResponse, RedirectResponse
from routers.altacm import altacm
from objects import Errors
from routers.blogs import blog_methods
from routers.chats import chats
from routers.communities import communities
from routers.configurations import configurations
from routers.links import links
from routers.logregin import logregin
# routers
from routers.mock import mock
from routers.moderation_tools import moderation_tools
from routers.profile import profile_methods
from routers.turtle import turtle
from routers.upload_media import upload_media
# app things
app = FastAPI(title="AltAmino", version="1", docs_url=None, redoc_url=None)
@app.get("/")
async def redirect():
return RedirectResponse("https://altamino.top")
@app.get("/health")
async def health():
return {"alive": True}
app.include_router(mock, prefix="/api/v1")
app.include_router(chats, prefix="/api/v1")
app.include_router(turtle, prefix="/api/v1")
app.include_router(links, prefix="/api/v1")
app.include_router(logregin, prefix="/api/v1")
app.include_router(upload_media, prefix="/api/v1")
app.include_router(configurations, prefix="/api/v1")
app.include_router(profile_methods, prefix="/api/v1")
app.include_router(communities, prefix="/api/v1")
app.include_router(blog_methods, prefix="/api/v1")
app.include_router(moderation_tools, prefix="/api/v1")
app.include_router(altacm, prefix="/api/v1")
# brotli can break amino libraries, but it's easy to fix
# either enable support for brotli, or just remove "brotli" from headers
app.add_middleware(BrotliMiddleware, gzip_fallback=True)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # dont be like us, configure it, im lazy to do it rn
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(403)
async def custom_403_handler(_, __):
return Errors.Forbidden()
@app.exception_handler(404)
@app.exception_handler(405)
async def custom_404_handler(_, __):
print("No path like: ", _.url.path, "(", await _.body(), ") | ", __)
return Errors.InvalidPath()
@app.exception_handler(422)
@app.exception_handler(RequestValidationError)
async def custom_422_handler(_, exc: RequestValidationError):
print(exc.errors())
return Errors.CantProcessData()
@app.exception_handler(500)
async def custom_500_handler(_, __):
try:
if isinstance(__.args[0], ORJSONResponse) or isinstance(
__.args[0], JSONResponse
):
return __.args[0]
except Exception:
print("Not a status code that we returned!")
try:
print("What happened:", _, "//", __)
except Exception:
print("WE CAN'T EVEN FUCKING PRINT WHAT HAPPENED. COOL")
return Errors.InternalServerError()