Refactor with its own entry point and startup script cista, instead of running via sanic. Config file handling and Droppy updates. HTTP redirection/acme server added.

This commit is contained in:
Leo Vasanko
2023-10-19 02:06:14 +03:00
committed by Leo Vasanko
parent 429a7dfb16
commit 05c6f03d20
18 changed files with 247 additions and 51 deletions

34
cista/droppy.py Executable file
View File

@@ -0,0 +1,34 @@
from pathlib import Path
import msgspec
def readconf() -> dict:
p = Path.home() / ".droppy/config" # Hardcoded in Droppy
cf = msgspec.json.decode((p / "config.json").read_bytes())
db = msgspec.json.decode((p / "db.json").read_bytes())
cf["path"] = p.parent / "files"
cf["listen"] = _droppy_listeners(cf)
return cf | db
def _droppy_listeners(cf):
"""Convert Droppy listeners to our format, for typical cases but not in full."""
for listener in cf["listeners"]:
try:
if listener["protocol"] == "https":
# TODO: Add support for TLS
continue
socket = listener.get("socket")
if socket:
if isinstance(socket, list): socket = socket[0]
return f"{socket}"
port = listener["port"]
if isinstance(port, list): port = port[0]
host = listener["host"]
if isinstance(host, list): host = host[0]
if host in ("127.0.0.1", "::", "localhost"): return f":{port}"
return f"{host}:{port}"
except (KeyError, IndexError):
continue
# If none matched, fallback to Droppy default
return f"0.0.0.0:8989"