Skip to content

Commit

Permalink
add test route for profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferrariic committed Jan 30, 2023
1 parent 06ea3e5 commit 6a7631b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
echo "${{ secrets.REDIS_DATABASE }}" >> .env
echo "${{ secrets.REDIS_PORT }}" >> .env
echo "${{ secrets.SERVER_IP }}" >> .env
echo "${{ secrets.ROUTE_IP }}" >> .env
deploy:
runs-on: self-hosted
Expand Down
1 change: 1 addition & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
redis_database = os.environ.get("redis_database")
redis_port = os.environ.get("redis_port")
server_ip = os.environ.get("server_ip")
route_ip = os.environ.get("route_ip")


# create application
Expand Down
4 changes: 2 additions & 2 deletions api/routers/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
async def get_image(image_id: str) -> json:
"""get image copy"""
image_route = await redis_client.get(image_id)
image_route = redis_decode(bytes_encoded=image_route)
return FileResponse("C:/Users/thear/Documents/GitHub/API/images/8/profile.jpeg")
image_route = image_route.decode("utf-8")
return FileResponse(image_route)
17 changes: 10 additions & 7 deletions api/routers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql import or_
from sqlalchemy.sql.expression import select
from api.config import redis_client
from api.config import redis_client, route_ip
from api.database.functions import generate_token
from api.routers.functions.general import get_token_user_id, check_user_block

Expand All @@ -33,19 +33,22 @@
@router.get("/v1/profile/avatar/{user_id}", tags=["profile"])
async def get_profile_picture(user_id: str) -> json:
"Get the profile picture of a user by their ID."
print("test")

if not os.path.exists(f"{os.getcwd()}/images/{user_id}/profile.jpeg"):
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="This user does not have a profile picture.",
)
print("test")
image_route = f"{os.getcwd()}\images\{user_id}\profile.jpeg"
image_token = await generate_token(16)
print("test")
await redis_client.set(name=image_token, value=image_route, ex=3600)
return HTTPException(status_code=status.HTTP_200_OK, detail=image_token)
image_route = await redis_client.get(name=image_token)
if not image_route:
await redis_client.set(name=image_token, value=image_route, ex=3600)

image_route = image_route.decode("utf-8")
return HTTPException(
status_code=status.HTTP_200_OK,
detail=f"http://{route_ip}/v1/image/{image_token}",
)


@router.post("/v1/profile/avatar/{token}", tags=["profile"])
Expand Down

0 comments on commit 6a7631b

Please sign in to comment.