batman
This commit is contained in:
commit
42f1d1012f
18 changed files with 399 additions and 0 deletions
0
app/routes/__init__.py
Normal file
0
app/routes/__init__.py
Normal file
BIN
app/routes/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/routes/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/routes/__pycache__/main.cpython-312.pyc
Normal file
BIN
app/routes/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
47
app/routes/main.py
Normal file
47
app/routes/main.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
from flask import Blueprint, render_template, request, current_app, redirect, url_for, abort, flash
|
||||
import os
|
||||
from app.utils.file_handler import save_file, read_markdown_file, get_file_by_uri, load_uri_map
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
|
||||
@main_bp.route('/', methods=['GET'])
|
||||
def index():
|
||||
# List all available documents
|
||||
uri_map = load_uri_map()
|
||||
documents = [{'uri': uri, 'filename': info['filename']} for uri, info in uri_map.items()]
|
||||
return render_template('index.html', documents=documents)
|
||||
|
||||
@main_bp.route('/upload', methods=['GET', 'POST'])
|
||||
def upload_file():
|
||||
if request.method == 'POST':
|
||||
if 'file' not in request.files:
|
||||
flash('No file part')
|
||||
return redirect(request.url)
|
||||
|
||||
file = request.files['file']
|
||||
|
||||
if file.filename == '':
|
||||
flash('No file selected')
|
||||
return redirect(request.url)
|
||||
|
||||
if file and file.filename.endswith('.md'):
|
||||
custom_uri = request.form.get('custom_uri', '').strip()
|
||||
uri, filename = save_file(file, custom_uri if custom_uri else None)
|
||||
return redirect(url_for('main.view_file', uri=uri))
|
||||
else:
|
||||
flash('Only markdown files are allowed')
|
||||
|
||||
return render_template('upload.html')
|
||||
|
||||
@main_bp.route('/view/<uri>')
|
||||
def view_file(uri):
|
||||
file_info = get_file_by_uri(uri)
|
||||
|
||||
if not file_info:
|
||||
abort(404)
|
||||
|
||||
html_content = read_markdown_file(file_info['path'])
|
||||
return render_template('viewer.html',
|
||||
filename=file_info['filename'],
|
||||
content=html_content,
|
||||
uri=uri)
|
Loading…
Add table
Add a link
Reference in a new issue