forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshare_links.py
More file actions
46 lines (33 loc) · 1.37 KB
/
Copy pathshare_links.py
File metadata and controls
46 lines (33 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Public share-link base URL for self-hosting (#4339).
Default production host remains ``https://h.omi.me``. Override with
``OMI_SHARE_BASE_URL`` (scheme + host, optional path prefix, no trailing slash).
"""
from __future__ import annotations
import os
from urllib.parse import urlsplit
DEFAULT_SHARE_BASE_URL = 'https://h.omi.me'
_ENV_KEY = 'OMI_SHARE_BASE_URL'
def share_base_url() -> str:
"""Return the configured share origin (no trailing slash)."""
raw = (os.getenv(_ENV_KEY) or DEFAULT_SHARE_BASE_URL).strip()
if not raw:
raw = DEFAULT_SHARE_BASE_URL
if '://' not in raw:
raw = f'https://{raw}'
return raw.rstrip('/')
def share_host() -> str:
"""Hostname used when minting share URLs (lowercase netloc without userinfo)."""
parsed = urlsplit(share_base_url())
return (parsed.hostname or 'h.omi.me').lower()
def accepted_share_hosts() -> frozenset[str]:
"""Hosts accepted when parsing inbound share URLs.
Always includes the production default so existing ``h.omi.me`` links keep
resolving even when ``OMI_SHARE_BASE_URL`` is customized.
"""
hosts = {share_host(), 'h.omi.me'}
return frozenset(hosts)
def build_share_url(path: str) -> str:
"""Join ``share_base_url()`` with a path that starts with ``/``."""
if not path.startswith('/'):
path = f'/{path}'
return f'{share_base_url()}{path}'