diff --git a/app.py b/app.py index ae1e934..8ca685c 100644 --- a/app.py +++ b/app.py @@ -20,6 +20,8 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.backends import default_backend import base64 +from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.triggers.interval import IntervalTrigger app = Flask(__name__) app.secret_key = os.environ.get('FLASK_SECRET_KEY', 'dev-secret-key-change-in-production') @@ -221,10 +223,15 @@ def build_directory_tree(): # Add file to current level if '_files' not in current: current['_files'] = [] + + # Check if file is protected + is_protected = is_file_protected(str(rel_path)) + current['_files'].append({ 'name': filename, 'path': str(rel_path), - 'encrypted': is_enc + 'encrypted': is_enc, + 'protected': is_protected }) logger.info(f"Built tree for {CONTENT_DIR}: found {file_count} markdown files") @@ -535,10 +542,31 @@ def status(): 'timestamp': datetime.now().isoformat() }) +def setup_scheduler(): + """Set up background scheduler for periodic content scanning.""" + scheduler = BackgroundScheduler() + scheduler.add_job( + func=update_search_index, + trigger=IntervalTrigger(seconds=60), + id='update_search_index', + name='Update search index every 60 seconds', + replace_existing=True + ) + scheduler.start() + logger.info("Scheduler started: content directory will be scanned every 60 seconds") + return scheduler + if __name__ == '__main__': # Perform initial index build logger.info("Initializing markmywords") update_search_index() - # Start Flask app - app.run(host='0.0.0.0', port=5000, debug=False) + # Start background scheduler for periodic content scanning + scheduler = setup_scheduler() + + try: + # Start Flask app + app.run(host='0.0.0.0', port=5000, debug=False) + finally: + # Shut down scheduler on exit + scheduler.shutdown() diff --git a/docker-compose.yml b/docker-compose.yml index d1d99b6..e6ea7f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: markmywords: build: . - container_name: markmywords + container_name: markmywords_test ports: - "5000:5000" volumes: diff --git a/manage_content.py b/manage_content.py index 7a7b4e4..c10a9d6 100755 --- a/manage_content.py +++ b/manage_content.py @@ -162,7 +162,9 @@ def encrypt(filepath, password): os.remove(filepath) # Update password database with encryption AND protection (same password) - file_key = get_file_key(enc_filepath) + # Normalize file_key to relative path (without CONTENT_DIR prefix) + display_path = enc_filepath.replace(CONTENT_DIR + '/', '') + file_key = get_file_key(display_path) passwords = load_passwords() passwords[file_key] = { @@ -175,7 +177,6 @@ def encrypt(filepath, password): save_passwords(passwords) - display_path = enc_filepath.replace(CONTENT_DIR + '/', '') print(f"✓ Encrypted & protected: {filepath} → {display_path}") return True @@ -282,7 +283,9 @@ def unprotect(filepath): if not filepath.startswith(CONTENT_DIR): filepath = os.path.join(CONTENT_DIR, filepath) - file_key = get_file_key(filepath) + # Normalize file_key to relative path (without CONTENT_DIR prefix) + display_path = filepath.replace(CONTENT_DIR + '/', '') + file_key = get_file_key(display_path) passwords = load_passwords() if file_key not in passwords: @@ -298,7 +301,6 @@ def unprotect(filepath): del passwords[file_key]['created_at'] if save_passwords(passwords): - display_path = filepath.replace(CONTENT_DIR + '/', '') print(f"✓ Unprotected: {display_path} (file stays encrypted, viewable in browser)") return True else: @@ -381,14 +383,14 @@ def status(filepath): if not filepath.startswith(CONTENT_DIR): filepath = os.path.join(CONTENT_DIR, filepath) - file_key = get_file_key(filepath) + # Normalize file_key to relative path (without CONTENT_DIR prefix) + display_path = filepath.replace(CONTENT_DIR + '/', '') + file_key = get_file_key(display_path) passwords = load_passwords() is_encrypted = filepath.endswith('.enc') is_protected = file_key in passwords and passwords[file_key].get('protected', False) - display_path = filepath.replace(CONTENT_DIR + '/', '') - print(f"\nFile: {display_path}") print(f"Encrypted: {'Yes' if is_encrypted else 'No'}") print(f"Protected: {'Yes' if is_protected else 'No'}") diff --git a/requirements.txt b/requirements.txt index 59628e4..95f41f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Flask==3.0.0 markdown==3.5.2 Whoosh==2.7.4 cryptography==41.0.7 +APScheduler==3.10.4 diff --git a/templates/tree_render.html b/templates/tree_render.html index 6226deb..ac0ea39 100644 --- a/templates/tree_render.html +++ b/templates/tree_render.html @@ -19,8 +19,8 @@ {% if '_files' in tree_dict %} {% for file in tree_dict['_files'] %}
  • - - 📄 {{ file.name }} + + 📄 {{ file.name }}{% if file.protected %} 🔒{% endif %}
  • {% endfor %}