Update fastapi-vue-setup.
This commit is contained in:
1 parent
a9e6c2a145
commit
d24f9bdc77
3 files changed
+20
-21
No files matched your search
+18
-14
@@ -1,5 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi_vue import server
|
||||
@@ -8,6 +9,22 @@ DEFAULT_PORT = 8420
|
||||
DEVMODE = bool(os.getenv("MEDIAHIVE_FRONTEND_URL"))
|
||||
|
||||
|
||||
def resolve_media_root(path: str | None = None) -> Path:
|
||||
"""Resolve the media root folder from a path, MEDIAHIVE_PATH env, or cwd."""
|
||||
match Path(path or os.environ.get("MEDIAHIVE_PATH") or Path.cwd()).parts:
|
||||
case (*rest, ".mediahive", "index.json"):
|
||||
...
|
||||
case (*rest, ".mediahive"):
|
||||
...
|
||||
case rest:
|
||||
...
|
||||
mediaroot = Path(*rest).resolve()
|
||||
if not mediaroot.exists() or not mediaroot.is_dir():
|
||||
sys.stderr.write(f"Error: Folder does not exist: {mediaroot}\n")
|
||||
exit(1)
|
||||
return mediaroot
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="MediaHive - Media scanning, indexing, and streaming"
|
||||
@@ -26,20 +43,7 @@ def main():
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Determine media folder
|
||||
match Path(
|
||||
args.media_folder or os.environ.get("MEDIAHIVE_PATH") or Path.cwd()
|
||||
).parts:
|
||||
case (*rest, ".mediahive", "index.json"):
|
||||
...
|
||||
case (*rest, ".mediahive"):
|
||||
...
|
||||
case rest:
|
||||
...
|
||||
mediaroot = Path(*rest).resolve()
|
||||
if not mediaroot.exists() or not mediaroot.is_dir():
|
||||
print(f"Error: Folder does not exist: {mediaroot}")
|
||||
exit(1)
|
||||
mediaroot = resolve_media_root(args.media_folder)
|
||||
os.environ["MEDIAHIVE_PATH"] = mediaroot.as_posix()
|
||||
|
||||
dev = {"reload": True, "reload_dirs": ["mediahive"]}
|
||||
|
||||
@@ -31,7 +31,7 @@ def _check_node_version(node_path: str) -> None:
|
||||
"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[node_path, "--version"], capture_output=True, encoding="utf-8", check=True
|
||||
[node_path, "--version"], capture_output=True, text=True, check=True
|
||||
)
|
||||
version_str = result.stdout.strip()
|
||||
# Parse version like "v20.10.0" or "v18.17.1"
|
||||
|
||||
@@ -207,10 +207,5 @@ def setup_cli(
|
||||
host = endpoints[0]["host"]
|
||||
port = endpoints[0]["port"]
|
||||
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
cli,
|
||||
f"--listen={host}:{port}",
|
||||
]
|
||||
cmd = [cli, f"--listen={host}:{port}"]
|
||||
return f"http://{host}:{port}", cmd
|
||||
Reference in new issue
Block a user