fast_save. Route handler or application helper. This docstring was expanded to make future maintenance easier. Args: file_storage: Parameter. dest_path: Parameter. bufsize: Parameter. Returns: Varies.
(file_storage, dest_path: str, bufsize: int = 64 * 1024 * 1024)
| 3507 | except Exception: |
| 3508 | pass |
| 3509 | |
| 3510 | conn.close() |
| 3511 | |
| 3512 | def set_profile_pic(username: str, file_stream, mime: str): |
| 3513 | """Store a user's profile picture on disk (plaintext). |
| 3514 | |
| 3515 | We keep profile pictures capped (PFP_MAX_BYTES) to avoid slow uploads and |
| 3516 | reduce risk/abuse. |
| 3517 | """ |
| 3518 | ensure_profile_row(username) |
| 3519 | dst = os.path.join(PFP_DIR, f"{username}.bin") |
| 3520 | os.makedirs(os.path.dirname(dst), exist_ok=True) |
| 3521 | |
| 3522 | total = 0 |
| 3523 | try: |
| 3524 | try: |
| 3525 | file_stream.seek(0) |
| 3526 | except Exception: |
| 3527 | pass |
| 3528 | with open(dst, "wb") as out: |
| 3529 | while True: |
| 3530 | chunk = file_stream.read(1024 * 1024) |
| 3531 | if not chunk: |
| 3532 | break |
| 3533 | total += len(chunk) |
| 3534 | if total > PFP_MAX_BYTES: |
| 3535 | raise ValueError("pfp_too_large") |
| 3536 | out.write(chunk) |
| 3537 | except Exception: |
nothing calls this directly
no outgoing calls
no test coverage detected