?
This commit is contained in:
parent
3c5c7eb142
commit
4626fafef7
@ -1,4 +1,6 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter, HTTPException
|
||||||
|
import httpx
|
||||||
|
import json
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@ -6,6 +6,4 @@ load_dotenv(dotenv_path=Path(__file__).parent.parent / ".env")
|
|||||||
CLIENT_NAME = os.getenv("CLIENT_NAME", "default-client-name")
|
CLIENT_NAME = os.getenv("CLIENT_NAME", "default-client-name")
|
||||||
API_BASE = os.getenv("VRCHAT_API_BASE", "https://api.vrchat.cloud/api/1")
|
API_BASE = os.getenv("VRCHAT_API_BASE", "https://api.vrchat.cloud/api/1")
|
||||||
TOKEN_FILE = Path(os.getenv("TOKEN_FILE", "data/auth/account.json"))
|
TOKEN_FILE = Path(os.getenv("TOKEN_FILE", "data/auth/account.json"))
|
||||||
IS_RENDER = os.getenv("IS_RENDER", "false").lower() in ("true", "1", "t")
|
IS_RENDER = os.getenv("IS_RENDER", "false").lower() in ("true", "1", "t")
|
||||||
ACCOUNT_JSON_URL = os.getenv("ACCOUNT_JSON_URL", "https://example.com/vrcapi_render_download_acc.php")
|
|
||||||
ACCOUNT_JSON_TOKEN = os.getenv("ACCOUNT_JSON_TOKEN", "your-token-here")
|
|
@ -17,7 +17,7 @@ app = FastAPI(
|
|||||||
- Automatic token management with 2FA handling
|
- Automatic token management with 2FA handling
|
||||||
- Public and private VRChat data endpoints
|
- Public and private VRChat data endpoints
|
||||||
- Response caching for performance
|
- Response caching for performance
|
||||||
- Easy deployment on hosted servers (Render compatible)
|
- Easy deployment on self-hosted servers (YunoHost compatible)
|
||||||
|
|
||||||
Built with FastAPI and async HTTPX for high performance and reliability.
|
Built with FastAPI and async HTTPX for high performance and reliability.
|
||||||
""",
|
""",
|
||||||
|
@ -6,30 +6,12 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(str(Path(__file__).resolve().parent.parent))
|
sys.path.append(str(Path(__file__).resolve().parent.parent))
|
||||||
from app.env import CLIENT_NAME, API_BASE, TOKEN_FILE, IS_RENDER, ACCOUNT_JSON_URL, ACCOUNT_JSON_TOKEN
|
from env import CLIENT_NAME, API_BASE, TOKEN_FILE, IS_RENDER
|
||||||
|
|
||||||
if IS_RENDER:
|
if IS_RENDER:
|
||||||
import requests
|
print("⚠️ Running in Render environment, skipping VRChat auth.")
|
||||||
print("⚠️ Running in Render environment, downloading account.json with token in URL...")
|
|
||||||
|
|
||||||
url = f"{ACCOUNT_JSON_URL}?token={ACCOUNT_JSON_TOKEN}"
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
except requests.RequestException as e:
|
|
||||||
print(f"❌ Failed to download account.json: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
Path(TOKEN_FILE).parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
with open(TOKEN_FILE, "wb") as f:
|
|
||||||
f.write(response.content)
|
|
||||||
|
|
||||||
print("✅ account.json downloaded successfully.")
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def save_token(data):
|
def save_token(data):
|
||||||
data["created_at"] = datetime.now(timezone.utc).isoformat()
|
data["created_at"] = datetime.now(timezone.utc).isoformat()
|
||||||
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
15
render.yaml
15
render.yaml
@ -1,15 +0,0 @@
|
|||||||
services:
|
|
||||||
- type: web
|
|
||||||
name: vrchat-api
|
|
||||||
env: python
|
|
||||||
buildCommand: |
|
|
||||||
pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
startCommand: python run.py
|
|
||||||
envVars:
|
|
||||||
- key: CLIENT_NAME
|
|
||||||
value: YourAPIName/1.0
|
|
||||||
- key: VRCHAT_API_BASE
|
|
||||||
value: https://api.vrchat.cloud/api/1
|
|
||||||
- key: TOKEN_FILE
|
|
||||||
value: data/auth/account.json
|
|
@ -2,5 +2,4 @@ fastapi
|
|||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
httpx
|
httpx
|
||||||
orjson
|
orjson
|
||||||
python-dotenv
|
python-dotenv
|
||||||
requests
|
|
2
run.py
2
run.py
@ -43,7 +43,7 @@ def main():
|
|||||||
print("Virtual environment found.")
|
print("Virtual environment found.")
|
||||||
|
|
||||||
print("Running VRChat authentication script...")
|
print("Running VRChat authentication script...")
|
||||||
run_in_venv(["prelaunch/vrchat_auth.py"])
|
run_in_venv(["app/prelaunch/vrchat_auth.py"])
|
||||||
|
|
||||||
print("Starting FastAPI server...")
|
print("Starting FastAPI server...")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user