Merge pull request #1690 from kettenbach-it/develop

Get image from S3-storage if configured
This commit is contained in:
vabene1111 2022-04-04 19:02:35 +02:00 committed by GitHub
commit dfa5475ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,8 @@ from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, Cu
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
UserFile, UserPreference, ViewLog)
from cookbook.templatetags.custom_tags import markdown
from recipes.settings import MEDIA_URL
from cookbook.helper.CustomStorageClass import CachedS3Boto3Storage
from recipes.settings import MEDIA_URL, AWS_S3_ENDPOINT_URL, AWS_ACCESS_KEY_ID
class ExtendedRecipeMixin(serializers.ModelSerializer):
@ -54,7 +55,12 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
def get_image(self, obj):
if obj.recipe_image:
return MEDIA_URL + obj.recipe_image
if AWS_ACCESS_KEY_ID and AWS_S3_ENDPOINT_URL:
storage = CachedS3Boto3Storage()
path = storage.url(obj.recipe_image)
else:
path = MEDIA_URL + obj.recipe_image
return path
class CustomDecimalField(serializers.Field):