Files
yt2mp3/server/py/fastapi.py
2026-01-13 19:08:21 +00:00

73 lines
1.8 KiB
Python

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Optional
import uvicorn
app = FastAPI()
class ConversionData(BaseModel):
input_value: str
conversion_type: str
class LoginData(BaseModel):
username: str
password: str
class MeData(BaseModel):
username: str
email: str
profile_picture: Optional[str] = None
@app.post("/convert")
async def convert_endpoint(data: ConversionData):
"""
Converts an input value based on the specified conversion type.
"""
# Dummy conversion logic
if data.conversion_type == "uppercase":
converted_value = data.input_value.upper()
elif data.conversion_type == "lowercase":
converted_value = data.input_value.lower()
else:
raise HTTPException(status_code=400, detail="Invalid conversion type")
return {"converted_value": converted_value}
@app.post("/login")
async def login_endpoint(data: LoginData):
"""
Verifies login credentials.
"""
# Dummy verification logic
if data.username == "user" and data.password == "password":
return {"message": "Login successful"}
else:
raise HTTPException(status_code=401, detail="Invalid credentials")
@app.get("/me")
async def me_get_endpoint():
"""
Retrieves user profile data.
"""
# Dummy user data
user_data = {
"username": "example_user",
"email": "user@example.com",
"profile_picture": "https://example.com/profile.jpg"
}
return user_data
@app.post("/me")
async def me_post_endpoint(data: MeData):
"""
Updates user profile data.
"""
# Dummy update logic
return {"message": "Profile updated successfully", **data.dict()}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)