diff --git a/archiver/settings.py b/archiver/settings.py index 1438fee..b586e0e 100644 --- a/archiver/settings.py +++ b/archiver/settings.py @@ -12,7 +12,7 @@ import os from pathlib import Path from .secgen import generate_secret_key -from archiver import is_available +from archiver import is_available,storage_backend from dotenv import load_dotenv load_dotenv() @@ -157,10 +157,9 @@ STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles') -STATIC_URL = '/static/' MEDIA_ROOT=os.path.join(BASE_DIR,'media') -MEDIA_URL='/media/' + # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field @@ -204,18 +203,32 @@ }, 'attachment_filesize_limit':FILE_SIZE_LIMIT, 'attachment_require_authentication': True, - + } -DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage' -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" #"storages.backends.dropbox.DropboxStorage" -#DROPBOX_OAUTH2_TOKEN = os.environ.get('DROPBOX_OAUTH2_TOKEN') +DEFAULT_FILE_STORAGE = 'archiver.storage_backend.MediaStorage' +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' +#dropbox settings DROPBOX_ROOT_PATH = '/k9archiver/' DROPBOX_APP_KEY = os.environ.get('DROPBOX_APP_KEY') DROPBOX_APP_SECRET = os.environ.get('DROPBOX_APP_SECRET') DROPBOX_OAUTH2_REFRESH_TOKEN=os.environ.get('DROPBOX_OAUTH2_REFRESH_TOKEN') +#[V-dev4.1.0] AWS/Backblaze settings for Media Storage +AWS_ACCESS_KEY_ID =os.environ.get('AWS_ACCESS_KEY_ID') #b2 application key id if using backblaze' +AWS_SECRET_ACCESS_KEY =os.environ.get('AWS_SECRET_ACCESS_KEY') #your b2 application key +AWS_STORAGE_BUCKET_NAME =os.environ.get('AWS_STORAGE_BUCKET_NAME') #'' +AWS_S3_REGION_NAME =os.environ.get('AWS_S3_REGION_NAME') #'' + +AWS_S3_ENDPOINT = f's3.{AWS_S3_REGION_NAME}.backblazeb2.com' +AWS_S3_ENDPOINT_URL = f'https://{AWS_S3_ENDPOINT}' + +AWS_S3_OBJECT_PARAMETERS = { + 'CacheControl': 'max-age=86400', +} + +STATIC_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.{AWS_S3_ENDPOINT}/" #django debug toolbar and other settings for development if DEBUG: #if DEBUG is False then we are in production and we want to use postgres. @@ -241,9 +254,11 @@ } #django storages settings for development - #if USE_DROPBOX_IN_DEVELOPMENT is True then we will use dropbox in development - #it is to test dropbox functionality in development - USE_DROPBOX_IN_DEVELOPMENT=os.environ.get('USE_DROPBOX_IN_DEVELOPMENT', False) == 'True' - if not(USE_DROPBOX_IN_DEVELOPMENT): + #if USE_LOCAL_STORAGE is True then we will use local storage in development + USE_LOCAL_STORAGE=os.environ.get('USE_LOCAL_STORAGE', False) == 'True' + if USE_LOCAL_STORAGE: + STATIC_URL='/static/' + MEDIA_URL='/media/' + STATICFILES_STORAGE="whitenoise.storage.CompressedManifestStaticFilesStorage" DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' \ No newline at end of file diff --git a/archiver/storage_backend.py b/archiver/storage_backend.py new file mode 100644 index 0000000..4325cbf --- /dev/null +++ b/archiver/storage_backend.py @@ -0,0 +1,5 @@ +from storages.backends.s3boto3 import S3Boto3Storage + +class MediaStorage(S3Boto3Storage): + location = 'media' + file_overwrite = False \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a1cfd45..badf9f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -53,3 +53,4 @@ urllib3==2.0.7 webencodings==0.5.1 whitenoise==6.6.0 wrapt==1.13.3 +boto3==1.33.6 \ No newline at end of file diff --git a/template.env b/template.env index 7e1a8eb..f107362 100644 --- a/template.env +++ b/template.env @@ -21,5 +21,11 @@ DROPBOX_APP_KEY="" DROPBOX_APP_SECRET="" DROPBOX_OAUTH2_REFRESH_TOKEN="" -#for testing dropbox related functionality in development -USE_DROPBOX_IN_DEVELOPMENT=False +#for using local storage in development +USE_LOCAL_STORAGE=True + +#AWS/BackBlaze configuration +AWS_ACCESS_KEY_ID ='' +AWS_SECRET_ACCESS_KEY ='' +AWS_STORAGE_BUCKET_NAME ='' +AWS_S3_REGION_NAME='' \ No newline at end of file