diff --git a/app.py b/app.py index 6a1f372..59d7032 100644 --- a/app.py +++ b/app.py @@ -1,75 +1,47 @@ -from flask import Flask, render_template, request, send_from_directory +from flask import Flask, request, send_from_directory import os + +# Initialize Flask app app = Flask(__name__) -EPUBS_DIR = { - 'default': './bookshelf/' -} - +# Directory containing EPUB files +EPUBS_DIR = './bookshelf/' @app.route('/') def index(): - return send_from_directory(app.root_path,'index.html') - + # Serve the main HTML page + return send_from_directory(app.root_path, 'index.html') @app.route('/search', methods=['GET']) def search(): + # Get the search query parameter and convert it to lowercase for case-insensitive matching query = request.args.get('searchQuery', '').lower() + + # List to store filenames of matching EPUB files matching_files = [] - for _, dir_path in EPUBS_DIR.items(): - all_files = [f for f in os.listdir(dir_path) if f.lower().endswith('.epub')] - matching_files += [f for f in all_files if query in f.lower()] + + # Fetch all EPUB files from the directory and filter them based on the search query + all_files = [f for f in os.listdir(EPUBS_DIR) if f.lower().endswith('.epub')] + matching_files += [f for f in all_files if query in f.lower()] - # Render the results as HTML + # Generate HTML for the list of matching files results_html = "".join([f'
  • {file}
  • ' for file in matching_files]) return results_html - +@app.route('/bookshelf/') +def serve_epub(filename): + # Serve an EPUB file from the bookshelf directory + return send_from_directory(EPUBS_DIR, filename) @app.route('/reader/') def serve_bibi_assets(subpath): - # This will serve all of Bibi's assets, such as JavaScript, CSS, etc. + # Serve assets for the Bibi EPUB reader (JavaScript, CSS, etc.) return send_from_directory('./reader', subpath) - - - -@app.route('/bookshelf/') -def serve_epub(filename): - return send_from_directory('./bookshelf', filename) - - - - -#@app.route('/reader') -#def serve_bibi_reader(): -# book_path = request.args.get('book') - # You might want to do some checks on `book_path` for security reasons. -# return send_from_directory('./reader', 'index.html') - -@app.route('/reader') -def serve_bibi_reader(): - book_path = request.args.get('book', '') - if book_path: - # Check if the EPUB file exists in the bookshelf - full_path = os.path.join('bookshelf', book_path.strip('/')) - if os.path.exists(full_path): - # Serve the Bibi reader's index.html - # The book path will be handled by Bibi's JavaScript - return send_from_directory('reader', 'index.html') - else: - return "EPUB file not found", 404 - return "No book specified", 400 - - - - - - @app.route('/favicon.ico') def favicon(): - return send_from_directory(os.path.join(app.root_path, './favicon.ico'), - 'favicon.ico', mimetype='image/vnd.microsoft.icon') + # Serve the favicon + return send_from_directory(os.path.join(app.root_path, 'favicon.ico'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + app.run(debug=True) diff --git a/bookshelf/Teaching Resistance_ Radicals, Revolutiona - John Mink.epub b/bookshelf/Teaching Resistance_ Radicals, Revolutiona - John Mink.epub new file mode 100644 index 0000000..980db57 Binary files /dev/null and b/bookshelf/Teaching Resistance_ Radicals, Revolutiona - John Mink.epub differ diff --git a/bookshelf/Teaching.epub b/bookshelf/Teaching.epub new file mode 100644 index 0000000..10c251d Binary files /dev/null and b/bookshelf/Teaching.epub differ diff --git a/bookshelf/interact.epub b/bookshelf/interact.epub new file mode 100644 index 0000000..a6f8b91 Binary files /dev/null and b/bookshelf/interact.epub differ diff --git a/bookshelf/palestine-a-socialist-introduction.epub b/bookshelf/palestine-a-socialist-introduction.epub new file mode 100644 index 0000000..ea2a5ed Binary files /dev/null and b/bookshelf/palestine-a-socialist-introduction.epub differ diff --git a/bookshelf/sample.epub b/bookshelf/sample.epub new file mode 100644 index 0000000..e598b7a Binary files /dev/null and b/bookshelf/sample.epub differ diff --git a/index.html b/index.html index 363eec7..26a0ad5 100644 --- a/index.html +++ b/index.html @@ -6,8 +6,7 @@ El Asteroide De Miguel - - +