mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
lint
This commit is contained in:
parent
62d0d8b6db
commit
8b735a492a
4 changed files with 35 additions and 18 deletions
|
|
@ -86,7 +86,7 @@ def downgrade() -> None:
|
|||
"ELASTICSEARCH_CONNECTOR",
|
||||
"WEBCRAWLER_CONNECTOR",
|
||||
)
|
||||
|
||||
|
||||
# All document values except TEAMS_CONNECTOR
|
||||
old_document_values = (
|
||||
"EXTENSION",
|
||||
|
|
|
|||
|
|
@ -253,7 +253,9 @@ class TeamsConnector:
|
|||
access_token = await self._get_valid_token()
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
url = f"{self.GRAPH_API_BASE}/teams/{team_id}/channels/{channel_id}/messages"
|
||||
url = (
|
||||
f"{self.GRAPH_API_BASE}/teams/{team_id}/channels/{channel_id}/messages"
|
||||
)
|
||||
|
||||
# Note: The Graph API for channel messages doesn't support $filter parameter
|
||||
# We fetch all messages and filter them client-side
|
||||
|
|
@ -270,7 +272,7 @@ class TeamsConnector:
|
|||
|
||||
data = response.json()
|
||||
messages = data.get("value", [])
|
||||
|
||||
|
||||
# Filter messages by date if needed (client-side filtering)
|
||||
if start_date or end_date:
|
||||
# Make sure comparison dates are timezone-aware (UTC)
|
||||
|
|
@ -278,26 +280,28 @@ class TeamsConnector:
|
|||
start_date = start_date.replace(tzinfo=UTC)
|
||||
if end_date and end_date.tzinfo is None:
|
||||
end_date = end_date.replace(tzinfo=UTC)
|
||||
|
||||
|
||||
filtered_messages = []
|
||||
for message in messages:
|
||||
created_at_str = message.get("createdDateTime")
|
||||
if not created_at_str:
|
||||
continue
|
||||
|
||||
|
||||
# Parse the ISO 8601 datetime string (already timezone-aware)
|
||||
created_at = datetime.fromisoformat(created_at_str.replace('Z', '+00:00'))
|
||||
|
||||
created_at = datetime.fromisoformat(
|
||||
created_at_str.replace("Z", "+00:00")
|
||||
)
|
||||
|
||||
# Check if message is within date range
|
||||
if start_date and created_at < start_date:
|
||||
continue
|
||||
if end_date and created_at > end_date:
|
||||
continue
|
||||
|
||||
|
||||
filtered_messages.append(message)
|
||||
|
||||
|
||||
return filtered_messages
|
||||
|
||||
|
||||
return messages
|
||||
|
||||
async def get_message_replies(
|
||||
|
|
|
|||
|
|
@ -343,8 +343,12 @@ async def teams_callback(
|
|||
|
||||
except IntegrityError as e:
|
||||
await session.rollback()
|
||||
logger.error("Database integrity error creating Teams connector: %s", str(e))
|
||||
redirect_url = f"{config.NEXT_FRONTEND_URL}/dashboard?error=connector_creation_failed"
|
||||
logger.error(
|
||||
"Database integrity error creating Teams connector: %s", str(e)
|
||||
)
|
||||
redirect_url = (
|
||||
f"{config.NEXT_FRONTEND_URL}/dashboard?error=connector_creation_failed"
|
||||
)
|
||||
return RedirectResponse(url=redirect_url)
|
||||
|
||||
except HTTPException:
|
||||
|
|
|
|||
|
|
@ -173,10 +173,14 @@ async def index_teams_messages(
|
|||
end_datetime = None
|
||||
if start_date_str:
|
||||
# Parse as naive datetime and make it timezone-aware (UTC)
|
||||
start_datetime = datetime.strptime(start_date_str, "%Y-%m-%d").replace(tzinfo=UTC)
|
||||
start_datetime = datetime.strptime(start_date_str, "%Y-%m-%d").replace(
|
||||
tzinfo=UTC
|
||||
)
|
||||
if end_date_str:
|
||||
# Parse as naive datetime, set to end of day, and make it timezone-aware (UTC)
|
||||
end_datetime = datetime.strptime(end_date_str, "%Y-%m-%d").replace(hour=23, minute=59, second=59, tzinfo=UTC)
|
||||
end_datetime = datetime.strptime(end_date_str, "%Y-%m-%d").replace(
|
||||
hour=23, minute=59, second=59, tzinfo=UTC
|
||||
)
|
||||
|
||||
# Process each team
|
||||
for team in teams:
|
||||
|
|
@ -314,8 +318,10 @@ async def index_teams_messages(
|
|||
chunks = await create_document_chunks(
|
||||
combined_document_string
|
||||
)
|
||||
doc_embedding = config.embedding_model_instance.embed(
|
||||
combined_document_string
|
||||
doc_embedding = (
|
||||
config.embedding_model_instance.embed(
|
||||
combined_document_string
|
||||
)
|
||||
)
|
||||
|
||||
# Update existing document
|
||||
|
|
@ -337,11 +343,14 @@ async def index_teams_messages(
|
|||
|
||||
# Delete old chunks and add new ones
|
||||
existing_document.chunks = chunks
|
||||
existing_document.updated_at = get_current_timestamp()
|
||||
existing_document.updated_at = (
|
||||
get_current_timestamp()
|
||||
)
|
||||
|
||||
documents_indexed += 1
|
||||
logger.info(
|
||||
"Successfully updated Teams message %s", message_id
|
||||
"Successfully updated Teams message %s",
|
||||
message_id,
|
||||
)
|
||||
continue
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue