fix content streaming
This commit is contained in:
1 parent
6e4893f59d
commit
9f949b3c09
2 files changed
+38
-6
No files matched your search
@@ -14,7 +14,9 @@ from app.core._config import CLIENT_TELEGRAM_API_KEY, CLIENT_TELEGRAM_BOT_USERNA
|
||||
from app.core.models.content_v3 import EncryptedContent as ECv3, ContentDerivative as CDv3, UploadSession
|
||||
from app.core.content.content_id import ContentId
|
||||
from app.core.network.dht import MetricsAggregator
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
|
||||
|
||||
@@ -303,9 +305,22 @@ async def s_api_v1_content_view(request, content_address: str):
|
||||
from app.core._crypto.signer import Signer
|
||||
from app.core._secrets import hot_seed, hot_pubkey
|
||||
from app.core._utils.b58 import b58encode as _b58e
|
||||
import time, json
|
||||
signer = Signer(hot_seed)
|
||||
exp = int(time.time()) + 600
|
||||
# Media URLs are polled very frequently by the web client (e.g. every 5s).
|
||||
# If we generate a new exp for every request, the signed URL changes every poll,
|
||||
# forcing the player to reload and breaking continuous streaming.
|
||||
#
|
||||
# To keep URLs stable while still expiring tokens, we "bucket" exp time.
|
||||
# Default behavior keeps tokens stable for ~10 minutes; can be tuned via env.
|
||||
ttl_sec = int(os.getenv("STORAGE_PROXY_TOKEN_TTL_SEC", "600"))
|
||||
bucket_sec = int(os.getenv("STORAGE_PROXY_TOKEN_BUCKET_SEC", str(ttl_sec)))
|
||||
ttl_sec = max(1, ttl_sec)
|
||||
bucket_sec = max(1, bucket_sec)
|
||||
now = int(time.time())
|
||||
exp_base = now + ttl_sec
|
||||
# Always move to the next bucket boundary so the token doesn't flip immediately
|
||||
# after a boundary due to rounding edge cases.
|
||||
exp = ((exp_base // bucket_sec) + 1) * bucket_sec
|
||||
uid = int(user_id or 0)
|
||||
payload = {'hash': hash_value, 'scope': scope, 'exp': exp, 'uid': uid}
|
||||
blob = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode()
|
||||
|
||||
Reference in new issue
Block a user