apply ruff formatting
This commit is contained in:
@@ -3,6 +3,7 @@ Google Drive Helper Functions
|
||||
|
||||
Shared utilities for Google Drive operations including permission checking.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
from typing import List, Dict, Any, Optional, Tuple
|
||||
@@ -11,15 +12,15 @@ from typing import List, Dict, Any, Optional, Tuple
|
||||
def check_public_link_permission(permissions: List[Dict[str, Any]]) -> bool:
|
||||
"""
|
||||
Check if file has 'anyone with the link' permission.
|
||||
|
||||
|
||||
Args:
|
||||
permissions: List of permission objects from Google Drive API
|
||||
|
||||
|
||||
Returns:
|
||||
bool: True if file has public link sharing enabled
|
||||
"""
|
||||
return any(
|
||||
p.get('type') == 'anyone' and p.get('role') in ['reader', 'writer', 'commenter']
|
||||
p.get("type") == "anyone" and p.get("role") in ["reader", "writer", "commenter"]
|
||||
for p in permissions
|
||||
)
|
||||
|
||||
@@ -27,11 +28,11 @@ def check_public_link_permission(permissions: List[Dict[str, Any]]) -> bool:
|
||||
def format_public_sharing_error(file_name: str, file_id: str) -> str:
|
||||
"""
|
||||
Format error message for files without public sharing.
|
||||
|
||||
|
||||
Args:
|
||||
file_name: Name of the file
|
||||
file_id: Google Drive file ID
|
||||
|
||||
|
||||
Returns:
|
||||
str: Formatted error message
|
||||
"""
|
||||
@@ -45,10 +46,10 @@ def format_public_sharing_error(file_name: str, file_id: str) -> str:
|
||||
def get_drive_image_url(file_id: str) -> str:
|
||||
"""
|
||||
Get the correct Drive URL format for publicly shared images.
|
||||
|
||||
|
||||
Args:
|
||||
file_id: Google Drive file ID
|
||||
|
||||
|
||||
Returns:
|
||||
str: URL for embedding Drive images
|
||||
"""
|
||||
@@ -58,16 +59,18 @@ def get_drive_image_url(file_id: str) -> str:
|
||||
# Precompiled regex patterns for Drive query detection
|
||||
DRIVE_QUERY_PATTERNS = [
|
||||
re.compile(r'\b\w+\s*(=|!=|>|<)\s*[\'"].*?[\'"]', re.IGNORECASE), # field = 'value'
|
||||
re.compile(r'\b\w+\s*(=|!=|>|<)\s*\d+', re.IGNORECASE), # field = number
|
||||
re.compile(r'\bcontains\b', re.IGNORECASE), # contains operator
|
||||
re.compile(r'\bin\s+parents\b', re.IGNORECASE), # in parents
|
||||
re.compile(r'\bhas\s*\{', re.IGNORECASE), # has {properties}
|
||||
re.compile(r'\btrashed\s*=\s*(true|false)\b', re.IGNORECASE), # trashed=true/false
|
||||
re.compile(r'\bstarred\s*=\s*(true|false)\b', re.IGNORECASE), # starred=true/false
|
||||
re.compile(r'[\'"][^\'"]+[\'"]\s+in\s+parents', re.IGNORECASE), # 'parentId' in parents
|
||||
re.compile(r'\bfullText\s+contains\b', re.IGNORECASE), # fullText contains
|
||||
re.compile(r'\bname\s*(=|contains)\b', re.IGNORECASE), # name = or name contains
|
||||
re.compile(r'\bmimeType\s*(=|!=)\b', re.IGNORECASE), # mimeType operators
|
||||
re.compile(r"\b\w+\s*(=|!=|>|<)\s*\d+", re.IGNORECASE), # field = number
|
||||
re.compile(r"\bcontains\b", re.IGNORECASE), # contains operator
|
||||
re.compile(r"\bin\s+parents\b", re.IGNORECASE), # in parents
|
||||
re.compile(r"\bhas\s*\{", re.IGNORECASE), # has {properties}
|
||||
re.compile(r"\btrashed\s*=\s*(true|false)\b", re.IGNORECASE), # trashed=true/false
|
||||
re.compile(r"\bstarred\s*=\s*(true|false)\b", re.IGNORECASE), # starred=true/false
|
||||
re.compile(
|
||||
r'[\'"][^\'"]+[\'"]\s+in\s+parents', re.IGNORECASE
|
||||
), # 'parentId' in parents
|
||||
re.compile(r"\bfullText\s+contains\b", re.IGNORECASE), # fullText contains
|
||||
re.compile(r"\bname\s*(=|contains)\b", re.IGNORECASE), # name = or name contains
|
||||
re.compile(r"\bmimeType\s*(=|!=)\b", re.IGNORECASE), # mimeType operators
|
||||
]
|
||||
|
||||
|
||||
@@ -113,7 +116,9 @@ def build_drive_list_params(
|
||||
|
||||
SHORTCUT_MIME_TYPE = "application/vnd.google-apps.shortcut"
|
||||
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
|
||||
BASE_SHORTCUT_FIELDS = "id, mimeType, parents, shortcutDetails(targetId, targetMimeType)"
|
||||
BASE_SHORTCUT_FIELDS = (
|
||||
"id, mimeType, parents, shortcutDetails(targetId, targetMimeType)"
|
||||
)
|
||||
|
||||
|
||||
async def resolve_drive_item(
|
||||
|
||||
Reference in New Issue
Block a user