Add dark mode UI and update components
This commit is contained in:
parent
f2817bc1f1
commit
c263092c10
9 changed files with 488 additions and 87 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from flask import Flask, request, jsonify, send_from_directory
|
||||
from flask import Flask, request, jsonify, send_from_directory, Blueprint
|
||||
from .cvs_client import CVSClient
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -17,6 +17,9 @@ app = Flask(__name__, static_folder=ui_dir, static_url_path='')
|
|||
cvs_client = None
|
||||
app_config = {}
|
||||
|
||||
# Create API Blueprint (will be registered with basepath as url_prefix)
|
||||
api_bp = Blueprint('api', __name__)
|
||||
|
||||
# Initialize CVS Client using provided parameters
|
||||
def create_cvs_client(cvs_url, repos_checkout=None, cvs_module=None):
|
||||
"""
|
||||
|
|
@ -37,7 +40,17 @@ def create_cvs_client(cvs_url, repos_checkout=None, cvs_module=None):
|
|||
|
||||
return CVSClient(cvs_url, repos_checkout=repos_checkout, cvs_module=cvs_module)
|
||||
|
||||
@app.route('/v1/tree', methods=['GET'])
|
||||
@api_bp.route('/ui/config.js', methods=['GET'])
|
||||
def serve_config():
|
||||
"""
|
||||
Serve dynamic configuration as JavaScript
|
||||
This allows the frontend to access the basepath configuration
|
||||
"""
|
||||
basepath = app_config.get('basepath', '')
|
||||
config_js = f"window.APP_CONFIG = {{ basepath: '{basepath}' }};"
|
||||
return config_js, 200, {'Content-Type': 'application/javascript'}
|
||||
|
||||
@api_bp.route('/api/v1/tree', methods=['GET'])
|
||||
def get_repository_tree():
|
||||
"""
|
||||
Get repository tree structure
|
||||
|
|
@ -53,7 +66,7 @@ def get_repository_tree():
|
|||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/v1/diff', methods=['GET'])
|
||||
@api_bp.route('/api/v1/diff', methods=['GET'])
|
||||
def get_file_diff():
|
||||
"""
|
||||
Get diff between two revisions of a file
|
||||
|
|
@ -75,7 +88,7 @@ def get_file_diff():
|
|||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/v1/history', methods=['GET'])
|
||||
@api_bp.route('/api/v1/history', methods=['GET'])
|
||||
def get_file_history():
|
||||
"""
|
||||
Get revision history for a file
|
||||
|
|
@ -95,7 +108,7 @@ def get_file_history():
|
|||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/v1/file', methods=['GET'])
|
||||
@api_bp.route('/api/v1/file', methods=['GET'])
|
||||
def get_file_content():
|
||||
"""
|
||||
Get raw file content at a specific revision
|
||||
|
|
@ -117,7 +130,7 @@ def get_file_content():
|
|||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/v1/health', methods=['GET'])
|
||||
@api_bp.route('/api/v1/health', methods=['GET'])
|
||||
def health_check():
|
||||
"""
|
||||
Simple health check endpoint
|
||||
|
|
@ -127,14 +140,14 @@ def health_check():
|
|||
"cvs_client": "initialized" if cvs_client else "not initialized"
|
||||
})
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
@api_bp.route('/ui/', methods=['GET'])
|
||||
def index():
|
||||
"""
|
||||
Serve the UI index.html
|
||||
"""
|
||||
return send_from_directory(ui_dir, 'index.html')
|
||||
|
||||
@app.route('/<path:filename>', methods=['GET'])
|
||||
@api_bp.route('/ui/<path:filename>', methods=['GET'])
|
||||
def serve_static(filename):
|
||||
"""
|
||||
Serve static files (CSS, JS, etc.)
|
||||
|
|
@ -180,6 +193,11 @@ def main():
|
|||
default=5000,
|
||||
help='Flask port to bind to (default: 5000)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--basepath',
|
||||
default='',
|
||||
help='Base path for API requests (e.g., /api/cvs) (default: empty string for root)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--debug',
|
||||
action='store_true',
|
||||
|
|
@ -195,9 +213,14 @@ def main():
|
|||
'cvs_module': args.cvs_module,
|
||||
'host': args.host,
|
||||
'port': args.port,
|
||||
'basepath': args.basepath,
|
||||
'debug': args.debug
|
||||
}
|
||||
|
||||
# Register the API Blueprint with basepath as url_prefix
|
||||
basepath = args.basepath if args.basepath else ''
|
||||
app.register_blueprint(api_bp, url_prefix=basepath)
|
||||
|
||||
# Attempt to create CVS client at startup
|
||||
try:
|
||||
cvs_client = create_cvs_client(
|
||||
|
|
@ -209,7 +232,7 @@ def main():
|
|||
print(f"Error initializing CVS Client: {e}", file=sys.stderr)
|
||||
cvs_client = None
|
||||
|
||||
print(f"Starting CVS Proxy on {args.host}:{args.port}")
|
||||
print(f"Starting CVS Proxy on {args.host}:{args.port} with basepath: '{basepath}'")
|
||||
app.run(host=args.host, port=args.port, debug=args.debug)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue