mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-13 14:08:33 +03:00
cleanup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,5 +9,6 @@ __pycache
|
|||||||
.env
|
.env
|
||||||
*.db
|
*.db
|
||||||
redis/data/*
|
redis/data/*
|
||||||
|
.ipynb_checkpoints*
|
||||||
#temp
|
#temp
|
||||||
tests
|
tests
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Auto Archiver API
|
# 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
|
## Development
|
||||||
@@ -25,6 +25,8 @@ check https://alembic.sqlalchemy.org/en/latest/tutorial.html#the-migration-envir
|
|||||||
* downgrade with `alembic downgrade -1`
|
* downgrade with `alembic downgrade -1`
|
||||||
|
|
||||||
## Release
|
## Release
|
||||||
|
Update `main.py:VERSION`.
|
||||||
|
|
||||||
Copy `.env` and `src/.env` to deployment, along with the contents of `secrets/` including `secrets/orchestration.yaml`.
|
Copy `.env` and `src/.env` to deployment, along with the contents of `secrets/` including `secrets/orchestration.yaml`.
|
||||||
|
|
||||||
Then `docker compose up -d`.
|
Then `docker compose up -d`.
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import os
|
|||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = os.environ.get("DATABASE_PATH")#"sqlite:///./auto-archiver.db"
|
SQLALCHEMY_DATABASE_URL = os.environ.get("DATABASE_PATH")#"sqlite:///./auto-archiver.db"
|
||||||
# SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db"
|
# SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db"
|
||||||
print("-"*50)
|
|
||||||
print(SQLALCHEMY_DATABASE_URL)
|
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
||||||
|
|||||||
18
src/main.py
18
src/main.py
@@ -1,7 +1,7 @@
|
|||||||
from celery.result import AsyncResult
|
from celery.result import AsyncResult
|
||||||
from fastapi import Body, FastAPI, Request, HTTPException, status, Depends
|
from fastapi import Body, FastAPI, Request, HTTPException, status, Depends
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse, FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
# from fastapi.templating import Jinja2Templates
|
# from fastapi.templating import Jinja2Templates
|
||||||
@@ -16,8 +16,6 @@ from db import crud, models, schemas
|
|||||||
from db.database import engine, SessionLocal
|
from db.database import engine, SessionLocal
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# models.Base.metadata.create_all(bind=engine)
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# Configuration
|
# 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(","))
|
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"
|
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(",")
|
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 = FastAPI()
|
||||||
app.add_middleware(
|
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)
|
"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("/")
|
@app.get("/")
|
||||||
def home():
|
def home():
|
||||||
|
|||||||
Reference in New Issue
Block a user