| Dara Singh | 2023BCY0045 |
| Akshat Saraswat | 2023BCY0048 |
| Sanjay Sahu | 2023BCY0051 |
| Akhil Yadav | 2023BCY0054 |
| Nahil Rasheed K.E | 2023BCY0057 |
| Abraham Thomas | 2023BCY0060 |
| Varshith Reddy | 2023BCY0063 |
Design and implement a cloud storage solution that allows users to upload, download and share files.
import resend
params: resend.Emails.SendParams = {
from: "[email protected]",
to: [user.email],
template_id: "d-1f"
}
resend.Emails.send(params)
@router.post("/api/auth/login")
async def login(user: UserLogin):
response = supabase.auth.sign_in_with_password(
{"email": user.email, "password": user.password}
)
if response.user is None:
raise HTTPException(status_code=400, detail="Login failed")
token = secrets.token_urlsafe(32)
redis_instance.set(token, response.user.id)
login_response = {
"message": "Login successful",
"token": token
}
return login_response
from pydantic import BaseModel
@router.post("/api/files")
async def get_user_files(req: GetFiles, userid=Depends(get_current_user)):
class File(BaseModel):
fileId: str
fileName: str
previewImage: str
data = supabase_admin.table("files").select("*").eq("owner", userid).execute()
files: List[File] = []
if data.data is not None:
for db_file in data.data:
file = File(
fileId=db_file["id"],
fileName=db_file["filename"],
previewImage=db_file["preview_image"],
)
files.append(file)
return {"message": "Files retrieved successfully", "files": files}
@router.patch("/api/files/{fileId}/share")
async def share_file(fileId: str, req: reqBody, userid=Depends(get_current_user)):
# Check file ownership
file_query = (
supabase_admin.table("files").select("owner").eq("id", fileId).execute()
)
if file_query.data[0]["owner"] != userid:
return {"message": "You are not the owner of this file"}
# Update file and create sharing record
supabase_admin.table("files").update({"is_shared": True}).eq(
"id", fileId
).execute()
supabase_admin.table("shared").insert(
{"file_id": fileId, "shared_with": recipient_id}
).execute()
return {"message": "File shared successfully"}