Added local-file-system storage

This commit is contained in:
Mawoka
2022-04-01 22:25:09 +02:00
parent 918d778db0
commit 0ec7c2b519
8 changed files with 76 additions and 15 deletions
+7 -3
View File
@@ -1,19 +1,23 @@
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException
from fastapi.responses import StreamingResponse
from classquiz.config import settings
import io
import re
from classquiz.storage import Storage
settings = settings()
router = APIRouter()
file_regex = r"^[a-z0-9]{8}-[a-z0-9-]{27}--[a-z0-9-]{36}$"
@router.get('/download/{file_name}')
async def download_file(file_name: str):
storage = Storage(backend=settings.storage_backend, deta_key=settings.deta_project_key,
deta_id=settings.deta_project_id)
deta_id=settings.deta_project_id, storage_path=settings.storage_path)
download = await storage.download(file_name)
if not re.match(file_regex, file_name):
raise HTTPException(status_code=400, detail="Invalid file name")
def iter_file():
yield from download