Skip to content

Commit 830695c

Browse files
authored
Merge pull request #83 from geotribu/feature/add-route-to-download-qfield-plugin
feat(qchat): add endpoint for downloading latest QChat QField plugin version
2 parents 804a1fc + 5020584 commit 830695c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

gischat/app.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from io import BytesIO
77
from uuid import UUID
88

9+
import httpx
910
import redis.asyncio as redis
1011
import sentry_sdk
11-
from fastapi import FastAPI, HTTPException, Request, WebSocket
12+
from fastapi import FastAPI, HTTPException, Request, Response, WebSocket
1213
from fastapi.encoders import jsonable_encoder
13-
from fastapi.responses import HTMLResponse
14+
from fastapi.responses import HTMLResponse, StreamingResponse
1415
from fastapi.templating import Jinja2Templates
1516
from PIL import Image
1617
from pydantic import ValidationError
@@ -148,6 +149,31 @@ async def get_version() -> VersionModel:
148149
return VersionModel(version=get_poetry_version())
149150

150151

152+
QFIELD_PLUGIN_LATEST_DOWNLOAD_URL = "https://github.com/geotribu/qchat-qfield-plugin/releases/latest/download/qfchat-latest.zip"
153+
154+
155+
@app.get("/qfield")
156+
async def get_latest_qfield_plugin() -> Response:
157+
async with httpx.AsyncClient() as client:
158+
remote_response = await client.get(
159+
QFIELD_PLUGIN_LATEST_DOWNLOAD_URL, follow_redirects=True
160+
)
161+
162+
if remote_response.status_code != 200:
163+
return Response(
164+
content="Error while downloading latest QField plugin",
165+
status_code=remote_response.status_code,
166+
)
167+
168+
return StreamingResponse(
169+
remote_response.aiter_bytes(),
170+
media_type=remote_response.headers.get(
171+
"content-type", "application/octet-stream"
172+
),
173+
headers={"Content-Disposition": 'attachment; filename="qfchat-latest.zip"'},
174+
)
175+
176+
151177
@app.get("/channels", response_model=list[str])
152178
async def get_channels() -> list[str]:
153179
return redis_dispatcher.channels

0 commit comments

Comments
 (0)