Add API for managing tariff configurator / Improved version 0.4.0 (Alpha)
This commit is contained in:
+2
-2
@@ -2,8 +2,8 @@ from fastapi import FastAPI
|
||||
from api.routes import coupons, gifts, keys, misc, referrals, servers, settings, tariffs, users
|
||||
|
||||
app = FastAPI(
|
||||
title="SoloBot API (preAlpha)",
|
||||
version="0.3.0",
|
||||
title="SoloBot API (Alpha)",
|
||||
version="0.4.0",
|
||||
docs_url="/api/docs",
|
||||
redoc_url="/api/redoc",
|
||||
openapi_url="/api/openapi.json",
|
||||
|
||||
+20
-4
@@ -93,15 +93,31 @@ async def edit_key_by_email(
|
||||
setattr(db_key, field, value)
|
||||
|
||||
try:
|
||||
new_expiry_time = db_key.expiry_time
|
||||
tariff = None
|
||||
if db_key.tariff_id is not None:
|
||||
tariff_result = await session.execute(select(Tariff).where(Tariff.id == db_key.tariff_id))
|
||||
tariff = tariff_result.scalar_one_or_none()
|
||||
|
||||
total_gb = db_key.current_traffic_limit
|
||||
if total_gb is None:
|
||||
total_gb = db_key.selected_traffic_limit
|
||||
if total_gb is None and tariff is not None:
|
||||
total_gb = tariff.traffic_limit
|
||||
|
||||
hwid_device_limit = db_key.current_device_limit
|
||||
if hwid_device_limit is None:
|
||||
hwid_device_limit = db_key.selected_device_limit
|
||||
if hwid_device_limit is None and tariff is not None:
|
||||
hwid_device_limit = tariff.device_limit
|
||||
|
||||
await renew_key_in_cluster(
|
||||
cluster_id=db_key.server_id,
|
||||
email=db_key.email,
|
||||
client_id=db_key.client_id,
|
||||
new_expiry_time=new_expiry_time,
|
||||
total_gb=getattr(db_key, "traffic_limit", None),
|
||||
new_expiry_time=db_key.expiry_time,
|
||||
total_gb=total_gb,
|
||||
session=session,
|
||||
hwid_device_limit=getattr(db_key, "device_limit", None),
|
||||
hwid_device_limit=hwid_device_limit,
|
||||
reset_traffic=True,
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
@@ -16,6 +16,13 @@ class KeyBase(BaseModel):
|
||||
notified: bool | None = False
|
||||
notified_24h: bool | None = False
|
||||
|
||||
selected_device_limit: int | None = None
|
||||
selected_traffic_limit: int | None = None
|
||||
selected_price_rub: int | None = None
|
||||
|
||||
current_device_limit: int | None = None
|
||||
current_traffic_limit: int | None = None
|
||||
|
||||
|
||||
class KeyResponse(KeyBase):
|
||||
class Config:
|
||||
@@ -41,6 +48,13 @@ class KeyDetailsResponse(BaseModel):
|
||||
location_name: str | None
|
||||
tariff_id: int | None
|
||||
|
||||
selected_device_limit: int | None = None
|
||||
selected_traffic_limit: int | None = None
|
||||
selected_price_rub: int | None = None
|
||||
|
||||
current_device_limit: int | None = None
|
||||
current_traffic_limit: int | None = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@@ -57,6 +71,13 @@ class KeyUpdate(BaseModel):
|
||||
notified: bool | None = None
|
||||
notified_24h: bool | None = None
|
||||
|
||||
selected_device_limit: int | None = None
|
||||
selected_traffic_limit: int | None = None
|
||||
selected_price_rub: int | None = None
|
||||
|
||||
current_device_limit: int | None = None
|
||||
current_traffic_limit: int | None = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -13,6 +14,19 @@ class TariffBase(BaseModel):
|
||||
is_active: bool = True
|
||||
subgroup_title: str | None = None
|
||||
sort_order: int | None = None
|
||||
vless: bool = False
|
||||
external_squad: str | None = None
|
||||
|
||||
configurable: bool = False
|
||||
|
||||
device_options: list[int] | None = None
|
||||
traffic_options_gb: list[int] | None = None
|
||||
|
||||
device_step_rub: int | None = None
|
||||
device_overrides: dict[str, int] | None = None
|
||||
|
||||
traffic_step_rub: int | None = None
|
||||
traffic_overrides: dict[str, int] | None = None
|
||||
|
||||
|
||||
class TariffResponse(TariffBase):
|
||||
@@ -34,6 +48,19 @@ class TariffUpdate(BaseModel):
|
||||
is_active: bool | None = None
|
||||
subgroup_title: str | None = None
|
||||
sort_order: int | None = None
|
||||
vless: bool | None = None
|
||||
external_squad: str | None = None
|
||||
|
||||
configurable: bool | None = None
|
||||
|
||||
device_options: list[int] | None = None
|
||||
traffic_options_gb: list[int] | None = None
|
||||
|
||||
device_step_rub: int | None = None
|
||||
device_overrides: dict[str, int] | None = None
|
||||
|
||||
traffic_step_rub: int | None = None
|
||||
traffic_overrides: dict[str, int] | None = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
Reference in New Issue
Block a user