# TanjaX API
This project is a Flask-based web API that retrieves random images from specified Dropbox folders and provides direct links to these images. The API uses Auth0 for authentication and authorization, ensuring that only authorized users can access the API.
## Features
- Authenticate with Auth0
- List and fetch random images from specified Dropbox folders
- Provide direct links to images
- Handle existing shared links and create new ones if necessary
- Cross-Origin Resource Sharing (CORS) enabled
## Prerequisites
- Python 3.x
- A Dropbox account and a Dropbox app
- Auth0 account
## Installation
1. **Clone the repository:**
```bash
git clone https://github.com/your-username/tanjax-api.git
cd tanjax-api
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root directory and add the following environment variables:API_TITLE=Your API Title DROPBOX_TOKEN=your_dropbox_token DROPBOX_APP_KEY=your_dropbox_app_key DROPBOX_REFRESH_TOKEN=your_dropbox_refresh_token DROPBOX_FOLDER_PATH=/path/to/your/dropbox/folder DROPBOX_FOLDER_APPROVE=/path/to/approve/folder DROPBOX_FOLDER_DELETE=/path/to/delete/folder DROPBOX_FOLDER_REWORK=/path/to/rework/folder REACT_APP_AUTH0_DOMAIN=your-auth0-domain REACT_APP_AUTH0_CLIENT_ID=your-auth0-client-id REACT_APP_AUTH0_AUDIENCE=your-auth0-audience
-
Create a Dropbox app:
- Go to the Dropbox App Console.
- Create a new app and get the
APP_KEY
andAPP_SECRET
.
-
Generate a Refresh Token:
- Follow the Dropbox OAuth 2 guide to generate a refresh token.
- Ensure the necessary permissions (scopes) are granted to access the files.
-
Create an Auth0 Application:
- Go to the Auth0 Dashboard.
- Create a new Single Page Application.
- Get the
DOMAIN
,CLIENT_ID
, andAUDIENCE
.
-
Update Application Settings:
- Ensure your application is configured to use the created API.
- Enable CORS for your application's URL.
-
Run the Flask API:
flask run
-
Run the React Application:
cd react-app npm install npm start
Open your web browser and navigate to
http://localhost:3000/
.
-
Set environment variables on PythonAnywhere:
- Go to the "Web" tab on PythonAnywhere.
- Find the "Environment Variables" section and set your environment variables.
-
Restart your web app:
- Ensure your changes take effect by restarting the web app from the "Web" tab.
- Authenticate using Auth0.
- Access the random image endpoint to get a direct link to a random image from Dropbox.
- The API will handle existing shared links or create new ones as needed.
GET /
: Returns the API title.GET /image
: Returns a random image URL from the specified Dropbox folder.
- The API uses Python's built-in logging module to log important events and errors.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.