|
6 | 6 | from io import BytesIO |
7 | 7 | from uuid import UUID |
8 | 8 |
|
| 9 | +import httpx |
9 | 10 | import redis.asyncio as redis |
10 | 11 | import sentry_sdk |
11 | | -from fastapi import FastAPI, HTTPException, Request, WebSocket |
| 12 | +from fastapi import FastAPI, HTTPException, Request, Response, WebSocket |
12 | 13 | from fastapi.encoders import jsonable_encoder |
13 | | -from fastapi.responses import HTMLResponse |
| 14 | +from fastapi.responses import HTMLResponse, StreamingResponse |
14 | 15 | from fastapi.templating import Jinja2Templates |
15 | 16 | from PIL import Image |
16 | 17 | from pydantic import ValidationError |
@@ -148,6 +149,31 @@ async def get_version() -> VersionModel: |
148 | 149 | return VersionModel(version=get_poetry_version()) |
149 | 150 |
|
150 | 151 |
|
| 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 | + |
151 | 177 | @app.get("/channels", response_model=list[str]) |
152 | 178 | async def get_channels() -> list[str]: |
153 | 179 | return redis_dispatcher.channels |
|
0 commit comments