refactor: sync running-container source back to repo for reproducible docker compose build; remove dead code (orphan pipeline.py + 104 stale files from iterative dev) and drop unused app/ mirror dir
This commit is contained in:
1 parent
1346fbbd4b
commit
5d7f32db0a
138 files changed
+12846
-84248
No files matched your search
@@ -4,7 +4,7 @@ from sqlalchemy import and_, desc, asc, func, extract
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
import uuid
|
||||
from datetime import datetime, date, timedelta, timezone
|
||||
from datetime import datetime, date, timedelta
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import (
|
||||
@@ -16,9 +16,6 @@ from ..middleware.log_service import LogService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# CST timezone (UTC+8)
|
||||
CST_TZ = timezone(timedelta(hours=8))
|
||||
|
||||
|
||||
class RechargeRequest(BaseModel):
|
||||
amount: int = Field(ge=1)
|
||||
@@ -35,15 +32,12 @@ def get_overview(
|
||||
TokenUsageLog.user_id == current_user.id
|
||||
).scalar()
|
||||
|
||||
# 今日使用中应用数 - 使用CST时区的"今天"
|
||||
now_cst = datetime.now(CST_TZ)
|
||||
today_start = now_cst.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
# Convert to UTC for DB comparison since container uses UTC timestamps
|
||||
today_start_utc = today_start.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
# 今日使用中应用数
|
||||
today_start = datetime.combine(date.today(), datetime.min.time())
|
||||
today_apps = db.query(func.count(func.distinct(TokenUsageLog.model_id))).filter(
|
||||
and_(
|
||||
TokenUsageLog.user_id == current_user.id,
|
||||
TokenUsageLog.created_at >= today_start_utc,
|
||||
TokenUsageLog.created_at >= today_start,
|
||||
)
|
||||
).scalar() or 0
|
||||
|
||||
@@ -52,7 +46,9 @@ def get_overview(
|
||||
TokenBalance.user_id == current_user.id
|
||||
).first()
|
||||
|
||||
server_time = datetime.now(CST_TZ).isoformat()
|
||||
from datetime import timezone, timedelta
|
||||
shanghai_tz = timezone(timedelta(hours=8))
|
||||
server_time = datetime.now(shanghai_tz).isoformat()
|
||||
|
||||
return {
|
||||
"code": 0,
|
||||
@@ -173,7 +169,7 @@ def get_token_logs(
|
||||
"completion_tokens": log_item.completion_tokens or 0,
|
||||
"total_tokens": log_item.total_tokens or 0,
|
||||
"conversation_id": log_item.conversation_id,
|
||||
"created_at": _format_cst_time(log_item.created_at),
|
||||
"created_at": log_item.created_at.isoformat() if log_item.created_at else None,
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -249,14 +245,3 @@ def recharge(
|
||||
},
|
||||
"message": "充值成功",
|
||||
}
|
||||
|
||||
|
||||
def _format_cst_time(dt_value):
|
||||
"""Format datetime to CST ISO string.
|
||||
DB values are written by cst_now() as CST time (stored naive by MySQL).
|
||||
No UTC conversion needed - treat naive values as CST directly.
|
||||
"""
|
||||
if dt_value is None:
|
||||
return None
|
||||
# DB naive values are already CST (written by cst_now()), just attach tz
|
||||
return dt_value.replace(tzinfo=CST_TZ).isoformat()
|
||||
Reference in new issue
Block a user