### Initialize Cloud Provider Setup Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Sets up the cloud provider handler based on user configuration. Ensure 'Filestack' and 'your_api_key_here' are replaced with actual values. ```python from logic.cloud import CloudSetup # Initialize cloud setup with user's provider and API key user_data = { "cloud_provider": "Filestack", "cloud_provider_api_key": "your_api_key_here" } # Create cloud setup instance cloud_setup = CloudSetup( cloud_provider=user_data["cloud_provider"], api_key=user_data["cloud_provider_api_key"] ) # Get the configured cloud provider handler cloud_handler = cloud_setup.setup() # Initialize the cloud provider client if cloud_handler is not None: cloud_handler.setup() print("Cloud provider initialized successfully") ``` -------------------------------- ### Flask Server Setup with SQLAlchemy Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Initializes a Flask application and configures SQLAlchemy for database integration using SQLite. This setup is essential for running the backend server. ```python from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) # Initialize database and run server if __name__ == '__main__': with app.app_context(): db.create_all() # Creates all database tables app.run(debug=True) # Runs on http://127.0.0.1:5000 # Production server configuration # APP_BASE_URL = "https://mayuresh22.pythonanywhere.com/" ``` -------------------------------- ### Get User Files Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Retrieves all files belonging to an authenticated user. Requires user ID and API key for authentication. ```APIDOC ## POST /files/ ### Description Retrieves all files belonging to an authenticated user. Requires user ID and API key for authentication. ### Method POST ### Endpoint /files/ ### Parameters #### Request Body - **file_owner** (integer) - Required - The ID of the user whose files are to be retrieved. - **cloud_provider_api_key** (string) - Required - The API key for authenticating the user. ### Request Example ```json { "file_owner": 1, "cloud_provider_api_key": "your_filestack_api_key" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message confirming the files were retrieved successfully. - **files** (array) - A list of file objects belonging to the user. - **id** (integer) - The unique identifier of the file. - **file_owner** (integer) - The ID of the user who owns the file. - **file_name** (string) - The name of the file. - **file_size** (integer) - The size of the file in bytes. - **file_type** (string) - The MIME type of the file. - **file_url** (string) - The public URL of the file in cloud storage. - **file_handle** (string) - The handle or identifier for the file in cloud storage. - **file_status** (string) - The current status of the file (e.g., "Stored"). #### Response Example ```json { "status": "success", "message": "Files Retrieved Successfully", "files": [ { "id": 1, "file_owner": 1, "file_name": "document.pdf", "file_size": 102400, "file_type": "application/pdf", "file_url": "https://cdn.filestackcontent.com/abc123", "file_handle": "abc123", "file_status": "Stored" }, { "id": 2, "file_owner": 1, "file_name": "photo.jpg", "file_size": 51200, "file_type": "image/jpeg", "file_url": "https://cdn.filestackcontent.com/def456", "file_handle": "def456", "file_status": "Stored" } ] } ``` ``` -------------------------------- ### Application Entry Point Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Initializes the CustomTkinter window and launches the authentication flow. Loads environment variables from a .env file. ```python from view.authframe import AuthFrame import customtkinter as ctk from dotenv import load_dotenv import os load_dotenv(".env") class App: def __init__(self): # Create main window self.root = ctk.CTk() self.root.title(os.getenv("APP_TITLE")) self.root.geometry(f"{os.getenv('DEFAULT_APP_WIDTH')}x{os.getenv('DEFAULT_APP_HEIGHT')}") self.root.resizable(False, False) self.root.iconbitmap(os.getenv("APP_ICON")) # Launch authentication frame AuthFrame(self.root) # Start the application self.root.mainloop() def app_config(self): # Configure appearance theme ctk.set_appearance_mode(os.getenv("DEFAULT_APPEARANCE_MODE")) ctk.set_default_color_theme(os.getenv("DEFAULT_COLOR_THEME")) # Run the application if __name__ == "__main__": app = App() ``` -------------------------------- ### Register New User Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Creates a new user account with cloud provider credentials. Validates that the username is unique. ```bash # Registration request curl -X POST http://127.0.0.1:5000/users/register/ \ -H "Content-Type: application/json" \ -d '{ "username": "jane_doe", "password": "secure_password456", "name": "Jane Doe", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key_here" }' # Successful response { "status": "success", "message": "Registration Successful", "id": 2, "name": "Jane Doe", "username": "jane_doe", "password": "secure_password456", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key_here" } # User exists response { "status": "User Already Exists, Select another Username" } ``` -------------------------------- ### Home Logic for File Management Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Core business logic for file operations including upload, download, and display of user files. Requires initialized user data and GUI widgets. ```python from logic.homelogic import HomeLogic # Initialize with authenticated user data user_obj = { "id": 1, "name": "John Doe", "username": "john_doe", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_api_key" } home_logic = HomeLogic(user_obj) # Upload a file (launches file dialog, uploads to cloud, stores metadata) home_logic.launch_file_explorer( files_frame=scrollable_files_widget, progress=progress_label_widget ) # Populate files grid with user's cloud files home_logic.populate_files(files_frame=scrollable_files_widget) # Download a specific file home_logic.download_file( file_url="https://cdn.filestackcontent.com/abc123", file_name="document.pdf" ) # Navigate to account settings home_logic.load_account_frame( parent=root_window, current=home_frame, userobj=user_obj ) ``` -------------------------------- ### User Authentication Logic Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Manages user login and registration. Requires GUI components like `root_window`, `auth_frame`, and `error_label_widget` to be defined. ```python from logic.authlogic import AuthLogic # User login authentication # Called from AuthFrame with GUI components AuthLogic.auth_user_login( parent=root_window, current=auth_frame, username="john_doe", password="secure_password123", errorlabel=error_label_widget ) # Response handling (internal): # - On success: Redirects to HomeFrame with user data # - On failure: Displays error message on errorlabel widget # User registration AuthLogic.auth_user_register( parent=root_window, current=auth_frame, name="Jane Doe", username="jane_doe", password="secure_password456", cloud_provider="Filestack", api_key="your_filestack_api_key", errorlabel=error_label_widget ) ``` -------------------------------- ### Authenticate User Login Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Authenticates a user via POST request and returns profile data including the cloud provider API key. ```bash # Login request curl -X POST http://127.0.0.1:5000/users/login/ \ -H "Content-Type: application/json" \ -d '{ "username": "john_doe", "password": "secure_password123" }' # Successful response { "status": "success", "message": "Login Successful", "id": 1, "name": "John Doe", "username": "john_doe", "password": "secure_password123", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key" } # Failed response { "status": "fail", "message": "Login Failed, try again" } ``` -------------------------------- ### User Registration Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Registers a new user with username, password, name, and cloud provider credentials. Validates username uniqueness before creating the account. ```APIDOC ## POST /users/register/ ### Description Registers a new user with username, password, name, and cloud provider credentials. Validates username uniqueness before creating the account. ### Method POST ### Endpoint /users/register/ ### Parameters #### Request Body - **username** (string) - Required - The username for the new account. - **password** (string) - Required - The password for the new account. - **name** (string) - Required - The full name of the user. - **cloud_provider** (string) - Required - The cloud storage provider to be used. - **cloud_provider_api_key** (string) - Required - The API key for the cloud storage provider. ### Request Example ```json { "username": "jane_doe", "password": "secure_password456", "name": "Jane Doe", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key_here" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message confirming the registration success. - **id** (integer) - The unique identifier of the newly registered user. - **name** (string) - The name of the user. - **username** (string) - The username of the user. - **password** (string) - The password of the user. - **cloud_provider** (string) - The cloud storage provider used by the user. - **cloud_provider_api_key** (string) - The API key for the cloud storage provider. #### Error Response (400) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message indicating that the username is already taken. #### Response Example (Success) ```json { "status": "success", "message": "Registration Successful", "id": 2, "name": "Jane Doe", "username": "jane_doe", "password": "secure_password456", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key_here" } ``` #### Response Example (User Exists) ```json { "status": "User Already Exists, Select another Username" } ``` ``` -------------------------------- ### Retrieve User Files Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Fetches all files associated with a specific user ID, requiring the cloud provider API key for authentication. ```bash # Get files request curl -X POST http://127.0.0.1:5000/files/ \ -H "Content-Type: application/json" \ -d '{ "file_owner": 1, "cloud_provider_api_key": "your_filestack_api_key" }' # Successful response { "status": "success", "message": "Files Retrieved Successfully", "files": [ { "id": 1, "file_owner": 1, "file_name": "document.pdf", "file_size": 102400, "file_type": "application/pdf", "file_url": "https://cdn.filestackcontent.com/abc123", "file_handle": "abc123", "file_status": "Stored" }, { "id": 2, "file_owner": 1, "file_name": "photo.jpg", "file_size": 51200, "file_type": "image/jpeg", "file_url": "https://cdn.filestackcontent.com/def456", "file_handle": "def456", "file_status": "Stored" } ] } ``` -------------------------------- ### Upload File Metadata Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Registers file metadata in the database after the file has been uploaded to the cloud provider. ```bash # Upload file metadata request curl -X POST http://127.0.0.1:5000/files/upload/ \ -H "Content-Type: application/json" \ -d '{ "file_owner": 1, "cloud_provider_api_key": "your_filestack_api_key", "file_name": "report.pdf", "file_size": 204800, "file_type": "application/pdf", "file_url_pub": "https://cdn.filestackcontent.com/xyz789", "file_url_pvt": "", "file_handle": "xyz789", "file_status": "Stored" }' # Successful response { "status": "success", "message": "File Uploaded Successfully" } # Authentication failure response { "status": "fail", "message": "Authentication Failed" } ``` -------------------------------- ### Check File Existence Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Verifies if a file name is already taken by the user to prevent duplicate uploads. ```bash # Check file existence request curl -X POST http://127.0.0.1:5000/files/upload/check/ \ -H "Content-Type: application/json" \ -d '{ "file_owner": 1, "file_name": "document.pdf" }' # File exists response { "status": "success", "file_exists": "True", "message": "File Already Exists" } # File does not exist response { "status": "fail", "file_exists": "False", "message": "File Does Not Exist" } ``` -------------------------------- ### User Login Authentication Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Authenticates a user with username and password credentials. Returns user profile data including cloud provider API key on successful login. ```APIDOC ## POST /users/login/ ### Description Authenticates a user with username and password credentials. Returns user profile data including cloud provider API key on successful login. ### Method POST ### Endpoint /users/login/ ### Parameters #### Request Body - **username** (string) - Required - The username for login. - **password** (string) - Required - The password for login. ### Request Example ```json { "username": "john_doe", "password": "secure_password123" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message confirming the operation's success. - **id** (integer) - The unique identifier of the user. - **name** (string) - The name of the user. - **username** (string) - The username of the user. - **password** (string) - The password of the user. - **cloud_provider** (string) - The cloud storage provider used by the user. - **cloud_provider_api_key** (string) - The API key for the cloud storage provider. #### Error Response (400) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message indicating login failure. #### Response Example (Success) ```json { "status": "success", "message": "Login Successful", "id": 1, "name": "John Doe", "username": "john_doe", "password": "secure_password123", "cloud_provider": "Filestack", "cloud_provider_api_key": "your_filestack_api_key" } ``` #### Response Example (Failure) ```json { "status": "fail", "message": "Login Failed, try again" } ``` ``` -------------------------------- ### Check File Existence Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Checks if a file with the same name already exists for a user before uploading to prevent duplicates. ```APIDOC ## POST /files/upload/check/ ### Description Checks if a file with the same name already exists for a user before uploading to prevent duplicates. ### Method POST ### Endpoint /files/upload/check/ ### Parameters #### Request Body - **file_owner** (integer) - Required - The ID of the user. - **file_name** (string) - Required - The name of the file to check. ### Request Example ```json { "file_owner": 1, "file_name": "document.pdf" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **file_exists** (string) - "True" if the file exists, "False" otherwise. - **message** (string) - A message indicating whether the file exists. #### Error Response (400) - **status** (string) - Indicates the status of the operation. - **file_exists** (string) - "False". - **message** (string) - A message indicating the file does not exist. #### Response Example (File Exists) ```json { "status": "success", "file_exists": "True", "message": "File Already Exists" } ``` #### Response Example (File Does Not Exist) ```json { "status": "fail", "file_exists": "False", "message": "File Does Not Exist" } ``` ``` -------------------------------- ### Filestack File Operations Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Handles file upload and download operations using the Filestack service. Replace placeholders with actual API keys, file paths, and URLs. ```python from logic.cloud import Filestack # Initialize Filestack with API key filestack_client = Filestack(api_key="your_filestack_api_key") filestack_client.setup() # Upload a file to cloud storage file_path = "/path/to/document.pdf" filelink = filestack_client.upload_file(file_path) # Access uploaded file details if filelink.upload_response["status"] == "Stored": print(f"File uploaded successfully!") print(f"Filename: {filelink.upload_response['filename']}") print(f"Size: {filelink.upload_response['size']} bytes") print(f"Type: {filelink.upload_response['mimetype']}") print(f"URL: {filelink.upload_response['url']}") print(f"Handle: {filelink.upload_response['handle']}") # Download a file from cloud storage file_url = "https://cdn.filestackcontent.com/abc123" file_name = "document.pdf" filestack_client.download_file(file_url, file_name) # Opens save dialog for user to choose download location ``` -------------------------------- ### UserDB SQLAlchemy Model Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Defines the UserDB model for storing user account information and cloud provider credentials. Use this model to interact with the user database. ```python from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() class UserDB(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password_hash = db.Column(db.String(20), nullable=False) name = db.Column(db.String(20), nullable=False) cloud_provider = db.Column(db.String(20), nullable=False) cloud_provider_api_key = db.Column(db.String(20), nullable=False) ``` ```python user = UserDB.query.filter_by(username="john_doe").first() user = UserDB.query.filter_by(username="john_doe", password_hash="password123").first() all_users = UserDB.query.all() ``` ```python new_user = UserDB( username="jane_doe", password_hash="secure_password", name="Jane Doe", cloud_provider="Filestack", cloud_provider_api_key="api_key_here" ) db.session.add(new_user) db.session.commit() ``` -------------------------------- ### Upload File Metadata Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Stores file metadata in the database after successful upload to cloud storage. Validates user authentication before storing. ```APIDOC ## POST /files/upload/ ### Description Stores file metadata in the database after successful upload to cloud storage. Validates user authentication before storing. ### Method POST ### Endpoint /files/upload/ ### Parameters #### Request Body - **file_owner** (integer) - Required - The ID of the user uploading the file. - **cloud_provider_api_key** (string) - Required - The API key for authenticating the user. - **file_name** (string) - Required - The name of the file. - **file_size** (integer) - Required - The size of the file in bytes. - **file_type** (string) - Required - The MIME type of the file. - **file_url_pub** (string) - Optional - The public URL of the file in cloud storage. - **file_url_pvt** (string) - Optional - The private URL of the file in cloud storage. - **file_handle** (string) - Required - The handle or identifier for the file in cloud storage. - **file_status** (string) - Required - The current status of the file (e.g., "Stored"). ### Request Example ```json { "file_owner": 1, "cloud_provider_api_key": "your_filestack_api_key", "file_name": "report.pdf", "file_size": 204800, "file_type": "application/pdf", "file_url_pub": "https://cdn.filestackcontent.com/xyz789", "file_url_pvt": "", "file_handle": "xyz789", "file_status": "Stored" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message confirming the file metadata was uploaded successfully. #### Error Response (401) - **status** (string) - Indicates the status of the operation. - **message** (string) - A message indicating authentication failure. #### Response Example (Success) ```json { "status": "success", "message": "File Uploaded Successfully" } ``` #### Response Example (Authentication Failure) ```json { "status": "fail", "message": "Authentication Failed" } ``` ``` -------------------------------- ### FilesDB SQLAlchemy Model Source: https://context7.com/mayuresh-22/clouddrive/llms.txt Defines the FilesDB model for storing file metadata, including cloud storage URLs and handles. Use this model to manage file information in the database. ```python class FilesDB(db.Model): id = db.Column(db.Integer, primary_key=True) file_owner = db.Column(db.Integer, nullable=False) file_name = db.Column(db.String(20), nullable=False) file_size = db.Column(db.Integer, nullable=False) file_type = db.Column(db.String(20), nullable=False) file_url_pub = db.Column(db.String(250), nullable=False) file_url_pvt = db.Column(db.String(500), nullable=False) file_handle = db.Column(db.String(100), nullable=False) file_status = db.Column(db.String(20), nullable=False) ``` ```python user_files = FilesDB.query.filter_by(file_owner=1).all() ``` ```python existing_file = FilesDB.query.filter_by( file_name="document.pdf", file_owner=1 ).first() ``` ```python new_file = FilesDB( file_owner=1, file_name="report.pdf", file_size=204800, file_type="application/pdf", file_url_pub="https://cdn.filestackcontent.com/xyz789", file_url_pvt="", file_handle="xyz789", file_status="Stored" ) db.session.add(new_file) db.session.commit() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.