diff --git a/.bin/bkup/clear_all_services.sh b/.bin/bkup/clear_all_services.sh new file mode 100755 index 0000000..854452a --- /dev/null +++ b/.bin/bkup/clear_all_services.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Determine the environment (e.g., from an env var) +ENVIRONMENT=${ENVIRONMENT:-development} + +# Source the appropriate .env file based on the environment +if [ "$ENVIRONMENT" == "development" ]; then + source .env +else + source .env.development +fi + +# Function to check if a string is a valid numeric port +is_numeric_port() { + [[ $1 =~ ^[0-9]+$ ]] +} + +# Function to clear a single port +clear_port() { + local PORT=$1 + + # Find the process ID using lsof + PID=$(lsof -i :$PORT -t) + + if [ -z "$PID" ]; then + echo "No process found running on port $PORT." + else + echo "Killing process $PID running on port $PORT..." + kill $PID + if [ $? -eq 0 ]; then + echo "Process $PID has been successfully terminated." + else + echo "Failed to terminate process $PID." + fi + fi +} + +# Read the .env file and extract ports with debugging output +while IFS='=' read -r key value; do + # Check if the line is a valid environment variable + if [[ "$key" == PORT* || "$key" == *_PORT ]]; then + echo "Found port variable: $key=$value" + # Check if the value is a numeric port + if is_numeric_port "$value"; then + clear_port "$value" + else + echo "Skipping non-numeric port value: $key=$value" + fi + fi +done < .env + +# Optionally, you can also clear specific ports mentioned in .env.example +while IFS='=' read -r key value; do + # Check if the line is a valid environment variable + if [[ "$key" == PORT* || "$key" == *_PORT ]]; then + echo "Found port variable: $key=$value" + # Check if the value is a numeric port + if is_numeric_port "$value"; then + clear_port "$value" + else + echo "Skipping non-numeric port value: $key=$value" + fi + fi +done < .env.example \ No newline at end of file diff --git a/.bin/bkup/start_gunicorn copy.sh b/.bin/bkup/start_gunicorn copy.sh new file mode 100755 index 0000000..fdf1a6c --- /dev/null +++ b/.bin/bkup/start_gunicorn copy.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +# Print all environment variables +echo "Environment variables:" +printenv + +# Ensure all required packages are installed +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log +npm install &> ./.tmp/npm_install_output.log + +# Start the Node.js server in the background and store its PID +echo "Starting Node.js server..." +npx tsc -w &> ./.tmp/node_output.log & +node app/static/templates/server/server.js +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & + +# Activate your virtual environment (if not already activated) +source ./.venv/bin/activate + +# Check if the virtual environment is correctly set up +echo "Checking virtual environment..." +python3 --version # Verify Python version +pip list | grep Flask # Verify Flask installation +npm --version # Verify Node.js installation +if [ $? -ne 0 ]; then + echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'" + deactivate + exit 1 +fi + +# Read port from environment variable, default to 8000 if not set +PORT=${FLASK_PORT:-4000} +echo "Starting Gunicorn server on port $PORT with gevent workers..." +nohup gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 & + +echo "Gunicorn server started on port $PORT." + +# Deactivate the virtual environment +deactivate + +# Tail the Gunicorn output for real-time logs (optional, but useful) +echo "Gunicorn server is running. Checking logs..." +tail -f ./.tmp/gunicorn_output.log & \ No newline at end of file diff --git a/.bin/bkup/start_gunicorn.sh b/.bin/bkup/start_gunicorn.sh new file mode 100755 index 0000000..6cafd98 --- /dev/null +++ b/.bin/bkup/start_gunicorn.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +# Ensure all required packages are installed +echo "Checking if required packages are installed..." + +# Install dependencies +pip install -r ./requirements.txt &> /dev/null +if [ $? -ne 0 ]; then + echo "One or more dependencies are missing. Please install them using 'pip install -r requirements.txt'" + pip install --upgrade pip + pip install -r requirements.txt + exit 1 +fi + +# Check if the virtual environment is activated +if [ ! -d ".venv" ]; then + echo "Virtual environment not found. Creating it using 'python3 -m venv .venv'..." + python3 -m venv .venv +fi + +echo "Activating virtual environment..." +source ./.venv/bin/activate &> /dev/null +if [ $? -ne 0 ]; then + echo "Failed to activate virtual environment. Please ensure it is correctly set up." + exit 1 +fi + +# Check if gunicorn is installed +pip show gunicorn &> /dev/null +if [ $? -ne 0 ]; then + echo "gunicorn is not installed. Installing it..." + pip install gunicorn +fi + +# Read port from environment variable, default to 8000 if not set +PORT=${FLASK_PORT:-8000} +echo "Starting Gunicorn server on port $PORT with gevent workers..." +nohup gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 & + +echo "Gunicorn server started on port $PORT." + +# Deactivate the virtual environment +deactivate + +# --worker-class gevent: This tells Gunicorn to use the gevent worker class, +# which is more suitable for high-concurrency applications and +# can handle many requests using fewer resources. + +# --workers 3: Specifies the number of worker processes. You can adjust this based on your server's CPU cores +# and available memory. \ No newline at end of file diff --git a/.bin/bkup/start_services.sh b/.bin/bkup/start_services.sh new file mode 100755 index 0000000..b5829da --- /dev/null +++ b/.bin/bkup/start_services.sh @@ -0,0 +1,91 @@ +#!/bin/bash + + +# Activate your virtual environment (if not already activated) +source ./.venv/bin/activate + +# Check if the virtual environment is correctly set up +echo "Checking virtual environment..." +python3 --version # Verify Python version +pip list | grep Flask # Verify Flask installation +npm --version # Verify Node.js installation +if [ $? -ne 0 ]; then + echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'" +# stop the node server + deactivate + exit 1 +fi + +# Ensure all required packages are installed +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log + +# Start the Node.js server +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +npm install &> ./.tmp/node_output.log & +node ./app/index.js &> ./.tmp/node_output.log & +npm run watch-css &> ./.tmp/node_output.log & +NODE_JS_PID=$! + + +# Set the FLASK_APP environment variable to point to your app.py file and specify the port +export FLASK_APP=./app/run_app.py +export FLASK_RUN_PORT=${FLASK_RUN_PORT} # Specify the desired port here + +# Start the Flask application in the background and store its PID +echo "Starting Flask server on port $FLASK_RUN_PORT..." +flask run &> ./.tmp/flask_output.log & +FLASK_PID=$! + +# Wait for 2 seconds to ensure the Flask server has started +sleep 2 + +# Check if the Flask process is running +if ps -p $FLASK_PID > /dev/null; then + echo "Flask server PID: $FLASK_PID" +else + echo "Failed to start Flask server." + cat ./.tmp/flask_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Tail the Flask output for real-time logs (optional, but useful) +echo "Flask server is running. Checking logs..." +tail -f ./.tmp/flask_output.log & + +# Run any additional Python scripts (e.g., Voice_v2.py) and capture their output +echo "Running additional services..." +python3.11 ./app/run_app.py &> ./.tmp/voice_output.log & + +# Optionally, wait for a few more seconds before exiting +sleep 5 + +# Kill the Flask process if it's still running after `Voice_v2.py` finishes +if [ -n "$FLASK_PID" ]; then + echo "Waiting for Flask server to finish..." + sleep 10 # Give some time for cleanup + kill $FLASK_PID || true # Kill the process, ignore errors if it's already gone + echo "Killed Flask server with PID: $FLASK_PID" +fi + +# Check if the Node.js server is running +if [ -n "$NODE_JS_PID" ]; then + if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" + else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + fi +else + echo "$NODE_JS_PID is not set. Node.js server was not started or PID capture failed." +fi + +# Wait for a few more seconds before exiting +# sleep 100 + +echo "All services started successfully." + +# Deactivate the virtual environment and exit +deactivate \ No newline at end of file diff --git a/.bin/bkup/start_services_2 copy.sh b/.bin/bkup/start_services_2 copy.sh new file mode 100755 index 0000000..87df546 --- /dev/null +++ b/.bin/bkup/start_services_2 copy.sh @@ -0,0 +1,150 @@ +#!/bin/bash + + +# Print all environment variables +# echo "Environment variables:" +# printenv +# Ensure all required packages are installed +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log +npm install &> ./.tmp/npm_install_output.log + +# Start the Node.js server +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +rm -rf app/static &> ./.tmp/node_output.log & +npx tsc -w &> ./.tmp/node_output.log & +# npx ts-node app/templates/server/server.ts &> ./.tmp/node_output.log & + +# Start the Node.js server in the background and store its PID +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +rm -rf app/static &> ./.tmp/node_output.log & +npx tsc -w &> ./.tmp/node_output.log & +# npx ts-node app/templates/server/server.ts &> ./.tmp/node_output.log & + +# Start the Node.js server in the background and store its PID +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & + +# Node APP +node ./app/static/templates/server/server.js &> ./.tmp/node_output.log & +npm run build-css &> ./.tmp/node_output.log & +npx nodemon ./app/static/templates/sever/server.js &> ./.tmp/node_output.log & + +# Activate your virtual environment (if not already activated) +source ./.venv/bin/activate + +# Check if the virtual environment is correctly set up +echo "Checking virtual environment..." +python3 --version # Verify Python version +pip list | grep Flask # Verify Flask installation +npm --version # Verify Node.js installation +if [ $? -ne 0 ]; then + echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'" + deactivate + exit 1 +fi + +# Set the FLASK_APP environment variable to point to your app.py file and specify the port +export FLASK_APP=./app/run_app.py +export FLASK_RUN_PORT=${FLASK_RUN_PORT:-4000} # Specify the desired port here (default is 4000) + +# Start the Flask application in the background and store its PID +echo "Starting Flask server on port $FLASK_RUN_PORT..." +flask run &> ./.tmp/flask_output.log & +FLASK_PID=$! + +# Wait for 2 seconds to ensure the Flask server has started +sleep 2 + +# Check if the Flask process is running +if ps -p $FLASK_PID > /dev/null; then + echo "Flask server PID: $FLASK_PID" +else + echo "Failed to start Flask server." + cat ./.tmp/flask_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Tail the Flask output for real-time logs (optional, but useful) +echo "Flask server is running. Checking logs..." +tail -f ./.tmp/flask_output.log & + +# Run any additional Python scripts (e.g., Voice_v2.py) and capture their output +echo "Running additional services..." +python3.11 ./app/tools/Voice_v2.py &> ./.tmp/voice_output.log & + +# Function to shut down Node.js server using clear_ports.sh +shutdown_nodejs() { + echo "Shutting down servers..." + + # Read the .env file and extract ports based on environment variable names ending with 'PORT' + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + .bin/clear_ports.sh "$value" + fi + done < .env +} + +# Function to review all environment ports in use +review_ports() { + echo "Reviewing all environment ports in use..." + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + echo "Port in use: $key=$value" + fi + done < .env +} + +# Optionally, wait for a few more seconds before exiting +sleep 60 + +# Kill the Flask process if it's still running after `Voice_v2.py` finishes +if [ -n "$FLASK_PID" ]; then + echo "Waiting for Flask server to finish..." + sleep 10 # Give some time for cleanup + kill $FLASK_PID || true # Kill the process, ignore errors if it's already gone + echo "Killed Flask server with PID: $FLASK_PID" +fi + +# Call the shutdown_nodejs function to terminate Node.js server +shutdown_nodejs + +# Review all environment ports in use +review_ports + +echo "All services have been shut down." \ No newline at end of file diff --git a/.bin/bkup/start_services_2.sh b/.bin/bkup/start_services_2.sh new file mode 100755 index 0000000..87df546 --- /dev/null +++ b/.bin/bkup/start_services_2.sh @@ -0,0 +1,150 @@ +#!/bin/bash + + +# Print all environment variables +# echo "Environment variables:" +# printenv +# Ensure all required packages are installed +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log +npm install &> ./.tmp/npm_install_output.log + +# Start the Node.js server +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +rm -rf app/static &> ./.tmp/node_output.log & +npx tsc -w &> ./.tmp/node_output.log & +# npx ts-node app/templates/server/server.ts &> ./.tmp/node_output.log & + +# Start the Node.js server in the background and store its PID +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +rm -rf app/static &> ./.tmp/node_output.log & +npx tsc -w &> ./.tmp/node_output.log & +# npx ts-node app/templates/server/server.ts &> ./.tmp/node_output.log & + +# Start the Node.js server in the background and store its PID +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & + +# Node APP +node ./app/static/templates/server/server.js &> ./.tmp/node_output.log & +npm run build-css &> ./.tmp/node_output.log & +npx nodemon ./app/static/templates/sever/server.js &> ./.tmp/node_output.log & + +# Activate your virtual environment (if not already activated) +source ./.venv/bin/activate + +# Check if the virtual environment is correctly set up +echo "Checking virtual environment..." +python3 --version # Verify Python version +pip list | grep Flask # Verify Flask installation +npm --version # Verify Node.js installation +if [ $? -ne 0 ]; then + echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'" + deactivate + exit 1 +fi + +# Set the FLASK_APP environment variable to point to your app.py file and specify the port +export FLASK_APP=./app/run_app.py +export FLASK_RUN_PORT=${FLASK_RUN_PORT:-4000} # Specify the desired port here (default is 4000) + +# Start the Flask application in the background and store its PID +echo "Starting Flask server on port $FLASK_RUN_PORT..." +flask run &> ./.tmp/flask_output.log & +FLASK_PID=$! + +# Wait for 2 seconds to ensure the Flask server has started +sleep 2 + +# Check if the Flask process is running +if ps -p $FLASK_PID > /dev/null; then + echo "Flask server PID: $FLASK_PID" +else + echo "Failed to start Flask server." + cat ./.tmp/flask_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Tail the Flask output for real-time logs (optional, but useful) +echo "Flask server is running. Checking logs..." +tail -f ./.tmp/flask_output.log & + +# Run any additional Python scripts (e.g., Voice_v2.py) and capture their output +echo "Running additional services..." +python3.11 ./app/tools/Voice_v2.py &> ./.tmp/voice_output.log & + +# Function to shut down Node.js server using clear_ports.sh +shutdown_nodejs() { + echo "Shutting down servers..." + + # Read the .env file and extract ports based on environment variable names ending with 'PORT' + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + .bin/clear_ports.sh "$value" + fi + done < .env +} + +# Function to review all environment ports in use +review_ports() { + echo "Reviewing all environment ports in use..." + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + echo "Port in use: $key=$value" + fi + done < .env +} + +# Optionally, wait for a few more seconds before exiting +sleep 60 + +# Kill the Flask process if it's still running after `Voice_v2.py` finishes +if [ -n "$FLASK_PID" ]; then + echo "Waiting for Flask server to finish..." + sleep 10 # Give some time for cleanup + kill $FLASK_PID || true # Kill the process, ignore errors if it's already gone + echo "Killed Flask server with PID: $FLASK_PID" +fi + +# Call the shutdown_nodejs function to terminate Node.js server +shutdown_nodejs + +# Review all environment ports in use +review_ports + +echo "All services have been shut down." \ No newline at end of file diff --git a/.bin/bkup/stop_all_services.sh b/.bin/bkup/stop_all_services.sh new file mode 100755 index 0000000..33bd8d2 --- /dev/null +++ b/.bin/bkup/stop_all_services.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Function to stop Flask servers based on process name or port +stop_flask_servers() { + # List all Python processes that are running Flask apps + PIDS=$(pgrep -f "flask run") + + if [ -z "$PIDS" ]; then + echo "No Flask servers found." + return + fi + + for PID in $PIDS; do + echo "Stopping Flask server with PID: $PID" + kill $PID + done + + echo "All Flask servers have been stopped." +} + +# Function to stop Gunicorn processes +stop_gunicorn_servers() { + # List all Python processes that are running Gunicorn + PIDS=$(pgrep -f "gunicorn") + + if [ -z "$PIDS" ]; then + echo "No Gunicorn servers found." + return + fi + + for PID in $PIDS; do + echo "Stopping Gunicorn server with PID: $PID" + kill $PID + done + + echo "All Gunicorn servers have been stopped." +} + +# Stop both Flask and Gunicorn servers +stop_flask_servers +stop_gunicorn_servers \ No newline at end of file diff --git a/.bin/check_gunicorn.sh b/.bin/check_gunicorn.sh new file mode 100755 index 0000000..291c74f --- /dev/null +++ b/.bin/check_gunicorn.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Function to check and kill existing Gunicorn processes +function kill_gunicorn() { + if pgrep -f gunicorn > /dev/null; then + echo "Killing existing Gunicorn processes..." + pkill -f gunicorn + sleep 2 # Wait for the processes to terminate + fi +} + +# Source the virtual environment +source ./.venv/bin/activate + +# Kill existing Gunicorn processes if any +kill_gunicorn + +# Start Gunicorn with your configuration +nohup gunicorn 'app.run_app:app' --bind 0.0.0.0:8000 --daemon & +GUNICORN_PID=$! + +echo "Captured Gunicorn PID: $GUNICORN_PID" + +if [ -z "$GUNICORN_PID" ]; then + echo "Failed to capture the PID of Gunicorn server." + cat ./.tmp/gunicorn_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Check if the process is running +if ps -p "$GUNICORN_PID" > /dev/null; then + echo "Gunicorn server PID: $GUNICORN_PID" +else + echo "Failed to start Gunicorn server." + cat ./.tmp/gunicorn_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Deactivate the virtual environment when done +deactivate \ No newline at end of file diff --git a/.bin/clear_all_services.sh b/.bin/clear_all_services.sh new file mode 100755 index 0000000..93b7bac --- /dev/null +++ b/.bin/clear_all_services.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Determine the environment (e.g., from an env var) +ENVIRONMENT=${ENVIRONMENT:-development} + +# Source the appropriate .env file based on the environment +if [ "$ENVIRONMENT" == "development" ]; then + if [ -f .env ]; then + source .env + else + echo ".env file not found. Exiting." + exit 1 + fi +else + if [ -f .env.development ]; then + source .env.development + else + echo ".env.development file not found. Exiting." + exit 1 + fi +fi + +# Function to clear a single port +clear_port() { + local PORT=$1 + + # Validate that the PORT is a number + if [[ ! "$PORT" =~ ^[0-9]+$ ]]; then + echo "Invalid port value: $PORT. Skipping..." + return + fi + + # Find the process ID using lsof + PID=$(lsof -i :$PORT -t) + + if [ -z "$PID" ]; then + echo "No process found running on port $PORT." + else + echo "Killing process $PID running on port $PORT..." + kill -9 $PID + if [ $? -eq 0 ]; then + echo "Process $PID on port $PORT has been successfully terminated." + else + echo "Failed to terminate process $PID on port $PORT." + fi + fi +} + +# Extract ports from the .env file dynamically +echo "Scanning .env file for port variables..." +PORT_KEYS=(NODE_FRONTEND_PORT BACK_END_NODE_PORT BACK_END_NODE_PORT1 NODE_API_PORT GRAPHQL_PORT DB_PORT NODE_PORT FLASK_PORT FLASK_RUN_PORT) + +for KEY in "${PORT_KEYS[@]}"; do + PORT=$(grep -E "^${KEY}=" .env | cut -d '=' -f 2 | tr -d '"') + if [ -n "$PORT" ]; then + clear_port "$PORT" + fi +done + +echo "All specified ports have been checked and cleared." diff --git a/.bin/clear_ports.sh b/.bin/clear_ports.sh new file mode 100755 index 0000000..db71269 --- /dev/null +++ b/.bin/clear_ports.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +PORT=$1 # Port number passed as the first argument + +if [ -z "$PORT" ]; then + echo "No port number provided." + exit 1 +fi + +# Find the process ID using lsof +PID=$(lsof -i :$PORT -t) + +if [ -z "$PID" ]; then + echo "No process found running on port $PORT." +else + echo "Killing process $PID running on port $PORT..." + kill $PID + if [ $? -eq 0 ]; then + echo "Process $PID has been successfully terminated." + else + echo "Failed to terminate process $PID." + fi +fi + diff --git a/.bin/config.env b/.bin/config.env new file mode 100644 index 0000000..e5652be --- /dev/null +++ b/.bin/config.env @@ -0,0 +1,4 @@ +# Set the desired Python version +PYTHON_VERSION=python3.11 + +limit_request_line = 8192 diff --git a/.bin/setup_env.sh b/.bin/setup_env.sh new file mode 100755 index 0000000..8246274 --- /dev/null +++ b/.bin/setup_env.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +# Function to create and activate virtual environment +create_and_activate_venv() { + echo "Creating and activating virtual environment..." + + # Remove existing venv directory if exists + if [ -d ".venv" ]; then + rm -rf .venv + fi + + # Create a new virtual environment + python3.11 -m venv .venv + + # Activate the virtual environment + source ./.venv/bin/activate + + echo "Virtual environment activated." +} + +# Function to install dependencies +install_dependencies() { + echo "Installing dependencies..." + + # Install all required packages + pip install -r requirements.txt + + if [ $? -ne 0 ]; then + echo "One or more dependencies failed to install. Please check the requirements.txt file." + exit 1 + fi + + echo "Dependencies installed successfully." +} + +# Function to start Gunicorn with logs in the terminal +start_gunicorn_with_logs() { + echo "Starting Gunicorn server with gevent workers and logging..." + + # Create .tmp directory if it doesn't exist + mkdir -p .tmp + + # Start Gunicorn with logs + gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:8000 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 & + + echo "Gunicorn server started with gevent workers." +} + +# Function to show Gunicorn logs in the terminal +show_gunicorn_logs() { + tail -f .tmp/gunicorn_output.log +} + +# Main logic based on arguments +case "$1" in + setup) + create_and_activate_venv + install_dependencies + ;; + start) + source ./.venv/bin/activate + start_gunicorn_with_logs + ;; + logs) + show_gunicorn_logs + ;; + *) + echo "Usage: $0 [setup|start|logs]" + exit 1 +esac \ No newline at end of file diff --git a/.bin/show_gunicorn_logs.sh b/.bin/show_gunicorn_logs.sh new file mode 100755 index 0000000..badfff9 --- /dev/null +++ b/.bin/show_gunicorn_logs.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +# Ensure all required packages are installed +echo "Checking if required packages are installed..." + +# Install dependencies +pip install -r ./requirements.txt &> /dev/null +if [ $? -ne 0 ]; then + echo "One or more dependencies are missing. Please install them using 'pip install -r requirements.txt'" + pip install --upgrade pip + pip install -r requirements.txt + exit 1 +fi + +# Check if the virtual environment is activated +source config.env +if [ ! -d ".venv" ]; then + echo "Virtual environment not found. Creating it using 'python3 -m venv .venv'..." + python3 -m venv .venv +fi + +echo "Activating virtual environment..." +source ./.venv/bin/activate &> /dev/null +if [ $? -ne 0 ]; then + echo "Failed to activate virtual environment. Please ensure it is correctly set up." + exit 1 +fi + +# Check if gunicorn is installed +pip show gunicorn &> /dev/null +if [ $? -ne 0 ]; then + echo "gunicorn is not installed. Installing it..." + pip install gunicorn +fi + +# Function to start Gunicorn with logs in the terminal +start_gunicorn_with_logs() { + echo "Starting Gunicorn server with gevent workers..." + gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:8000 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 & + echo "Gunicorn server started." +} + +# Function to show Gunicorn logs in the terminal +show_gunicorn_logs() { + echo "Showing Gunicorn logs..." + tail -f .tmp/gunicorn_output.log +} + +# Main logic +if [ "$#" -eq 0 ]; then + start_gunicorn_with_logs +elif [ "$1" == "logs" ]; then + show_gunicorn_logs +else + echo "Usage: $0 [logs]" + exit 1 +fi + +# Deactivate the virtual environment +deactivate + +# --worker-class gevent: This tells Gunicorn to use the gevent worker class, +# which is more suitable for high-concurrency applications and +# can handle many requests using fewer resources. + +# --workers 3: Specifies the number of worker processes. You can adjust this based on your server's CPU cores +# and available memory. \ No newline at end of file diff --git a/.bin/start_gunicorn.sh b/.bin/start_gunicorn.sh new file mode 100755 index 0000000..897285b --- /dev/null +++ b/.bin/start_gunicorn.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +# Ensure the .tmp directory exists for logs +mkdir -p .tmp + +# Load environment variables +if [ -f .env ]; then + echo "Loading environment variables from .env..." + source .env +else + echo ".env file not found. Please provide one to configure the environment." + exit 1 +fi + +# Print all environment variables for debugging +echo "Environment variables:" +printenv + +# Verify required tools are installed +command -v pip >/dev/null 2>&1 || { echo >&2 "pip is not installed. Aborting."; exit 1; } +command -v npm >/dev/null 2>&1 || { echo >&2 "npm is not installed. Aborting."; exit 1; } +command -v gunicorn >/dev/null 2>&1 || { echo >&2 "gunicorn is not installed. Installing..."; pip install gunicorn; } + +# Install dependencies +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log || { echo "Python dependency installation failed. Check ./.tmp/install_output.log for details."; exit 1; } +npm install &> ./.tmp/npm_install_output.log || { echo "Node.js dependency installation failed. Check ./.tmp/npm_install_output.log for details."; exit 1; } + + +# Start Node.js server in the background +echo "Starting Node.js server..." +npx tsc -w &> ./.tmp/tsc_output.log & + + +node app/static/templates/server/server.js &> ./.tmp/node_output.log & +NODE_JS_PID=$! + +# Wait for the Node.js server to start +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server is running (PID: $NODE_JS_PID)" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Display the log contents for debugging + exit 1 +fi + +# Tail Node.js logs in the background (optional) +tail -f ./.tmp/node_output.log & + +# Activate the Python virtual environment +if [ ! -d ".venv" ]; then + echo "Virtual environment not found. Creating one..." + python3 -m venv .venv || { echo "Failed to create virtual environment. Aborting."; exit 1; } +fi + +echo "Activating virtual environment..." +source ./.venv/bin/activate || { echo "Failed to activate virtual environment. Aborting."; exit 1; } + +# Verify Flask installation +echo "Checking Flask installation..." +pip list | grep Flask >/dev/null || { echo "Flask is not installed. Please install it using 'pip install flask'."; deactivate; exit 1; } + +# Start Gunicorn server +PORT=${FLASK_PORT:-4000} +echo "Starting Gunicorn server on port $PORT..." +gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > ./.tmp/gunicorn_output.log 2>&1 & +GUNICORN_PID=$! + +# Check if Gunicorn is running +if ps -p $GUNICORN_PID > /dev/null; then + echo "Gunicorn server is running (PID: $GUNICORN_PID). Logs available in .tmp/gunicorn_output.log" +else + echo "Failed to start Gunicorn server." + cat ./.tmp/gunicorn_output.log # Display the log contents for debugging + deactivate + exit 1 +fi + +# Tail Gunicorn logs (optional) +tail -f ./.tmp/gunicorn_output.log & + +# Shutdown hook to clean up processes +trap 'echo "Stopping servers..."; kill $NODE_JS_PID; kill $GUNICORN_PID; deactivate; exit 0' SIGINT SIGTERM +wait diff --git a/.bin/start_services_2.sh b/.bin/start_services_2.sh new file mode 100755 index 0000000..df72e2c --- /dev/null +++ b/.bin/start_services_2.sh @@ -0,0 +1,127 @@ +#!/bin/bash + + +# Print all environment variables +echo "Environment variables:" +printenv +# Ensure all required packages are installed +echo "Installing missing dependencies..." +pip install -r ./requirements.txt &> ./.tmp/install_output.log +npm install &> ./.tmp/npm_install_output.log + +# Start the Node.js server +echo "Starting Node.js server..." +npm cache clean --force &> ./.tmp/node_output.log & +rm -rf app/server_files &> ./.tmp/node_output.log & +npm run build-css &> ./.tmp/node_output.log & +npx tsc -w &> ./.tmp/node_output.log & +# npx ts-node app/templates/server/server.ts &> ./.tmp/node_output.log & + +# Start the Node.js server in the background and store its PID +NODE_JS_PID=$! + +# Wait for 2 seconds to ensure the Node.js server has started +sleep 2 + +# Check if the Node.js process is running +if ps -p $NODE_JS_PID > /dev/null; then + echo "Node.js server PID: $NODE_JS_PID" +else + echo "Failed to start Node.js server." + cat ./.tmp/node_output.log # Print the log file contents in case of failure + exit 1 +fi + +# Tail the Node.js output for real-time logs (optional, but useful) +echo "Node.js server is running. Checking logs..." +tail -f ./.tmp/node_output.log & + +# Node APP +node ./app/static/templates/server/server.js &> ./.tmp/node_output.log & + +# npx nodemon ./app/server_files/templates/sever/server.js &> ./.tmp/node_output.log & + +# Activate your virtual environment (if not already activated) +source ./.venv/bin/activate + +# Check if the virtual environment is correctly set up +echo "Checking virtual environment..." +python3 --version # Verify Python version +pip list | grep Flask # Verify Flask installation +npm --version # Verify Node.js installation +if [ $? -ne 0 ]; then + echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'" + deactivate + exit 1 +fi + +# Set the FLASK_APP environment variable to point to your app.py file and specify the port +export FLASK_APP=./app/run_app.py +export FLASK_RUN_PORT=${FLASK_RUN_PORT:-4000} # Specify the desired port here (default is 4000) + +# Start the Flask application in the background and store its PID +echo "Starting Flask server on port $FLASK_RUN_PORT..." +flask run &> ./.tmp/flask_output.log & +FLASK_PID=$! + +# Wait for 2 seconds to ensure the Flask server has started +sleep 2 + +# Check if the Flask process is running +if ps -p $FLASK_PID > /dev/null; then + echo "Flask server PID: $FLASK_PID" +else + echo "Failed to start Flask server." + cat ./.tmp/flask_output.log # Print the log file contents in case of failure + deactivate + exit 1 +fi + +# Tail the Flask output for real-time logs (optional, but useful) +echo "Flask server is running. Checking logs..." +tail -f ./.tmp/flask_output.log & + +# Run any additional Python scripts (e.g., Voice_v2.py) and capture their output +echo "Running additional services..." +python3.11 ./app/tools/Voice_v2.py &> ./.tmp/voice_output.log & + +# Function to shut down Node.js server using clear_ports.sh +shutdown_nodejs() { + echo "Shutting down servers..." + + # Read the .env file and extract ports based on environment variable names ending with 'PORT' + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + .bin/clear_ports.sh "$value" + fi + done < .env +} + +# Function to review all environment ports in use +review_ports() { + echo "Reviewing all environment ports in use..." + while IFS='=' read -r key value; do + if [[ "$key" == *PORT ]]; then + echo "Port in use: $key=$value" + fi + done < .env +} + +# Optionally, wait for a few more seconds before exiting +sleep 60 + +# Kill the Flask process if it's still running after `Voice_v2.py` finishes +if [ -n "$FLASK_PID" ]; then + echo "Waiting for Flask server to finish..." + sleep 10 # Give some time for cleanup + kill $FLASK_PID || true # Kill the process, ignore errors if it's already gone + echo "Killed Flask server with PID: $FLASK_PID" +fi + +# Call the shutdown_nodejs function to terminate Node.js server +shutdown_nodejs + +# Review all environment ports in use +review_ports + +echo "All services have been shut down." \ No newline at end of file diff --git a/.bin/stop_all_services.sh b/.bin/stop_all_services.sh new file mode 100755 index 0000000..daafb85 --- /dev/null +++ b/.bin/stop_all_services.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +#!/bin/bash + +# Function to clear a single port +clear_port() { + local PORT=$1 + + # Ensure the PORT variable is expanded correctly + if [[ -z "$PORT" ]]; then + echo "No valid port provided." + return 1 + fi + + echo "Checking for process on port $PORT..." + + # Find the process ID using lsof + PID=$(lsof -i :$PORT -t) + + if [ -z "$PID" ]; then + echo "No process found running on port $PORT." + else + echo "Killing process $PID running on port $PORT..." + kill $PID + if [ $? -eq 0 ]; then + echo "Process $PID has been successfully terminated." + else + echo "Failed to terminate process $PID." + fi + fi +} + +# Read the .env file and extract ports +while IFS='=' read -r key value; do + # Check if the line is a valid environment variable + if [[ "$key" == PORT* || "$key" == *_PORT ]]; then + clear_port "$value" + fi +done < .env + +# Optionally, you can also clear specific ports mentioned in .env.example +while IFS='=' read -r key value; do + # Check if the line is a valid environment variable + if [[ "$key" == PORT* || "$key" == *_PORT ]]; then + clear_port "$value" + fi +done < .env.example + +# Function to stop Flask servers based on process name or port +stop_flask_servers() { + # List all Python processes that are running Flask apps + PIDS=$(pgrep -f "flask run") + + if [ -z "$PIDS" ]; then + echo "No Flask servers found." + return + fi + + for PID in $PIDS; do + echo "Stopping Flask server with PID: $PID" + kill $PID + done + + echo "All Flask servers have been stopped." +} + +# Function to stop Gunicorn processes +stop_gunicorn_servers() { + # List all Python processes that are running Gunicorn + PIDS=$(pgrep -f "gunicorn") + + if [ -z "$PIDS" ]; then + echo "No Gunicorn servers found." + return + fi + + for PID in $PIDS; do + echo "Stopping Gunicorn server with PID: $PID" + kill $PID + done + + echo "All Gunicorn servers have been stopped." +} + +# Stop both Flask and Gunicorn servers +stop_flask_servers +stop_gunicorn_servers \ No newline at end of file diff --git a/.bin/update_server.sh b/.bin/update_server.sh new file mode 100755 index 0000000..9633fa7 --- /dev/null +++ b/.bin/update_server.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Navigate to the root of the project +cd "$(dirname "$0")"/.. + +echo "Updating server..." + +# Check if the virtual environment is activated +if [ -n "$VIRTUAL_ENV" ]; then + echo "Deactivating virtual environment..." + deactivate +fi + +# Stop any running Gunicorn instances +echo "Stopping any running Gunicorn processes..." +pkill -f gunicorn &> /dev/null +if [ $? -eq 0 ]; then + echo "Gunicorn processes stopped." +else + echo "No running Gunicorn processes found." +fi + +# Activate the virtual environment +echo "Activating virtual environment..." +source ./.venv/bin/activate &> /dev/null +if [ $? -ne 0 ]; then + echo "Failed to activate virtual environment. Please ensure it is correctly set up." + exit 1 +fi + +# Read port from environment variable, default to 8000 if not set +PORT=${PORT:-8000} +echo "Starting Gunicorn server on port $PORT with gevent workers..." +nohup gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 & + +echo "Gunicorn server started on port $PORT." + +# Deactivate the virtual environment +deactivate + +echo "Server update complete." \ No newline at end of file diff --git a/.bin/zip_ignore.sh b/.bin/zip_ignore.sh new file mode 100755 index 0000000..f3ebea2 --- /dev/null +++ b/.bin/zip_ignore.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Directory to zip +SOURCE_DIR="./" + +# Output ZIP file +ZIP_FILE="librit_appFolder.zip" + +# Temporary list for unique untracked files +UNTRACKED_FILES=$(mktemp) +# Get the absolute path of SOURCE_DIR +ABS_SOURCE_DIR=$(realpath "$SOURCE_DIR") + +# Debug: Print source directory and temporary file paths +echo "Source Directory: $ABS_SOURCE_DIR" +echo "Untracked Files List: $UNTRACKED_FILES" + +# Function to check if a file/directory matches a gitignore pattern recursively +is_ignored() { + local path="$1" + for pattern in $(grep -v '^#' .gitignore | grep -v '^$'); do + # Convert pattern to regex and escape special characters + regex=$(echo "$pattern" | sed 's/[][\\^$.|?*+]/\\&/g') + if [[ "$path" =~ ^$regex ]]; then + echo "Matched ignored file: $ABS_SOURCE_DIR/$path" + return 0 + fi + done + return 1 +} + +# Get untracked and ignored files using git status --porcelain=v2 +while IFS= read -r line; do + # Parse the git status line + status="${line:0:2}" + path="${line:3}" + + if [[ "$status" == "?? " ]]; then + echo "$path" >> "$UNTRACKED_FILES" + fi +done <<< "$(git -C "$SOURCE_DIR" status --porcelain=v2)" + +# Sort the untracked files list to ensure uniqueness +sort -u "$UNTRACKED_FILES" -o "$UNTRACKED_FILES" + +# Initialize array for ignored files +IGNORED_FILES=() + +# Filter out ignored files from the untracked list and ensure uniqueness +while IFS= read -r file; do + # Debug: Print current file being processed + echo "Processing file: $file" + + if is_ignored "$file"; then + IGNORED_FILES+=("$ABS_SOURCE_DIR/$file") + echo "Added to ignored files list: @$ABS_SOURCE_DIR/$file" + else + echo "$file" >> "$UNTRACKED_FILES" + echo "Added to untracked files list: $file" + fi +done < "$UNTRACKED_FILES" + +# Create the ZIP archive excluding ignored files and untracked files +if [ ${#IGNORED_FILES[@]} -eq 0 ]; then + # If no ignored files, simply zip everything + echo "No ignored files found. Creating a full ZIP archive." + zip -r "$ZIP_FILE" "$SOURCE_DIR" +else + # Exclude ignored files from the ZIP archive + zip -r "$ZIP_FILE" "$SOURCE_DIR" "${IGNORED_FILES[@]/#/--exclude=}" +fi + +# Debug: Print contents of untracked files list and ignored files list +echo "Untracked Files List Contents:" +cat "$UNTRACKED_FILES" +echo "Ignored Files List Contents:" +for file in "${IGNORED_FILES[@]}"; do + echo "$file" +done +# Check if zip command was successful +if [ $? -eq 0 ]; then + echo "Zip archive created successfully." +else + echo "Error creating zip archive." +fi + +# Clean up temporary files +rm "$UNTRACKED_FILES" diff --git a/.dockerignore b/.dockerignore index fd00eaa..0893ca9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,34 +1,72 @@ -# Include any files or directories that you don't want to be copied to your -# container here (e.g., local build artifacts, temporary files, etc.). -# -# For more help, visit the .dockerignore file reference guide at -# https://docs.docker.com/go/build-context-dockerignore/ - -**/.classpath -**/.dockerignore -**/.env -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/.next -**/.cache -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/charts -**/docker-compose* -**/compose* -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -**/build -**/dist -LICENSE -README.md +# .dockerignore file for optimal Docker builds + +# Node.js dependencies +node_modules/ +npm-debug.log +yarn-debug.log + +# Python artifacts +__pycache__/ +*.pyc +*.pyo +.pytest_cache/ +.coverage + +# IDE and editor files +.idea/ +.vscode/ +*.swp +*.swo + +# Build outputs +dist/ +build/ +out/ + +# Test files +test/ +tests/ +*_test.go + +# Debug files +debug/ +*.log + +# Version control +.git/ +.gitignore + +# Environment and secrets +.env* +*.env +*.pem +*.key +*.crt + +# Documentation +docs/ +*.md +README* + +# Docker files +Dockerfile* +docker-compose* + +# Temporary files +tmp/ +temp/ +*.tmp + +# Local development +.local/ +local/ + +# Project-specific patterns +.DS_Store +.next/ +public/uploads/ +server/logs/ + +# Exclude Dockerfile and .dockerignore +!Dockerfile +!.dockerignore \ No newline at end of file diff --git a/.dockerignore.bak b/.dockerignore.bak new file mode 100644 index 0000000..fd00eaa --- /dev/null +++ b/.dockerignore.bak @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/.dockerignore.bak.bak b/.dockerignore.bak.bak new file mode 100644 index 0000000..fd00eaa --- /dev/null +++ b/.dockerignore.bak.bak @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..001237b --- /dev/null +++ b/.env.sample @@ -0,0 +1,5 @@ +# OrbisDB Configuration +ORBISDB_API_URL=https://rpc.ankr.com/eth_holesky/ +ORBISDB_API_KEY=https://rpc.ankr.com/multichain/ # or polygon-mainnet, etc. +ORBISDB_CHAIN_ID=17000 +ORBISDB_CONTRACT_ADDRESS=0xYourOrbisDBContractAddresc \ No newline at end of file diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..ea2d329 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + - run: npm test + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: https://npm.pkg.github.com/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.gitignore b/.gitignore index f11e600..8fd064b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,16 @@ orbisdb-settings.json server/plugins/evm-blockchain-listener/blocks-indexed.json .DS_Store +# Docker +# Ignore Docker-related files +# If you have a Dockerfile in the root of your project, uncomment the line below +Dockerfile +# Ignore Docker Compose files +docker-compose*.yml +# Ignore Docker Compose override files +docker-compose.override.yml +# Ignore Docker Compose environment files + # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -25,6 +35,8 @@ pids *.seed *.pid.lock +./.bin + # Directory for instrumented libs generated by jscoverage/JSCover lib-cov diff --git a/README.md b/README.md index a9be072..c16627b 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,411 @@ -# OrbisDB - +# Orbirsbd Middleware +The Orbisdb connects you to the Graphql system that mnages your Web3 data. -OrbisDB is a fully open-source relational database designed for onchain builders. Stored data inherits verifiable, permissionless and mutable properties of [Ceramic](https://www.ceramic.network), while providing a highly scalable way of querying data via SQL, GraphQL and a built-in Dashboard. -- [x] Hosted Postgres Database. [Docs](https://www.notion.so/Managed-Studio-be33efc2124e4f3583ab10a1639c45b1?pvs=21) -- [x] Authentication. [Docs](https://www.notion.so/Accounts-DIDs-b936223c995f432682bc4c648e52a892?pvs=21) -- [x] Crypto Plugins. [Docs](https://www.notion.so/Building-a-plugin-9255e4f7ca044f91831548a9179d6bcd?pvs=21) -- [x] Database functions - - [x] Insert. [Docs](https://www.notion.so/Writing-data-INSERT-8d1fae8016d94393ad439feeb3c9f7ff?pvs=21) - - [x] Select. [Docs](https://www.notion.so/869d600cf7d04ae58d0b1c4821b1d35e?pvs=21) -- [x] Dashboard. [Docs](https://www.notion.so/Data-f0f4cdef9f5e4fffb8c298e4b5176b72?pvs=21) -- [X] OrbisDB SDK [Github](https://github.com/OrbisWeb3/db-sdk) +### Base Command Explanation -> [!IMPORTANT] -> 🚨 Hosted service provided by Orbis, register for closed beta access to [OrbisDB Studio](https://app.formo.so/hJ5VGyugmGigyVFyqdHJa) +1. Set up Ceramic DB +```bash -> [!NOTE] -> ⚡️ Quickly start with a [Forum Template](https://github.com/mzkrasner/deforum-lite) +cd server +./wheel +``` + +This command executes the `wheel` script located in the current directory. `wheel` appears to be a tool or utility for setting up and managing a Ceramic-based application. + +### Configuration Prompt + +The script prompts the user to confirm the initial configuration settings. Here's a breakdown of what happens: + +1. **Project Name**: The user is asked if they want to keep or change the project name. The default project name is "ceramic-app". +2. **Project Directory**: The user is asked if the project directory already exists and, if not, if they want to create it. +3. **Network**: The user is asked if they want to use the `InMemory` network for testing purposes. +4. **Ceramic Included**: The script checks if Ceramic should be included in the setup. +5. **ComposeDB Included**: The script checks if ComposeDB should be included. +6. **ComposeDB Sample Application Included**: The script checks if a sample ComposeDB application should be included. +7. **DID Generated Secret Key Path**: The user is asked to provide the path where the DID secret key will be saved. +8. **Confirmation**: The user confirms whether they want to keep or change the configuration. + +### Database Verification + +The script then verifies the connection to the SQLite database using the provided connection string: + +```bash +Verifying database connection using connection string sqlite:///Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/server/ceramic-app/ceramic-indexing/ceramic.db +``` + +This ensures that the database is accessible and properly configured. + +### Writing Configuration Files + +The script writes configuration files to the project directory: + +```bash +Saving config to /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/server/ceramic-app/ceramic.json +Saving daemon file to /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/server/ceramic-app/daemon_config.json +``` + +These files contain the necessary configuration settings for the Ceramic and ComposeDB setup. + +### Installing Dependencies + +The script installs dependencies using npm: + +```bash ++ Installing dependencies for @ceramicnetwork/cli +When you would like to run ceramic please run +./ceramic daemon --config /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/server/ceramic-app/daemon_config.json +from the directory /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/server/ceramic-app. For more information on the Ceramic http api see https://developers.ceramic.network/build/http/api/ +``` + +This command installs the necessary dependencies for the `@ceramicnetwork/cli` package. + +### Summary of the Process + +- **User Interaction**: The user is prompted to confirm or change various configuration settings. +- **Database Verification**: The script checks the SQLite database connection. +- **Configuration Writing**: Configuration files are written to the project directory. +- **Dependency Installation**: Dependencies are installed using npm. +- **Ceramic Setup**: The script sets up a Ceramic network and initializes the ComposeDB application. + +This process ensures that the Ceramic setup is correctly configured for your Ceramic-based application. +## Prerequisites + +Ensure you have the following installed: + +- Docker version 20.10 or later +- Docker Compose version 1.29 or later +- Node.js version 18.0.0 or later + +## Environment Variables + +Set the following environment variables in a `.env` file or export them in your shell: + +- `POSTGRES_USER`: Database username (default: `user`) +- `POSTGRES_PASSWORD`: Database password (default: `password`) + +## Build and Run Instructions + +1. Clone the repository and navigate to the project directory. + + ```bash + git clone https://github.com/your-repo/project.git + cd project + ``` + +2. Build and start the services using Docker Compose: - + ```bash + cd docker/core/ + docker build -f ../../docker/core/Dockerfile ../.. + ``` -## Documentation & Community -- Full [Documentation](https://www.notion.so/OrbisDB-Docs-e77a592361b74e66a45404ca1cbc517b?pvs=21) -- [YouTube](https://www.youtube.com/@orbisdb) channel with step-by-step videos -- [Discord](https://discord.gg/jmnzGYfhHt) to ask all your technical questions -- [Twitter](https://x.com/useOrbis) to get latest updates on OrbisDB - +3. Access the application at `http://localhost:7008`. -## How it works -OrbisDB is a relational database built on top of [Ceramic Network](https://www.ceramic.network), a verifiable and decentralized event store. Data inherits transparency, user ownership and permissionless capabilities while ensuring high throughput and low costs. OrbisDB leverages PostgreSQL for querying, offering a robust and scalable indexing solution. Finally, the OrbisDB software orchestrates data storage, management, and access, providing a robust and scalable database solution. +## Ceramatic (MacOS) -## Plugins -OrbisDB Plugins allow users to customize and enrich the behavior of their instance. -- `generate` to **Create streams**: Automatically create new streams based on external data sources (ie. blockchain event, a local CSV file or an API data source). -- `add_metadata` to **Add metadata**: Modifies or enhances the stream content before indexing (ie. classify the content using AI, fetch the ENS name of the stream’s controller) -- `validate` to **Validate / Gate:** Checks the stream details and decides whether it should be indexed or not (for moderation, token gating or sybil resistance) -- `post_process` to **Perform an action**: Performs actions **after** a stream has been indexed (ie. send an email or a push notification, trigger a blockchain transaction...). +```bash +brew install ceramicnetwork/tap/ceramic-one +ceramic-one daemon --network in-memory -You can find multiple examples of plugins in the `server/plugins` directory. +``` + +## Exposed Ports + +- `app`: 7008 +- `db`: Not exposed externally + +## Notes + +- Ensure the `Dockerfile` and `docker-compose.yml` are correctly configured for your environment. +- For additional configuration, refer to the [documentation](#documentation-community). + +## Starting the Server + +To start the server, navigate to the project directory and run the following command: + +```bash +cd docker/core/ +docker-compose up -d +``` + +This will start the necessary services in detached mode. + +### Expected Output + +When you start the server, you should see output similar to this: + +```bash +[INFO] Starting ceramic-one daemon... +[INFO] Ceramic Node started: /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/ceramic/node-12700 +[INFO] Listening for incoming connections on port 3001... +``` + +You can access the application at `http://localhost:7008` in your web browser. + +### Connecting to Ceramic - +Once the server is running, you can connect to Ceramic using the following command: -## Setting up -As is the case with other web services, OrbisDB can be hosted locally, in the cloud or via a managed hosting provider. This is true for each separate component, as they don’t have to be hosted on a single server. +```bash +cd docker/core/ +docker-compose exec -it ceramic-one /bin/bash +``` + +This will start a shell session inside the Ceramic node container. You can then interact with Ceramic using the provided commands. + +### Additional Information about Connecting the Ceramic + +To connect the Ceramic network, follow these steps: + +1. **Install `ceramic-cli`**: + Install the `ceramic-cli` tool by following the [installation instructions](https://github.com/ceramicnetwork/cli). + +2. **Get a Ceramic ID**: + Use the `ceramic-cli` to generate a new Ceramic ID. For example: + + ```bash + ceramic id + ``` + +3. **Initialize OrbisDB**: + Initialize OrbisDB by providing the Ceramic ID and any other necessary configuration. -### 🌟 Recommended - Managed + Studio + ```bash + pnpm run init --ceramic-id + ``` -> [!IMPORTANT] -> 🚨 Register here to get early access of [OrbisDB Studio](https://app.formo.so/hJ5VGyugmGigyVFyqdHJa), a hosted service provided by Orbis. +4. **Start the Application**: + Once OrbisDB is initialized, start your application as described in the previous steps. -Orbis offers a free [shared OrbisDB instance](https://www.notion.so/Overview-fbc65a9a0356485a993b0cab190779f3?pvs=21) managed by Orbis. This means you don’t have to worry about any of the backend requirements - just set up your environment via our UI and get started with decentralized data. +By following these steps, you should be able to start the server and connect to Ceramic successfully. -With a shared instance, each developer gets their own isolated database and environment - however, the underlying hardware is shared. Once your application starts scaling you should consider a dedicated instance. +### Running the Project with Docker -You also have other partners who can enable managed services for you like hirenodes.io +This project is a web application that provides users with a platform to create and manage digital identities. It utilizes the Ceramic protocol to enable decentralized identity management, allowing users to have full control over their data. -### Local +## Prerequisites -If you want to run OrbisDB Locally, you are able to easily do it by following this guide [here](https://www.notion.so/Local-d3e9dd97e97b4c00a530b6ada20a8536?pvs=21) and our latest YouTube video [here](https://www.youtube.com/watch?v=8embizFvI-U). +Ensure you have the following installed: -This means all OrbisDB nodes will be hosted locally, including PostgreSQL, Ceramic and OrbisDB Node itself. +- Docker version 20.10 or later +- Docker Compose version 1.29 or later +- Node.js version 18.0.0 or later -### Self-hosted +## Environment Variables -Self-hosting OrbisDB allows for full control over each component. +Set the following environment variables in a `.env` file or export them in your shell: -Each component can be isolated on a separate server or hosted on a single instance. +- `POSTGRES_USER`: Database username (default: `user`) +- `POSTGRES_PASSWORD`: Database password (default: `password`) -Check out our self-hosting guide [here](https://www.notion.so/Self-hosted-603eb88f811f4bd596c2af38d187ac81?pvs=21). +## Build and Run Instructions -### Hybrid +1. Clone the repository and navigate to the project directory. -Because each OrbisDB component can be hosted separately, this allows for a hybrid hosting environment. You can choose to run the OrbisDB node yourself, but delegate database and Ceramic hosting to a managed provider. + ```bash + git clone https://github.com/your-repo/project.git + cd project + ``` -Configure your setup to your needs to strike your own balance of control and convenience. +2. Build and start the services using Docker Compose: -For more details, you can visit the [full documentation](https://www.notion.so/Architecture-4b4ca402cb1a44e58b9a2884bdc02f04?pvs=21). + ```bash + cd docker/core/ + docker build -f ../../docker/core/Dockerfile ../.. + ``` -## Running this repository -To get started with OrbisDB locally, we recommend downloading this repository locally and running it as a simple NodeJS program. +3. Access the application at `http://localhost:7008`. -Full guide [here](https://www.notion.so/Local-d3e9dd97e97b4c00a530b6ada20a8536?pvs=21). +## Ceramatic (MacOS) + +```bash +brew install ceramicnetwork/tap/ceramic-one +ceramic-one daemon --network in-memory ``` -npm install -npm run dev +## Exposed Ports + +- `app`: 7008 +- `db`: Not exposed externally + +## Notes + +- Ensure the `Dockerfile` and `docker-compose.yml` are correctly configured for your environment. +- For additional configuration, refer to the [documentation](#documentation-community). +## Starting the Server + +To start the server, navigate to the project directory and run the following command: + +```bash +cd docker/core/ +docker-compose up -d ``` -Your OrbisDB instance will then be running on port `7008`, allowing you to access it through your browser by navigating to `http://localhost:7008/`. If this is your first time using it, you will be prompted to enter the details of your Ceramic node as well as your database credentials, which are necessary for indexing. +This will start the necessary services in detached mode. + +### Expected Output + +When you start the server, you should see output similar to this: + +```bash +[INFO] Starting ceramic-one daemon... +[INFO] Ceramic Node started: /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/ceramic/node-12700 +[INFO] Listening for incoming connections on port 3001... +``` + +You can access the application at `http://localhost:7008` in your web browser. + +### Connecting to Ceramic + +Once the server is running, you can connect to Ceramic using the following command: + +```bash +cd docker/core/ +docker-compose exec -it ceramic-one /bin/bash +``` + +This will start a shell session inside the Ceramic node container. You can then interact with Ceramic using the provided commands. + +### Additional Information about Connecting the Ceramic + +To connect the Ceramic network, follow these steps: + +1. **Install `ceramic-cli`**: + Install the `ceramic-cli` tool by following the [installation instructions](https://github.com/ceramicnetwork/cli). + +2. **Get a Ceramic ID**: + Use the `ceramic-cli` to generate a new Ceramic ID. For example: + + ```bash + ceramic id + ``` + +3. **Initialize OrbisDB**: + Initialize OrbisDB by providing the Ceramic ID and any other necessary configuration. + + ```bash + pnpm run init --ceramic-id + ``` + +4. **Start the Application**: + Once OrbisDB is initialized, start your application as described in the previous steps. + +By following these steps, you should be able to start the server and connect to Ceramic successfully. + +### Running the Project with Docker + +This project is a web application that provides users with a platform to create and manage digital identities. It utilizes the Ceramic protocol to enable decentralized identity management, allowing users to have full control over their data. + +## Prerequisites + +Ensure you have the following installed: + +- Docker version 20.10 or later +- Docker Compose version 1.29 or later +- Node.js version 18.0.0 or later + +## Environment Variables + +Set the following environment variables in a `.env` file or export them in your shell: + +- `POSTGRES_USER`: Database username (default: `user`) +- `POSTGRES_PASSWORD`: Database password (default: `password`) + +## Build and Run Instructions + +1. Clone the repository and navigate to the project directory. + + ```bash + git clone https://github.com/your-repo/project.git + cd project + ``` + +2. Build and start the services using Docker Compose: + + ```bash + cd docker/core/ + docker build -f ../../docker/core/Dockerfile ../.. + ``` + +3. Access the application at `http://localhost:7008`. + +## Ceramatic (MacOS) + +```bash +brew install ceramicnetwork/tap/ceramic-one +ceramic-one daemon --network in-memory + +``` + +## Exposed Ports + +- `app`: 7008 +- `db`: Not exposed externally + +## Notes + +- Ensure the `Dockerfile` and `docker-compose.yml` are correctly configured for your environment. +- For additional configuration, refer to the [documentation](#documentation-community). + +## Starting the Server + +To start the server, navigate to the project directory and run the following command: + +```bash +cd docker/core/ +docker-compose up -d +``` + +This will start the necessary services in detached mode. + +### Expected Output + +When you start the server, you should see output similar to this: + +```bash +[INFO] Starting ceramic-one daemon... +[INFO] Ceramic Node started: /Users/jeldonmusic/Documents/matrixblend_com/Datbase/orbisdb/ceramic/node-12700 +[INFO] Listening for incoming connections on port 3001... +``` + +You can access the application at `http://localhost:7008` in your web browser. + +### Connecting to Ceramic + +Once the server is running, you can connect to Ceramic using the following command: + +```bash +cd docker/core/ +docker-compose exec -it ceramic-one /bin/bash +``` + +This will start a shell session inside the Ceramic node container. You can then interact with Ceramic using the provided commands. + +### Additional Information about Connecting the Ceramic + +To connect the Ceramic network, follow these steps: + +1. **Install `ceramic-cli`**: + Install the `ceramic-cli` tool by following the [installation instructions](https://github.com/ceramicnetwork/cli). + +2. **Get a Ceramic ID**: + Use the `ceramic-cli` to generate a new Ceramic ID. For example: + + ```bash + ceramic id + ``` + +3. **Initialize OrbisDB**: + Initialize OrbisDB by providing the Ceramic ID and any other necessary configuration. + + ```bash + pnpm run init --ceramic-id + ``` + +4. **Start the Application**: + Once OrbisDB is initialized, start your application as described in the previous steps. + +By following these steps, you should be able to start the server and connect to Ceramic successfully. \ No newline at end of file diff --git a/README.md.bak b/README.md.bak new file mode 100644 index 0000000..a9be072 --- /dev/null +++ b/README.md.bak @@ -0,0 +1,92 @@ +# OrbisDB + + +OrbisDB is a fully open-source relational database designed for onchain builders. Stored data inherits verifiable, permissionless and mutable properties of [Ceramic](https://www.ceramic.network), while providing a highly scalable way of querying data via SQL, GraphQL and a built-in Dashboard. + +- [x] Hosted Postgres Database. [Docs](https://www.notion.so/Managed-Studio-be33efc2124e4f3583ab10a1639c45b1?pvs=21) +- [x] Authentication. [Docs](https://www.notion.so/Accounts-DIDs-b936223c995f432682bc4c648e52a892?pvs=21) +- [x] Crypto Plugins. [Docs](https://www.notion.so/Building-a-plugin-9255e4f7ca044f91831548a9179d6bcd?pvs=21) +- [x] Database functions + - [x] Insert. [Docs](https://www.notion.so/Writing-data-INSERT-8d1fae8016d94393ad439feeb3c9f7ff?pvs=21) + - [x] Select. [Docs](https://www.notion.so/869d600cf7d04ae58d0b1c4821b1d35e?pvs=21) +- [x] Dashboard. [Docs](https://www.notion.so/Data-f0f4cdef9f5e4fffb8c298e4b5176b72?pvs=21) +- [X] OrbisDB SDK [Github](https://github.com/OrbisWeb3/db-sdk) + +> [!IMPORTANT] +> 🚨 Hosted service provided by Orbis, register for closed beta access to [OrbisDB Studio](https://app.formo.so/hJ5VGyugmGigyVFyqdHJa) + +> [!NOTE] +> ⚡️ Quickly start with a [Forum Template](https://github.com/mzkrasner/deforum-lite) + + + +## Documentation & Community +- Full [Documentation](https://www.notion.so/OrbisDB-Docs-e77a592361b74e66a45404ca1cbc517b?pvs=21) +- [YouTube](https://www.youtube.com/@orbisdb) channel with step-by-step videos +- [Discord](https://discord.gg/jmnzGYfhHt) to ask all your technical questions +- [Twitter](https://x.com/useOrbis) to get latest updates on OrbisDB + + +## How it works +OrbisDB is a relational database built on top of [Ceramic Network](https://www.ceramic.network), a verifiable and decentralized event store. Data inherits transparency, user ownership and permissionless capabilities while ensuring high throughput and low costs. OrbisDB leverages PostgreSQL for querying, offering a robust and scalable indexing solution. Finally, the OrbisDB software orchestrates data storage, management, and access, providing a robust and scalable database solution. + +## Plugins +OrbisDB Plugins allow users to customize and enrich the behavior of their instance. +- `generate` to **Create streams**: Automatically create new streams based on external data sources (ie. blockchain event, a local CSV file or an API data source). +- `add_metadata` to **Add metadata**: Modifies or enhances the stream content before indexing (ie. classify the content using AI, fetch the ENS name of the stream’s controller) +- `validate` to **Validate / Gate:** Checks the stream details and decides whether it should be indexed or not (for moderation, token gating or sybil resistance) +- `post_process` to **Perform an action**: Performs actions **after** a stream has been indexed (ie. send an email or a push notification, trigger a blockchain transaction...). + +You can find multiple examples of plugins in the `server/plugins` directory. + + + +## Setting up +As is the case with other web services, OrbisDB can be hosted locally, in the cloud or via a managed hosting provider. This is true for each separate component, as they don’t have to be hosted on a single server. + +### 🌟 Recommended - Managed + Studio + +> [!IMPORTANT] +> 🚨 Register here to get early access of [OrbisDB Studio](https://app.formo.so/hJ5VGyugmGigyVFyqdHJa), a hosted service provided by Orbis. + +Orbis offers a free [shared OrbisDB instance](https://www.notion.so/Overview-fbc65a9a0356485a993b0cab190779f3?pvs=21) managed by Orbis. This means you don’t have to worry about any of the backend requirements - just set up your environment via our UI and get started with decentralized data. + +With a shared instance, each developer gets their own isolated database and environment - however, the underlying hardware is shared. Once your application starts scaling you should consider a dedicated instance. + +You also have other partners who can enable managed services for you like hirenodes.io + +### Local + +If you want to run OrbisDB Locally, you are able to easily do it by following this guide [here](https://www.notion.so/Local-d3e9dd97e97b4c00a530b6ada20a8536?pvs=21) and our latest YouTube video [here](https://www.youtube.com/watch?v=8embizFvI-U). + +This means all OrbisDB nodes will be hosted locally, including PostgreSQL, Ceramic and OrbisDB Node itself. + +### Self-hosted + +Self-hosting OrbisDB allows for full control over each component. + +Each component can be isolated on a separate server or hosted on a single instance. + +Check out our self-hosting guide [here](https://www.notion.so/Self-hosted-603eb88f811f4bd596c2af38d187ac81?pvs=21). + +### Hybrid + +Because each OrbisDB component can be hosted separately, this allows for a hybrid hosting environment. You can choose to run the OrbisDB node yourself, but delegate database and Ceramic hosting to a managed provider. + +Configure your setup to your needs to strike your own balance of control and convenience. + +For more details, you can visit the [full documentation](https://www.notion.so/Architecture-4b4ca402cb1a44e58b9a2884bdc02f04?pvs=21). + +## Running this repository +To get started with OrbisDB locally, we recommend downloading this repository locally and running it as a simple NodeJS program. + +Full guide [here](https://www.notion.so/Local-d3e9dd97e97b4c00a530b6ada20a8536?pvs=21). + +``` +npm install + +npm run dev + +``` + +Your OrbisDB instance will then be running on port `7008`, allowing you to access it through your browser by navigating to `http://localhost:7008/`. If this is your first time using it, you will be prompted to enter the details of your Ceramic node as well as your database credentials, which are necessary for indexing. diff --git a/client/components/ConfigurationPreset.js b/client/components/ConfigurationPreset.js index b28fe3c..2a34194 100644 --- a/client/components/ConfigurationPreset.js +++ b/client/components/ConfigurationPreset.js @@ -1,44 +1,64 @@ import Button from "./Button"; import { GovernanceIcon, SocialIcon } from "./Icons"; -const ConfigurationPreset = ({presets, setPresets, status, save}) => { +const ConfigurationPreset = ({ presets, setPresets, status, save }) => { + /** Will enable or disable a prest on click */ + function enablePreset(type, enabled) { + if (enabled) { + // Add the new type if it's not already in the array to avoid duplicates + setPresets((prevPresets) => { + return prevPresets.includes(type) + ? prevPresets + : [...prevPresets, type]; + }); + } else { + // Delete preset "type" from presets array + setPresets((prevPresets) => { + return prevPresets.filter((p) => p !== type); + }); + } + } - /** Will enable or disable a prest on click */ - function enablePreset(type, enabled) { - if (enabled) { - // Add the new type if it's not already in the array to avoid duplicates - setPresets(prevPresets => { - return prevPresets.includes(type) ? prevPresets : [...prevPresets, type]; - }); - } else { - // Delete preset "type" from presets array - setPresets(prevPresets => { - return prevPresets.filter(p => p !== type); - }); - } - } - - return( - <> -
- -

