73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from flask import Blueprint, abort, redirect, render_template, request, url_for, jsonify, current_app
|
|
|
|
from app.services.notes_fs import create_note, list_notes, load_note_by_id, update_note_body
|
|
from app.services.renderer import render_markdown
|
|
from app.services.vault import Vault
|
|
import frontmatter
|
|
import os
|
|
|
|
bp = Blueprint("notes", __name__, url_prefix="/notes")
|
|
|
|
# ... keep your existing routes ...
|
|
|
|
# Debug endpoints remain available while app.debug is True or KB_ENABLE_DEBUG_ROUTES is True
|
|
|
|
@bp.get("/_debug/ids")
|
|
def notes_debug_ids():
|
|
if not (current_app.debug or current_app.config.get("KB_ENABLE_DEBUG_ROUTES", False)):
|
|
abort(404)
|
|
notes = list_notes()
|
|
return jsonify(
|
|
notes=[{"id": n.id, "title": n.title, "path": n.rel_path} for n in notes]
|
|
)
|
|
|
|
|
|
@bp.get("/_debug/scan")
|
|
def notes_debug_scan():
|
|
if not (current_app.debug or current_app.config.get("KB_ENABLE_DEBUG_ROUTES", False)):
|
|
abort(404)
|
|
|
|
vault_path = current_app.config.get("KB_VAULT_PATH")
|
|
v = Vault(vault_path)
|
|
v.ensure_structure()
|
|
notes_dir = v.paths.notes
|
|
|
|
exists = os.path.isdir(notes_dir)
|
|
ls_notes = []
|
|
if exists:
|
|
try:
|
|
ls_notes = sorted(os.listdir(notes_dir))
|
|
except Exception as e:
|
|
ls_notes = [f"<error listing dir: {e}>"]
|
|
|
|
discovered = list(v.iter_markdown_files())
|
|
|
|
probe = []
|
|
for p in discovered:
|
|
try:
|
|
with open(p, "r", encoding="utf-8", errors="replace") as f:
|
|
post = frontmatter.loads(f.read())
|
|
meta = post.metadata or {}
|
|
probe.append({
|
|
"path": p,
|
|
"ok": True,
|
|
"id": meta.get("id"),
|
|
"title": meta.get("title"),
|
|
})
|
|
except Exception as e:
|
|
probe.append({
|
|
"path": p,
|
|
"ok": False,
|
|
"error": str(e),
|
|
})
|
|
|
|
return jsonify({
|
|
"vault": vault_path,
|
|
"notes_dir": notes_dir,
|
|
"notes_dir_exists": exists,
|
|
"notes_dir_list": ls_notes,
|
|
"discovered_md_files": discovered,
|
|
"probe": probe,
|
|
}) |