fix: use absolute tariff_end_at for expire_ts instead of now+remaining
This commit is contained in:
+5
-2
@@ -81,7 +81,9 @@ def clear_cache(sub_id: str = None):
|
|||||||
_links_cache.clear()
|
_links_cache.clear()
|
||||||
_traffic_cache.clear()
|
_traffic_cache.clear()
|
||||||
|
|
||||||
def get_remaining_days(user: dict) -> int:
|
def get_remaining_days(user) -> int:
|
||||||
|
if not isinstance(user, dict):
|
||||||
|
user = dict(user)
|
||||||
end = user.get("tariff_end_at", 0)
|
end = user.get("tariff_end_at", 0)
|
||||||
if end:
|
if end:
|
||||||
return max(0, (end - int(time.time())) // 86400)
|
return max(0, (end - int(time.time())) // 86400)
|
||||||
@@ -566,9 +568,10 @@ async def get_subscription(request: Request, subscription_id: str, format: str =
|
|||||||
if support_url:
|
if support_url:
|
||||||
lines.append(f"#support-url: {support_url}")
|
lines.append(f"#support-url: {support_url}")
|
||||||
|
|
||||||
expire_ts = 0
|
expire_ts = user.get("tariff_end_at", 0) or 0
|
||||||
rem_days = get_remaining_days(user)
|
rem_days = get_remaining_days(user)
|
||||||
if rem_days > 0:
|
if rem_days > 0:
|
||||||
|
if not expire_ts:
|
||||||
expire_ts = int((datetime.now() + timedelta(days=rem_days)).timestamp())
|
expire_ts = int((datetime.now() + timedelta(days=rem_days)).timestamp())
|
||||||
lines.append("#sub-expire: 1")
|
lines.append("#sub-expire: 1")
|
||||||
if support_url:
|
if support_url:
|
||||||
|
|||||||
Reference in New Issue
Block a user