Browse Source

Bug proxy

master
scayac 3 weeks ago
parent
commit
de459417f7
  1. 12
      backend/app/audio_player.py
  2. 1
      backend/app/main.py
  3. 3
      backend/systemd/pysonnerie-backend.service
  4. 6
      frontend/app/backend_client.py
  5. 3
      frontend/systemd/pysonnerie-frontend.service

12
backend/app/audio_player.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
from __future__ import annotations
import logging
import shutil
import subprocess
import threading
from pathlib import Path
@ -86,12 +87,11 @@ class AudioPlayer: @@ -86,12 +87,11 @@ class AudioPlayer:
raise ValueError("end_seconds must be greater than start_seconds")
volume_factor = max(0.0, min(1.0, float(volume) / 100.0))
cmd = [
base_cmd = [
"play",
"-q",
"-v",
str(volume_factor),
str(music_path),
]
effects: list[str] = []
@ -134,14 +134,14 @@ class AudioPlayer: @@ -134,14 +134,14 @@ class AudioPlayer:
effects += ["repeat", str(int(repeat_count))]
# If sox lacks mp3 handlers, decode with ffmpeg and stream wav to sox.
if music_path.suffix.lower() == ".mp3":
if music_path.suffix.lower() == ".mp3" and shutil.which("ffmpeg"):
decoder_cmd = ["ffmpeg", "-v", "error", "-i", str(music_path), "-f", "wav", "-"]
self._decoder_proc = subprocess.Popen(
decoder_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
cmd += ["-t", "wav", "-"] + effects
cmd = base_cmd + ["-t", "wav", "-"] + effects
self._proc = subprocess.Popen(
cmd,
stdin=self._decoder_proc.stdout,
@ -151,7 +151,9 @@ class AudioPlayer: @@ -151,7 +151,9 @@ class AudioPlayer:
if self._decoder_proc.stdout is not None:
self._decoder_proc.stdout.close()
else:
cmd += [str(music_path)] + effects
if music_path.suffix.lower() == ".mp3":
logger.warning("ffmpeg unavailable, falling back to direct sox playback for %s", music_path)
cmd = base_cmd + [str(music_path)] + effects
self._proc = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def stop(self) -> None:

1
backend/app/main.py

@ -218,6 +218,7 @@ def force_play(trigger_id: str, repeat_count: int | None = None) -> Dict[str, st @@ -218,6 +218,7 @@ def force_play(trigger_id: str, repeat_count: int | None = None) -> Dict[str, st
except KeyError:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Unknown trigger")
except (FileNotFoundError, ValueError, RuntimeError) as exc:
logging.getLogger("pysonnerie.api").warning("Force play failed for %s: %s", trigger_id, exc)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
return {"status": "playing"}

3
backend/systemd/pysonnerie-backend.service

@ -7,9 +7,10 @@ Type=simple @@ -7,9 +7,10 @@ Type=simple
User=www-data
WorkingDirectory=/opt/pySonnerie/backend
Environment=PATH=/opt/pySonnerie/backend/.venv/bin:/usr/bin:/bin
Environment=NO_PROXY=127.0.0.1,localhost,::1
Environment=no_proxy=127.0.0.1,localhost,::1
#Environment=http_proxy=http://proxy:port
#Environment=https_proxy=http://proxy:port
#Environment=no_proxy=127.0.0.1,localhost
ExecStart=/opt/pySonnerie/backend/.venv/bin/python /opt/pySonnerie/backend/run.py
Restart=on-failure
RestartSec=3

6
frontend/app/backend_client.py

@ -40,11 +40,13 @@ class BackendClient: @@ -40,11 +40,13 @@ class BackendClient:
self.base_url = base_url.rstrip("/")
self.auth = (username, password)
self.timeout = 8
self.session = requests.Session()
self.session.trust_env = False
def _request(self, method: str, path: str, json_payload: dict[str, Any] | None = None) -> Any:
url = f"{self.base_url}{path}"
try:
response = requests.request(
response = self.session.request(
method=method,
url=url,
auth=self.auth,
@ -75,7 +77,7 @@ class BackendClient: @@ -75,7 +77,7 @@ class BackendClient:
def health(self) -> dict[str, Any]:
url = f"{self.base_url}/api/health"
try:
response = requests.get(url, timeout=self.timeout, verify=False)
response = self.session.get(url, timeout=self.timeout, verify=False)
response.raise_for_status()
return response.json()
except requests.RequestException as exc:

3
frontend/systemd/pysonnerie-frontend.service

@ -9,9 +9,10 @@ Group=www-data @@ -9,9 +9,10 @@ Group=www-data
WorkingDirectory=/opt/pySonnerie/frontend
Environment=FRONTEND_BIND=0.0.0.0:5000
Environment=PATH=/opt/pySonnerie/frontend/.venv/bin:/usr/bin:/bin
Environment=NO_PROXY=127.0.0.1,localhost,::1
Environment=no_proxy=127.0.0.1,localhost,::1
#Environment=http_proxy=http://TON_PROXY:PORT
#Environment=https_proxy=http://TON_PROXY:PORT
#Environment=no_proxy=127.0.0.1,localhost
ExecStart=/opt/pySonnerie/frontend/.venv/bin/gunicorn --workers 2 --bind ${FRONTEND_BIND} wsgi:app
Restart=on-failure
RestartSec=3

Loading…
Cancel
Save