added config
This commit is contained in:
parent
80b9cba5f3
commit
009d7fcab3
@ -16,8 +16,10 @@ sudo -Hu fba git clone https://gitlab.com/EnjuAihara/fedi-block-api.git /opt/fed
|
|||||||
cd /opt/fedi-block-api
|
cd /opt/fedi-block-api
|
||||||
sudo -Hu fba pip3 install -r requirements.txt
|
sudo -Hu fba pip3 install -r requirements.txt
|
||||||
sudo -Hu fba cp blocks_preloaded.db blocks.db
|
sudo -Hu fba cp blocks_preloaded.db blocks.db
|
||||||
|
sudo -Hu fba cp config.defaults.json config.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Install the services
|
### Install the services
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
14
api.py
14
api.py
@ -1,10 +1,15 @@
|
|||||||
|
import uvicorn
|
||||||
from fastapi import FastAPI, Request, HTTPException, responses
|
from fastapi import FastAPI, Request, HTTPException, responses
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from requests import get
|
from requests import get
|
||||||
|
from json import loads
|
||||||
|
|
||||||
base_url = ""
|
with open("config.json") as f:
|
||||||
|
config = loads(f.read())
|
||||||
|
base_url = config["base_url"]
|
||||||
|
port = config["port"]
|
||||||
app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
|
app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
|
||||||
templates = Jinja2Templates(directory=".")
|
templates = Jinja2Templates(directory=".")
|
||||||
|
|
||||||
@ -57,13 +62,16 @@ def blocked(domain: str = None):
|
|||||||
def index(request: Request, domain: str = None):
|
def index(request: Request, domain: str = None):
|
||||||
if domain == "":
|
if domain == "":
|
||||||
return responses.RedirectResponse("/")
|
return responses.RedirectResponse("/")
|
||||||
blocks = get(f"http://127.0.0.1:8069{base_url}/api?domain={domain}")
|
blocks = get(f"http://127.0.0.1:{port}{base_url}/api?domain={domain}")
|
||||||
info = None
|
info = None
|
||||||
if domain == None:
|
if domain == None:
|
||||||
info = get(f"http://127.0.0.1:8069{base_url}/info")
|
info = get(f"http://127.0.0.1:{port}{base_url}/info")
|
||||||
if not info.ok:
|
if not info.ok:
|
||||||
raise HTTPException(status_code=info.status_code, detail=info.text)
|
raise HTTPException(status_code=info.status_code, detail=info.text)
|
||||||
info = info.json()
|
info = info.json()
|
||||||
if not blocks.ok:
|
if not blocks.ok:
|
||||||
raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
|
raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
|
||||||
return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks.json(), "info": info})
|
return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks.json(), "info": info})
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
uvicorn.run("api:app", host="127.0.0.1", port=port, log_level="info")
|
||||||
|
4
config.defaults.json
Normal file
4
config.defaults.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"base_url": "",
|
||||||
|
"port": 8069
|
||||||
|
}
|
@ -7,7 +7,7 @@ Restart=on-failure
|
|||||||
RestartSec=10
|
RestartSec=10
|
||||||
User=fba
|
User=fba
|
||||||
WorkingDirectory=/opt/fedi-block-api
|
WorkingDirectory=/opt/fedi-block-api
|
||||||
ExecStart=uvicorn api:app --port 8069
|
ExecStart=python3 api.py
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
Loading…
x
Reference in New Issue
Block a user