Fix Flask app context error in SSE stream route
This commit is contained in:
5
app.py
5
app.py
@@ -358,8 +358,11 @@ def api_download():
|
||||
@login_required
|
||||
def stream_download(download_id):
|
||||
download = Download.query.get_or_404(download_id)
|
||||
download_id_val = download.id
|
||||
|
||||
def generate():
|
||||
with app.app_context():
|
||||
download = Download.query.get(download_id_val)
|
||||
last_len = 0
|
||||
while True:
|
||||
db.session.refresh(download)
|
||||
@@ -371,7 +374,7 @@ def stream_download(download_id):
|
||||
yield data
|
||||
last_len = current_len
|
||||
|
||||
if download.status in ('completed', 'error'):
|
||||
if download.status in ('completed', 'error', 'cancelled'):
|
||||
data = f"data: {download.id}|{download.status}|{download.progress}|__END__\n\n"
|
||||
yield data
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user