S3 support - draft

feat-s3-exp
Markos Gogoulos 2021-07-26 19:09:03 +03:00
rodzic 7237040777
commit 28f16cbd83
4 zmienionych plików z 56 dodań i 5 usunięć

Wyświetl plik

@ -32,3 +32,16 @@ CELERY_RESULT_BACKEND = BROKER_URL
MP4HLS_COMMAND = "/home/mediacms.io/bento4/bin/mp4hls"
DEBUG = False
USE_S3_FOR_MEDIA_STORAGE = True
AWS_ACCESS_KEY = 'x'
AWS_SECRET_KEY = 'Y'
S3_BUCKET_NAME = 'Z'
# S3 work plan
# 1. Enter settings that you're using S3 OK
# 2. Enter a migration remote_urls on Media/Encode OK
# 3. add task that puts content to S3, removes local file, sets remote_urls
# 4. API response for orig/encod/hls from S3 --> plays??
# 5. script to migrate existing to S3

Wyświetl plik

@ -0,0 +1,23 @@
# Generated by Django 3.1.8 on 2021-07-26 16:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('files', '0002_auto_20201201_0712'),
]
operations = [
migrations.AddField(
model_name='encoding',
name='remote_urls',
field=models.JSONField(default=dict, help_text='This will keep any url'),
),
migrations.AddField(
model_name='media',
name='remote_urls',
field=models.JSONField(default=dict, help_text='This will keep any url'),
),
]

Wyświetl plik

@ -284,6 +284,8 @@ class Media(models.Model):
video_height = models.IntegerField(default=1)
views = models.IntegerField(db_index=True, default=1)
# this will keep any cloud url info, as original_file, probably hls files, encoding files etc
remote_urls = models.JSONField(default=dict, help_text='This will keep any url')
# keep track if media file has changed, on saves
__original_media_file = None
@ -691,7 +693,11 @@ class Media(models.Model):
ep = {}
ep["title"] = encoding.profile.name
ep["url"] = encoding.media_encoding_url
if encoding.remote_urls and encoding.remote_urls.get('media_encoding_url'):
url = encoding.remote_urls.get('media_encoding_url')
else:
url = encoding.media_encoding_url
ep["url"] = url
ep["progress"] = encoding.progress
ep["size"] = encoding.size
ep["encoding_id"] = encoding.id
@ -731,11 +737,15 @@ class Media(models.Model):
def original_media_url(self):
"""Property used on serializers"""
if settings.SHOW_ORIGINAL_MEDIA:
return helpers.url_from_path(self.media_file.path)
else:
if not settings.SHOW_ORIGINAL_MEDIA:
return None
if self.remote_urls and self.remote_urls.get('original_media_url'):
url = self.remote_urls.get('original_media_url')
else:
url = helpers.url_from_path(self.media_file.path)
return url
@property
def thumbnail_url(self):
"""Property used on serializers
@ -1077,6 +1087,9 @@ class Encoding(models.Model):
worker = models.CharField(max_length=100, blank=True)
# this will keep any cloud url info, as original_file, probably hls files, encoding files etc
remote_urls = models.JSONField(default=dict, help_text='This will keep any url')
@property
def media_encoding_url(self):
if self.media_file:

Wyświetl plik

@ -30,4 +30,6 @@ m3u8
django-ckeditor
django-debug-toolbar
django-login-required-middleware==0.6.1
django-login-required-middleware==0.6.1
boto3==1.17.111