Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
aisbf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
aisbf
Commits
120a5c82
Commit
120a5c82
authored
May 10, 2026
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: migrate fastapi lifecycle hooks to lifespan
parent
2cccd183
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
main.py
main.py
+17
-5
No files found.
main.py
View file @
120a5c82
from
contextlib
import
asynccontextmanager
from
decimal
import
Decimal
from
decimal
import
Decimal
"""
"""
Copyleft (C) 2026 Stefy Lanza <stefy@nexlab.net>
Copyleft (C) 2026 Stefy Lanza <stefy@nexlab.net>
...
@@ -104,7 +105,20 @@ def _get_user_handler(handler_type: str, user_id=None):
...
@@ -104,7 +105,20 @@ def _get_user_handler(handler_type: str, user_id=None):
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# FastAPI app
# FastAPI app
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
app
=
FastAPI
(
title
=
"AI Proxy Server"
,
max_request_size
=
100
*
1024
*
1024
)
@
asynccontextmanager
async
def
lifespan
(
app
:
FastAPI
):
await
_run_startup
()
try
:
yield
finally
:
await
_run_shutdown
()
app
=
FastAPI
(
title
=
"AI Proxy Server"
,
max_request_size
=
100
*
1024
*
1024
,
lifespan
=
lifespan
,
)
_static_dir
=
Path
(
__file__
)
.
parent
/
'static'
_static_dir
=
Path
(
__file__
)
.
parent
/
'static'
_static_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
_static_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
...
@@ -236,8 +250,7 @@ async def _check_server_ip_country() -> None:
...
@@ -236,8 +250,7 @@ async def _check_server_ip_country() -> None:
logger
.
warning
(
f
"Could not determine server public IP country: {e}"
)
logger
.
warning
(
f
"Could not determine server public IP country: {e}"
)
@
app
.
on_event
(
"startup"
)
async
def
_run_startup
()
->
None
:
async
def
startup_event
():
global
_server_ip_blocked
global
_server_ip_blocked
await
_check_server_ip_country
()
await
_check_server_ip_country
()
...
@@ -344,8 +357,7 @@ async def startup_event():
...
@@ -344,8 +357,7 @@ async def startup_event():
logger
.
info
(
f
"Providers: {list(config.providers.keys()) if config else []}"
)
logger
.
info
(
f
"Providers: {list(config.providers.keys()) if config else []}"
)
@
app
.
on_event
(
"shutdown"
)
async
def
_run_shutdown
()
->
None
:
async
def
shutdown_event
():
tor_service
=
_app_state
.
get
(
'tor_service'
)
tor_service
=
_app_state
.
get
(
'tor_service'
)
if
tor_service
:
if
tor_service
:
tor_service
.
disconnect
()
tor_service
.
disconnect
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment