diff --git a/.gitignore b/.gitignore index abf4544..af01c42 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ __pycache .env *.db redis/data/* +.ipynb_checkpoints* #temp tests diff --git a/README.md b/README.md index 180ebe7..9520cf7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Auto Archiver API -An api that uses celery workers to process URL archive requests via [bellingcat/auto-archiver](), it allows authentication via Google OAuth Apps an d enables CORS, everything runs on docker but development can be done without docker (except for redis). +An api that uses celery workers to process URL archive requests via [bellingcat/auto-archiver](https://github.com/bellingcat/auto-archiver), it allows authentication via Google OAuth Apps an d enables CORS, everything runs on docker but development can be done without docker (except for redis). ## Development @@ -25,6 +25,8 @@ check https://alembic.sqlalchemy.org/en/latest/tutorial.html#the-migration-envir * downgrade with `alembic downgrade -1` ## Release +Update `main.py:VERSION`. + Copy `.env` and `src/.env` to deployment, along with the contents of `secrets/` including `secrets/orchestration.yaml`. Then `docker compose up -d`. diff --git a/src/db/database.py b/src/db/database.py index 55c47ea..8c425a0 100644 --- a/src/db/database.py +++ b/src/db/database.py @@ -5,8 +5,6 @@ import os SQLALCHEMY_DATABASE_URL = os.environ.get("DATABASE_PATH")#"sqlite:///./auto-archiver.db" # SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db" -print("-"*50) -print(SQLALCHEMY_DATABASE_URL) engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} diff --git a/src/main.py b/src/main.py index 873afbc..e1e829a 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,7 @@ from celery.result import AsyncResult from fastapi import Body, FastAPI, Request, HTTPException, status, Depends from fastapi.encoders import jsonable_encoder -from fastapi.responses import JSONResponse +from fastapi.responses import JSONResponse, FileResponse from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware # from fastapi.templating import Jinja2Templates @@ -16,8 +16,6 @@ from db import crud, models, schemas from db.database import engine, SessionLocal from sqlalchemy.orm import Session -# models.Base.metadata.create_all(bind=engine) - load_dotenv() # Configuration @@ -26,7 +24,7 @@ assert len(GOOGLE_CHROME_APP_ID)>10, "GOOGLE_CHROME_APP_ID env variable not set" ALLOWED_EMAILS = set(os.environ.get("ALLOWED_EMAILS", "").split(",")) assert len(GOOGLE_CHROME_APP_ID)>=1, "at least one ALLOWED_EMAILS is required from the env variable" ALLOWED_ORIGINS = os.environ.get("ALLOWED_ORIGINS", "chrome-extension://ondkcheoicfckabcnkdgbepofpjmjcmb,chrome-extension://ojcimmjndnlmmlgnjaeojoebaceokpdp").split(",") -VERSION = "0.1.6" +VERSION = "0.1.7" app = FastAPI() app.add_middleware( @@ -98,6 +96,18 @@ def get_status(task_id, access_token:str, db: Session = Depends(get_db)): "deleted": crud.soft_delete_task(db, task_id, email) }) +# logic to allow access to 1 static file +SF = os.environ.get("STATIC_FILE", "") +SFP = os.environ.get("STATIC_FILE_PASSWORD", "") # min length is 20 chars +if len(SF) > 1 and len(SFP) >= 20 and os.path.isfile(SF): + @app.get("/static-file") + def static_file(static_file_password:str): + if type(static_file_password) ==str and len(static_file_password)>=20 and static_file_password==SFP: + return FileResponse(SF, filename=os.path.basename(SF)) + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Wrong static file access credentials" + ) @app.get("/") def home():