2023-12-28 06:33:55 +00:00
|
|
|
from flask import Flask, request, send_from_directory
|
2023-12-28 03:11:21 +00:00
|
|
|
import os
|
|
|
|
|
2023-12-28 06:33:55 +00:00
|
|
|
# Initialize Flask app
|
|
|
|
app = Flask(__name__)
|
2023-12-28 03:11:21 +00:00
|
|
|
|
2023-12-28 06:33:55 +00:00
|
|
|
# Directory containing EPUB files
|
2024-01-22 19:00:46 +00:00
|
|
|
RESUME_DIR = './resumes/'
|
2023-12-28 03:11:21 +00:00
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2023-12-28 06:33:55 +00:00
|
|
|
# Serve the main HTML page
|
|
|
|
return send_from_directory(app.root_path, 'index.html')
|
2023-12-28 03:11:21 +00:00
|
|
|
|
|
|
|
@app.route('/search', methods=['GET'])
|
|
|
|
def search():
|
2023-12-28 06:33:55 +00:00
|
|
|
# Get the search query parameter and convert it to lowercase for case-insensitive matching
|
2023-12-28 03:11:21 +00:00
|
|
|
query = request.args.get('searchQuery', '').lower()
|
2023-12-28 06:33:55 +00:00
|
|
|
|
|
|
|
# List to store filenames of matching EPUB files
|
2023-12-28 03:11:21 +00:00
|
|
|
matching_files = []
|
2023-12-28 06:33:55 +00:00
|
|
|
|
|
|
|
# Fetch all EPUB files from the directory and filter them based on the search query
|
2024-01-22 19:00:46 +00:00
|
|
|
all_files = [f for f in os.listdir(RESUME_DIR) if f.lower().endswith('.epub')]
|
2023-12-28 06:33:55 +00:00
|
|
|
matching_files += [f for f in all_files if query in f.lower()]
|
2023-12-28 03:11:21 +00:00
|
|
|
|
2023-12-28 06:33:55 +00:00
|
|
|
# Generate HTML for the list of matching files
|
2023-12-28 03:11:21 +00:00
|
|
|
results_html = "".join([f'<li><a href="#" onclick="loadEpubInBibi(\'/bookshelf/{file}\'); return false;">{file}</a></li>' for file in matching_files])
|
|
|
|
return results_html
|
|
|
|
|
2023-12-28 06:33:55 +00:00
|
|
|
@app.route('/bookshelf/<filename>')
|
|
|
|
def serve_epub(filename):
|
|
|
|
# Serve an EPUB file from the bookshelf directory
|
|
|
|
return send_from_directory(EPUBS_DIR, filename)
|
2023-12-28 03:11:21 +00:00
|
|
|
|
|
|
|
@app.route('/reader/<path:subpath>')
|
|
|
|
def serve_bibi_assets(subpath):
|
2023-12-28 06:33:55 +00:00
|
|
|
# Serve assets for the Bibi EPUB reader (JavaScript, CSS, etc.)
|
2023-12-28 03:11:21 +00:00
|
|
|
return send_from_directory('./reader', subpath)
|
|
|
|
|
|
|
|
@app.route('/favicon.ico')
|
|
|
|
def favicon():
|
2023-12-28 06:33:55 +00:00
|
|
|
# Serve the favicon
|
|
|
|
return send_from_directory(os.path.join(app.root_path, 'favicon.ico'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
|
2023-12-28 03:11:21 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-12-28 06:33:55 +00:00
|
|
|
app.run(debug=True)
|