abineshkuma's picture
feat: add token usage export functionality with validation and CSV row structure
c802173
Raw
History Blame Contribute Delete
1.04 kB
import mimetypes
def get_extension_from_content_type(content_type: str) -> str:
"""Return file extension (without dot) from a given content-type."""
ext = mimetypes.guess_extension(content_type)
if ext is None:
# fallback for types mimetypes may miss
mapping = {
"image/webp": "webp",
"image/jpeg": "jpg",
"image/png": "png",
"image/gif": "gif",
"video/mp4": "mp4",
"video/webm": "webm",
"application/pdf": "pdf",
}
return mapping.get(content_type, "")
return ext.lstrip(".") # remove leading dot
def pick_team(uid: str, user_to_teams: dict, team_map: dict) -> str:
"""Return the best team ID for a user — preferring non-personal teams."""
candidates = user_to_teams.get(uid, [])
non_personal = [
t for t in candidates
if not team_map.get(t, {}).get("is_personal_team", False)
]
return non_personal[0] if non_personal else (candidates[0] if candidates else "")