- clone the repo
- create .env file based on .env.example
- Run docker compose
docker-compose up --build
- connect to the docker image CLI
- Make migrations, migrate and create super user:
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
- Restart docker image if needed
- Go to "http://127.0.0.1:8000/admin/" and create tiers and users with tier attached.
- Go to "http://127.0.0.1:8000/api/images" and login. NOTE: Users need to be authenticated (loged in) and have a tier to be able to use API
- When no longer needed unmount docker image:
docker-compose down
- NOTE: In requirements.txt libraries for tests and formating were commented out. If you want you can bring them back.
-
You can check detailed swagger documentation at localhost:5000/apidocs
-
GET "http://127.0.0.1:8000/api-auth/login/" - returns csrf token
-
POST "http://127.0.0.1:8000/api-auth/login/" - login user
{
{
"X-CSRFToken": <csrftoken>
},
{
"username": <str>,
"password": <str>
}
}
-
GET "http://127.0.0.1:8000/api-auth/logout/" - logout user
-
GET "http://127.0.0.1:8000/api/images" - returns current user images if images exist depending on user tier:
{
{
"id": <uuid>,
"img_px200": <image_url>,
"img_px400": <optional:image_url>,
"img_native": <optional:image_url>,
"temp_url": <optional:image_url>,
"delete_url_time_left_second": <optional:int>
}
}
- POST "http://127.0.0.1:8000/api/images" - upload image. Users with generated_url tier can add time in seconds after which temp_url will expire (default between 300 and 30_000 seconds):
{
{
"X-CSRFToken": <csrftoken>
},
{
"image": <image>,
"delete_url_time": <optional:int>
}
}
-
During uploading file, image is validated by django build-in "FileExtensionValidator" to validate that the file extension is supported by Pillow. "validate_image_file_extension"
-
Custom validators in "validators.py" file:
- validate_image() - checks if: -- image is present -- image file size is less than 3 MB (settings.py) -- image extension is .jpg or .png. NOTE: Just checks the filename extension not the acctual extension. It's required by django documentation not to rely on this type of validation. "Files can be renamed to have any extension no matter what data they contain." https://docs.djangoproject.com/en/4.1/ref/validators/#fileextensionvalidator