2025-12-04 15:41:22 +07:00
|
|
|
import io
|
|
|
|
|
|
|
|
|
|
from flask import Response
|
|
|
|
|
from helpers import S3_BUCKET, get_secret, s3_client
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create&Update function to upload or update user avatar S3/Minio
|
2025-12-08 20:15:52 +07:00
|
|
|
def create_phone(user_id: str, file):
|
2025-12-04 15:41:22 +07:00
|
|
|
try:
|
2025-12-08 20:15:52 +07:00
|
|
|
|
2025-12-04 15:41:22 +07:00
|
|
|
|
|
|
|
|
return result, 200
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return {"error": str(e)}, 500
|
|
|
|
|
|
|
|
|
|
|
2025-12-08 20:15:52 +07:00
|
|
|
def get_phone(user_id: str): # Read function to get user avatar from S3/Minio
|
2025-12-04 15:41:22 +07:00
|
|
|
try:
|
2025-12-08 20:15:52 +07:00
|
|
|
|
2025-12-04 15:41:22 +07:00
|
|
|
|
|
|
|
|
return Response(
|
2025-12-08 20:15:52 +07:00
|
|
|
|
2025-12-04 15:41:22 +07:00
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return {"error": str(e)}, 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Delete Function to delete user avatar from S3/Minio
|
2025-12-08 20:15:52 +07:00
|
|
|
def delete_phone(user_id: str) -> dict:
|
2025-12-04 15:41:22 +07:00
|
|
|
try:
|
2025-12-08 20:15:52 +07:00
|
|
|
|
|
|
|
|
|
2025-12-04 15:41:22 +07:00
|
|
|
return result, 200
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return {"error": str(e)}, 500
|