fix: resolve datetime timezone comparison issues in share module [AC-IDMP-SHARE]
This commit is contained in:
parent
382f91ce83
commit
978aaee885
|
|
@ -146,6 +146,20 @@ export interface SharedSessionInfo {
|
||||||
history: DialogueMessage[]
|
history: DialogueMessage[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CreatePublicShareTokenRequest {
|
||||||
|
tenant_id?: string
|
||||||
|
api_key?: string
|
||||||
|
session_id: string
|
||||||
|
user_id?: string
|
||||||
|
expires_in_minutes?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreatePublicShareTokenResponse {
|
||||||
|
share_token: string
|
||||||
|
share_url: string
|
||||||
|
expires_at: string
|
||||||
|
}
|
||||||
|
|
||||||
export function createShare(sessionId: string, data: CreateShareRequest = {}): Promise<ShareResponse> {
|
export function createShare(sessionId: string, data: CreateShareRequest = {}): Promise<ShareResponse> {
|
||||||
return request({
|
return request({
|
||||||
url: `/mid/sessions/${sessionId}/share`,
|
url: `/mid/sessions/${sessionId}/share`,
|
||||||
|
|
@ -154,6 +168,14 @@ export function createShare(sessionId: string, data: CreateShareRequest = {}): P
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createPublicShareToken(data: CreatePublicShareTokenRequest): Promise<CreatePublicShareTokenResponse> {
|
||||||
|
return request({
|
||||||
|
url: '/openapi/v1/share/token',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function getSharedSession(shareToken: string): Promise<SharedSessionInfo> {
|
export function getSharedSession(shareToken: string): Promise<SharedSessionInfo> {
|
||||||
return request({
|
return request({
|
||||||
url: `/mid/share/${shareToken}`,
|
url: `/mid/share/${shareToken}`,
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,15 @@ settings = get_settings()
|
||||||
|
|
||||||
|
|
||||||
def _utcnow() -> datetime:
|
def _utcnow() -> datetime:
|
||||||
"""Get current UTC time with timezone info."""
|
"""Get current UTC time without timezone info (for DB compatibility)."""
|
||||||
return datetime.now(timezone.utc)
|
return datetime.utcnow()
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_datetime(dt: datetime) -> datetime:
|
||||||
|
"""Normalize datetime to offset-naive UTC for comparison."""
|
||||||
|
if dt.tzinfo is not None:
|
||||||
|
return dt.replace(tzinfo=None)
|
||||||
|
return dt
|
||||||
|
|
||||||
|
|
||||||
def _generate_share_url(share_token: str) -> str:
|
def _generate_share_url(share_token: str) -> str:
|
||||||
|
|
@ -136,7 +143,7 @@ async def get_shared_session(
|
||||||
if not shared.is_active:
|
if not shared.is_active:
|
||||||
raise HTTPException(status_code=410, detail="Share is inactive")
|
raise HTTPException(status_code=410, detail="Share is inactive")
|
||||||
|
|
||||||
if shared.expires_at < _utcnow():
|
if _normalize_datetime(shared.expires_at) < _utcnow():
|
||||||
raise HTTPException(status_code=410, detail="Share has expired")
|
raise HTTPException(status_code=410, detail="Share has expired")
|
||||||
|
|
||||||
if shared.current_users >= shared.max_concurrent_users:
|
if shared.current_users >= shared.max_concurrent_users:
|
||||||
|
|
@ -216,7 +223,7 @@ async def list_shares(
|
||||||
title=s.title,
|
title=s.title,
|
||||||
description=s.description,
|
description=s.description,
|
||||||
expires_at=s.expires_at.isoformat(),
|
expires_at=s.expires_at.isoformat(),
|
||||||
is_active=s.is_active and s.expires_at > now,
|
is_active=s.is_active and _normalize_datetime(s.expires_at) > now,
|
||||||
max_concurrent_users=s.max_concurrent_users,
|
max_concurrent_users=s.max_concurrent_users,
|
||||||
current_users=s.current_users,
|
current_users=s.current_users,
|
||||||
created_at=s.created_at.isoformat(),
|
created_at=s.created_at.isoformat(),
|
||||||
|
|
@ -303,7 +310,7 @@ async def join_shared_session(
|
||||||
if not shared.is_active:
|
if not shared.is_active:
|
||||||
raise HTTPException(status_code=410, detail="Share is inactive")
|
raise HTTPException(status_code=410, detail="Share is inactive")
|
||||||
|
|
||||||
if shared.expires_at < _utcnow():
|
if _normalize_datetime(shared.expires_at) < _utcnow():
|
||||||
raise HTTPException(status_code=410, detail="Share has expired")
|
raise HTTPException(status_code=410, detail="Share has expired")
|
||||||
|
|
||||||
if shared.current_users >= shared.max_concurrent_users:
|
if shared.current_users >= shared.max_concurrent_users:
|
||||||
|
|
@ -410,7 +417,7 @@ async def send_shared_message(
|
||||||
if not shared.is_active:
|
if not shared.is_active:
|
||||||
raise HTTPException(status_code=410, detail="Share is inactive")
|
raise HTTPException(status_code=410, detail="Share is inactive")
|
||||||
|
|
||||||
if shared.expires_at < _utcnow():
|
if _normalize_datetime(shared.expires_at) < _utcnow():
|
||||||
raise HTTPException(status_code=410, detail="Share has expired")
|
raise HTTPException(status_code=410, detail="Share has expired")
|
||||||
|
|
||||||
user_message = ChatMessage(
|
user_message = ChatMessage(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue