Skip to content

Commit

Permalink
Merge pull request #17 from breakmagazine/feat/article
Browse files Browse the repository at this point in the history
reformat: black으로 reformatting
  • Loading branch information
yjoonjang authored Jul 20, 2024
2 parents eef7480 + f7f2c3a commit aea451b
Showing 1 changed file with 47 additions and 60 deletions.
107 changes: 47 additions & 60 deletions breakserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create_presigned_url(bucket_name, object_name, expiration=3600):

return response


@extend_schema(
description="S3에 파일을 업로드하기 위해 presigned url 요청",
parameters=[
Expand All @@ -53,76 +54,66 @@ def create_presigned_url(bucket_name, object_name, expiration=3600):
description="presigned_url을 요청할 카테고리입니다.",
examples=[
OpenApiExample(
'USER/PROFILE_IMAGE',
value='USER/PROFILE_IMAGE',
description='User profile image upload'
"USER/PROFILE_IMAGE",
value="USER/PROFILE_IMAGE",
description="User profile image upload",
),
OpenApiExample(
'BANNER/MAIN',
value='BANNER/MAIN',
description='Main banner upload'
"BANNER/MAIN", value="BANNER/MAIN", description="Main banner upload"
),
OpenApiExample(
'BANNER/MID',
value='BANNER/MID',
description='Middle banner upload'
"BANNER/MID", value="BANNER/MID", description="Middle banner upload"
),
OpenApiExample(
'SYMBOLIC',
value='SYMBOLIC',
description='Symbolic upload'
"SYMBOLIC", value="SYMBOLIC", description="Symbolic upload"
),
OpenApiExample(
'HOME_ARTICLE/LEFT',
value='HOME_ARTICLE/LEFT',
description='Left home article upload'
"HOME_ARTICLE/LEFT",
value="HOME_ARTICLE/LEFT",
description="Left home article upload",
),
OpenApiExample(
'HOME_ARTICLE/RIGHT',
value='HOME_ARTICLE/RIGHT',
description='Right home article upload'
"HOME_ARTICLE/RIGHT",
value="HOME_ARTICLE/RIGHT",
description="Right home article upload",
),
OpenApiExample(
'CATEGORY/ABOUT',
value='CATEGORY/ABOUT',
description='Category about image upload'
"CATEGORY/ABOUT",
value="CATEGORY/ABOUT",
description="Category about image upload",
),
OpenApiExample(
'CATEGORY/FASHION',
value='CATEGORY/FASHION',
description='Category fashion image upload'
"CATEGORY/FASHION",
value="CATEGORY/FASHION",
description="Category fashion image upload",
),
OpenApiExample(
'CATEGORY/FEATURE',
value='CATEGORY/FEATURE',
description='Category feature image upload'
"CATEGORY/FEATURE",
value="CATEGORY/FEATURE",
description="Category feature image upload",
),
OpenApiExample(
'CATEGORY/PHOTOGRAPHY',
value='CATEGORY/PHOTOGRAPHY',
description='Category photography image upload'
"CATEGORY/PHOTOGRAPHY",
value="CATEGORY/PHOTOGRAPHY",
description="Category photography image upload",
),
OpenApiExample(
'CATEGORY/FILM',
value='CATEGORY/FILM',
description='Category film image upload'
"CATEGORY/FILM",
value="CATEGORY/FILM",
description="Category film image upload",
),
OpenApiExample(
'CATEGORY/ART',
value='CATEGORY/ART',
description='Category art image upload'
"CATEGORY/ART",
value="CATEGORY/ART",
description="Category art image upload",
),
OpenApiExample(
'HISTORY',
value='HISTORY',
description='History upload'
"HISTORY", value="HISTORY", description="History upload"
),
OpenApiExample(
'ARTICLE',
value='ARTICLE',
description='Article upload'
)
]
"ARTICLE", value="ARTICLE", description="Article upload"
),
],
)
],
responses={
Expand All @@ -132,34 +123,28 @@ def create_presigned_url(bucket_name, object_name, expiration=3600):
"application/json": {
"example": {
"url": "https://s3.ap-northeast-2.amazonaws.com/breakmagazine_image/articles/thumbnails/123e4567-e89b-12d3-a456-426614174000.jpg",
"object_name": "articles/thumbnails/123e4567-e89b-12d3-a456-426614174000.jpg"
"object_name": "articles/thumbnails/123e4567-e89b-12d3-a456-426614174000.jpg",
}
}
}
},
},
400: {
"description": "Category is required",
"content": {
"application/json": {
"example": {
"error": "Category is required"
}
}
}
"application/json": {"example": {"error": "Category is required"}}
},
},
500: {
"description": "Could not generate presigned URL",
"content": {
"application/json": {
"example": {
"error": "Could not generate presigned URL"
}
"example": {"error": "Could not generate presigned URL"}
}
}
}
}
},
},
},
)
@api_view(['GET'])
@api_view(["GET"])
def get_presigned_url(request):
if request.method == "GET":
bucket_name = env("AWS_STORAGE_BUCKET_NAME")
Expand All @@ -171,7 +156,9 @@ def get_presigned_url(request):
# 고유 객체 이름 생성
object_name = f"{category}/{uuid.uuid4()}.jpg"
url = create_presigned_url(bucket_name, object_name)
object_url = f"https://{bucket_name}.s3.ap-northeast-2.amazonaws.com/{object_name}"
object_url = (
f"https://{bucket_name}.s3.ap-northeast-2.amazonaws.com/{object_name}"
)
if url:
return JsonResponse({"url": url, "objectUrl": object_url})
else:
Expand Down

0 comments on commit aea451b

Please sign in to comment.