Click on the presets you want to use in order to configure your instance to cover specific use cases immediately.

-
- {/** Social preset */} -
enablePreset("social", !presets.includes("social"))}>Social
- {/** Governance preset */} -
enablePreset("governance", !presets.includes("governance"))}>Governance
+ return ( + <> +
+ +

+ Click on the presets you want to use in order to configure your + instance to cover specific use cases immediately. +

+
+ {/** Social preset */} +
enablePreset("social", !presets.includes("social"))} + > + + Social +
+ {/** Governance preset */} +
+ enablePreset("governance", !presets.includes("governance")) + } + > + + Governance
- - {/** Go to next step */} - {save && -
-
- } - - ) -} +
+ + {/** Go to next step */} + {save && ( +
+
+ )} + + ); +}; -export default ConfigurationPreset; \ No newline at end of file +export default ConfigurationPreset; diff --git a/client/components/ConfigurationSettings.js b/client/components/ConfigurationSettings.js index 35a4ea8..7744d1a 100644 --- a/client/components/ConfigurationSettings.js +++ b/client/components/ConfigurationSettings.js @@ -8,14 +8,12 @@ import { OrbisDB } from "@useorbis/db-sdk"; import { OrbisEVMAuth } from "@useorbis/db-sdk/auth"; import ConfigurationPreset from "./ConfigurationPreset"; -export default function ConfigurationSettings({showPresets}) { - return( - - ) +export default function ConfigurationSettings({ showPresets }) { + return ; } -export function ConfigurationSetup({showPresets}) { - const { +export function ConfigurationSetup({ showPresets }) { + const { settings, globalSettings, setSettings, @@ -24,7 +22,7 @@ export function ConfigurationSetup({showPresets}) { setIsAdmin, setIsConfigured, adminSession, - setIsConnected + setIsConnected, } = useGlobal(); const [status, setStatus] = useState(STATUS.ACTIVE); const [statusConnect, setStatusConnect] = useState(STATUS.ACTIVE); @@ -108,12 +106,19 @@ export function ConfigurationSetup({showPresets}) { } async function goStep3() { - if((!dbDatabase || dbDatabase == "") || (!dbUser || dbUser == "") || (!dbPassword || dbPassword == "")) { + if ( + !dbDatabase || + dbDatabase == "" || + !dbUser || + dbUser == "" || + !dbPassword || + dbPassword == "" + ) { alert("The database credentials are required."); return; } setStatus(STATUS.ACTIVE); - if(showPresets) { + if (showPresets) { setStep(3); } else { setStep(4); @@ -152,18 +157,21 @@ export function ConfigurationSetup({showPresets}) { database: dbDatabase, password: dbPassword, host: dbHost, - port: parseInt(dbPort) - } + port: parseInt(dbPort), + }, }, - presets: presets - }) + presets: presets, + }), }); const response = await rawResponse.json(); console.log("Configuration saved:", response); - if(response.result) { - console.log("Success updating configutation with:", response.updatedSettings); + if (response.result) { + console.log( + "Success updating configutation with:", + response.updatedSettings + ); setStatus(STATUS.SUCCESS); setSettings(response.updatedSettings); setIsConfigured(true); @@ -208,128 +216,206 @@ export function ConfigurationSetup({showPresets}) { const auth = new OrbisEVMAuth(window.ethereum); try { - const result = await adminOrbisDB.connectUser({ auth, saveSession: false }); - localStorage.setItem("orbisdb-admin-session", result.auth.serializedSession); + const result = await adminOrbisDB.connectUser({ + auth, + saveSession: false, + }); + localStorage.setItem( + "orbisdb-admin-session", + result.auth.serializedSession + ); if (result?.user) { setAdminAccount(result.user.did); setIsAdmin(true); setSessionJwt(result.auth.serializedSession); } setStatusConnect(STATUS.SUCCESS); - } catch(e) { + } catch (e) { console.log("Error while connecting:", e); setStatusConnect(STATUS.ACTIVE); } - } return ( <> - {/** Stepper to show progress */} - {showPresets ? - - : - - } - - - {/** Step 1: Ceramic node */} - {step == 1 && - <> -
- - setCeramicNode(e.target.value)} value={ceramicNode} /> - {hasLocalNode && -

We found a local Ceramic node on this server.

- } -
+ {/** Stepper to show progress */} + {showPresets ? ( + + ) : ( + + )} -
- -

- This seed will be used to create streams from the OrbisDB UI as - well as by plugins creating streams. You can also{" "} - generateSeed()} - > - generate a new one - - . Make sure to back it up somewhere. + {/** Step 1: Ceramic node */} + {step == 1 && ( + <> +

+ + setCeramicNode(e.target.value)} + value={ceramicNode} + /> + {hasLocalNode && ( +

+ {" "} + We found a local Ceramic node on this server.

-