diff --git a/requirements.txt b/requirements.txt index d7d8990..dbed088 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,9 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # + # pip-compile --output-file=requirements.txt requirements.in + # annotated-types==0.7.0 # via pydantic diff --git a/src/ssoss/api.py b/src/ssoss/api.py new file mode 100644 index 0000000..0a377f6 --- /dev/null +++ b/src/ssoss/api.py @@ -0,0 +1,37 @@ +from fastapi import FastAPI, UploadFile, File, HTTPException +from pathlib import Path +import shutil + +app = FastAPI() + +UPLOAD_DIR = Path("uploads") +UPLOAD_DIR.mkdir(parents=True, exist_ok=True) + + +def _save_upload(upload: UploadFile, allowed_exts: set[str]): + ext = Path(upload.filename).suffix.lower() + if ext not in allowed_exts: + raise HTTPException(status_code=400, detail="Invalid file type") + dest = UPLOAD_DIR / upload.filename + with dest.open("wb") as buffer: + shutil.copyfileobj(upload.file, buffer) + return {"filename": upload.filename} + + +@app.post("/upload/csv") +async def upload_csv(file: UploadFile = File(...)): + """Accept a CSV file upload.""" + return _save_upload(file, {".csv"}) + + +@app.post("/upload/gpx") +async def upload_gpx(file: UploadFile = File(...)): + """Accept a GPX file upload.""" + return _save_upload(file, {".gpx"}) + + +@app.post("/upload/video") +async def upload_video(file: UploadFile = File(...)): + """Accept a video file upload.""" + # Accept a few common video extensions + return _save_upload(file, {".mp4", ".mov", ".avi", ".mkv"})