fix(identity): share one model-download user agent definition
Both model-download call sites built the User-Agent string separately: recognition_manager used a hardcoded literal while settings_dialog interpolated APP_ID. Add app_identity.user_agent() and use it in both, with a test pinning the shared definition. Fixes #17
This commit is contained in:
@@ -42,6 +42,12 @@ IBUS_TEXTDOMAIN: str = "voculinux"
|
||||
|
||||
UPDATE_CHECKER_USER_AGENT: str = "Voculinux-UpdateChecker"
|
||||
|
||||
|
||||
def user_agent(version: str) -> str:
|
||||
"""Outbound HTTP User-Agent for model downloads."""
|
||||
return f"{APP_ID}/{version}"
|
||||
|
||||
|
||||
RESOURCE_DIR_NAME: str = "voculinux"
|
||||
|
||||
VERIFICATION_STAMP_NAME: str = ".voculinux_verified"
|
||||
|
||||
@@ -27,7 +27,7 @@ if TYPE_CHECKING:
|
||||
import numpy as np
|
||||
import requests
|
||||
|
||||
from ..app_identity import APP_NAME, RESOURCE_DIR_NAME
|
||||
from ..app_identity import APP_NAME, RESOURCE_DIR_NAME, user_agent
|
||||
from ..audio.capture import ( # noqa: F401 (re-exported for compatibility)
|
||||
_STICKY_LOCK_MIN_MEAN_SQUARE,
|
||||
CaptureStalledError,
|
||||
@@ -2731,7 +2731,7 @@ class SpeechRecognitionManager:
|
||||
url,
|
||||
stream=True,
|
||||
timeout=self._MODEL_DOWNLOAD_TIMEOUT,
|
||||
headers={"User-Agent": f"voculinux/{__version__}"},
|
||||
headers={"User-Agent": user_agent(__version__)},
|
||||
proxies=requests_proxies(),
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
|
||||
@@ -36,7 +36,7 @@ gi.require_version("Gdk", "3.0")
|
||||
# Need GLib for idle_add
|
||||
from gi.repository import Gdk, GLib, GObject, Gtk, Pango # noqa: E402
|
||||
|
||||
from ..app_identity import APP_ID, APP_NAME, RESOURCE_DIR_NAME # noqa: E402
|
||||
from ..app_identity import APP_NAME, RESOURCE_DIR_NAME, user_agent # noqa: E402
|
||||
from ..audio.pulse_sources import ( # noqa: E402
|
||||
PULSE_INDEX_BASE,
|
||||
PulseSource,
|
||||
@@ -6461,7 +6461,7 @@ class SettingsDialog(AboutSectionMixin):
|
||||
try:
|
||||
response = requests.get(
|
||||
"https://huggingface.co/api/models/ggerganov/whisper.cpp",
|
||||
headers={"User-Agent": f"{APP_ID}/{__version__}"},
|
||||
headers={"User-Agent": user_agent(__version__)},
|
||||
timeout=10,
|
||||
proxies=requests_proxies(config),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user