From 7531302b49936ce8effebaf3336e4206a21bb167 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Mon, 24 Feb 2025 22:13:56 +0330 Subject: [PATCH] aw3 file server added to backend --- backend/core/settings/base.py | 21 ++++++++++++++++++- backend/core/settings/production.py | 11 +++++++++- backend/core/storages.py | 6 ++++++ backend/requirements.txt | 32 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 backend/core/storages.py diff --git a/backend/core/settings/base.py b/backend/core/settings/base.py index 96b8693..c1d752b 100644 --- a/backend/core/settings/base.py +++ b/backend/core/settings/base.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", # Third-Party Apps + "storages", "corsheaders", "rest_framework", "drf_spectacular", @@ -212,4 +213,22 @@ JALALI_SETTINGS = { "admin/css/main.css", ] }, -} \ No newline at end of file +} + + +# ============================================================================== +# AWS S3 setting for production +# ============================================================================== +AWS_ACCESS_KEY_ID = 'mtiSN2JWjWgyfr2u' +AWS_SECRET_ACCESS_KEY = 'ZGmOM6ekLJEswJS1kOLp49B8DQ3GT0HZ' +AWS_STORAGE_BUCKET_NAME = 'c262408' +AWS_S3_ENDPOINT_URL = 'https://parspack.net' +AWS_S3_REGION_NAME = 'default' +AWS_S3_SIGNATURE_VERSION = 's3' +AWS_S3_ADDRESSING_STYLE = 'virtual' +AWS_QUERYSTRING_AUTH = True +AWS_DEFAULT_ACL = None +AWS_S3_OBJECT_PARAMETERS = { + 'CacheControl': 'max-age=86400', +} + diff --git a/backend/core/settings/production.py b/backend/core/settings/production.py index 2a5497f..3ec44aa 100644 --- a/backend/core/settings/production.py +++ b/backend/core/settings/production.py @@ -33,7 +33,16 @@ DATABASES = { } } -MEDIA_URL = '/shop_media/' +STORAGES = { + "default": { + "BACKEND": 'core.storages.MediaStorage', + }, + "staticfiles": { + "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", + }, +} + +MEDIA_URL = 'https://c262408.parspack.net/' MEDIA_ROOT = '/app/media' STATIC_URL = '/shop_static/' diff --git a/backend/core/storages.py b/backend/core/storages.py new file mode 100644 index 0000000..766fd23 --- /dev/null +++ b/backend/core/storages.py @@ -0,0 +1,6 @@ +from storages.backends.s3boto3 import S3Boto3Storage + + +class MediaStorage(S3Boto3Storage): + location = 'media' + default_acl = 'private' \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index ca6be94..83cdbca 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -5,22 +5,33 @@ annotated-types==0.7.0 anyio==4.6.0 asgiref==3.8.1 attrs==24.2.0 +az-iranian-bank-gateways==2.0.5 +beautifulsoup4==4.12.3 +boto3==1.36.26 +botocore==1.36.26 branca==0.8.1 certifi==2024.8.30 cffi==1.17.1 charset-normalizer==3.3.2 +colorama==0.4.6 cryptography==44.0.1 defusedxml==0.8.0rc2 diff-match-patch==20230430 distro==1.9.0 Django==5.1.2 +django-admin-interface==0.28.5 +django-admin-persian-fonts==0.2 django-cleanup==8.1.0 +django-colorfield==0.11.0 django-cors-headers==4.4.0 +django-cron==0.6.0 django-dbbackup==4.2.1 +django-dirtyfields==1.9.3 django-filter==24.3 django-import-export==4.1.1 django-iranian-cities==1.0.2 django-jalali==7.3.0 +django-storages==1.14.5 django-unfold==0.48.0 djangorestframework==3.15.2 djangorestframework-simplejwt==5.3.1 @@ -28,6 +39,7 @@ djoser==2.3.1 dnspython==2.7.0 drf-spectacular==0.27.2 email_validator==2.2.0 +et-xmlfile==1.1.0 factory_boy==3.3.1 Faker==28.4.1 folium==0.19.4 @@ -43,29 +55,40 @@ httpcore==1.0.5 httpx==0.27.2 idna==3.10 inflection==0.5.1 +isodate==0.6.1 jalali_core==1.0.0 jdatetime==5.0.0 Jinja2==3.1.5 jiter==0.8.2 +jmespath==1.0.1 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 +lxml==5.2.2 +MarkupPy==1.14 MarkupSafe==3.0.2 maxminddb==2.6.2 multidict==6.1.0 numpy==2.2.3 oauthlib==3.2.2 +odfpy==1.4.1 openai==1.58.1 +openpyxl==3.1.2 pillow==10.4.0 +platformdirs==4.2.2 +propcache==0.2.0 psutil==6.0.0 psycopg2-binary==2.9.10 py-vapid==1.9.2 pycparser==2.22 +pycryptodome==3.20.0 pydantic==2.10.6 pydantic_core==2.27.2 PyJWT==2.10.1 pyTelegramBotAPI==4.23.0 python-dateutil==2.9.0.post0 +python-decouple==3.8 python-dotenv==1.0.1 +python-slugify==8.0.4 python-telegram-bot==21.6 python3-openid==3.2.0 pytz==2024.2 @@ -73,20 +96,29 @@ pywebpush==2.0.3 PyYAML==6.0.2 referencing==0.35.1 requests==2.32.3 +requests-file==2.1.0 requests-oauthlib==2.0.0 +requests-toolbelt==1.0.0 rpds-py==0.20.0 +s3transfer==0.11.2 setuptools==75.1.0 six==1.16.0 sniffio==1.3.1 social-auth-app-django==5.4.2 social-auth-core==4.5.4 +soupsieve==2.5 sqlparse==0.5.1 tablib==3.5.0 +telebot==0.0.5 +text-unidecode==1.3 tqdm==4.67.1 typing_extensions==4.12.2 tzdata==2024.1 uritemplate==4.1.1 urllib3==2.2.3 whitenoise==6.7.0 +xlrd==2.0.1 +xlwt==1.3.0 xyzservices==2025.1.0 yarl==1.11.1 +zeep==4.2.1